You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
FITS checksum comments set by add_checksum(when=...) are overwritten on flush in update mode #20789
When a FITS file containing existing CHECKSUM and DATASUM keywords is opened with mode="update", calling add_checksum(when=...) correctly updates the checksum comments in memory. However, when the HDUList is flushed or closed, the comments are overwritten with Astropy's default timestamp comments.
This happens because _update_checksum() calls add_checksum() without passing a when argument, even if the user has already explicitly updated the checksums with custom comments.
It seems like it might be preferable for automatic checksum updates to preserve existing comments, particularly when the checksum cards have already been explicitly updated by the user.
Expected behavior
An explicit call to add_checksum(when=...) should preserve the supplied comments when the file is saved. Automatic checksum recalculation should not silently overwrite them.
How to Reproduce
fromastropy.ioimportfitsorig_header=fits.getheader("astropy_demo.fits.gz")
print(orig_header.comments["CHECKSUM"]) # HDU already has a CHECKSUM and DATASUMwithfits.open("astropy_demo.fits.gz", mode="update") ashdul:
hdul[0].data[0, 0] =5# change the datahdul[0].add_checksum(when="This is a custom `when` comment")
print(hdul[0].header.comments["CHECKSUM"]) # confirm that the custom comment did takenew_header=fits.getheader("astropy_demo.fits.gz")
print(new_header.comments["CHECKSUM"]) # overwritten by default `when` comment
Activity