-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Closed
Description
Calling table write to FITS modifies table.meta, adding comments:
>>> import astropy
>>> astropy.__version__
'3.1.dev21681'
>>> from astropy.table import Table, Column
>>> t = Table(data=[Column([1, 2], 'a', description='spam')])
>>> t.meta
OrderedDict()
>>> t.write('test.fits', overwrite=True)
>>> t.meta
OrderedDict([('comments', ['--BEGIN-ASTROPY-SERIALIZED-COLUMNS--', 'datatype:', '- {name: a, datatype: int64, description: spam}', 'meta:', ' __serialized_columns__: {}', '--END-ASTROPY-SERIALIZED-COLUMNS--'])])
>>> t.write('test.fits', overwrite=True)
>>> t.meta
OrderedDict([('comments', ['--BEGIN-ASTROPY-SERIALIZED-COLUMNS--', 'datatype:', '- {name: a, datatype: int64, description: spam}', 'meta:', ' __serialized_columns__: {}', '--END-ASTROPY-SERIALIZED-COLUMNS--', '--BEGIN-ASTROPY-SERIALIZED-COLUMNS--', 'datatype:', '- {name: a, datatype: int64, description: spam}', 'meta:', ' __serialized_columns__: {}', '--END-ASTROPY-SERIALIZED-COLUMNS--'])])
I previously mentioned this already at #6912 (comment) , but that PR is closed so I wanted to file this separate issue.
IMO write shouldn't modify the object, i.e. this could be considered a bug or at least undesirable behaviour. Note how calling write twice puts the comments twice, maybe another indication that if at all the addition doesn't happen in the right place, and e.g. a copy of meta should be made in the process?
Finally, BinTableHDU(table) doesn't have that behaviour, so the write to FITS on disk and in-memory conversion to FITS don't behave the same, which is a bit problematic for us in Gammapy where we have both cases.
cc @taldcroft
Reactions are currently unavailable