Skip to content

Commit 6b53134

Browse files
committed
Avoid modifying .meta when serializing columns
Fix astropy#7364
1 parent df0f7b3 commit 6b53134

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

‎astropy/io/fits/connect.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import os
55
import re
66
import warnings
7+
from copy import deepcopy
78

89
from astropy.io import registry as io_registry
910
from astropy import units as u
@@ -360,6 +361,11 @@ def _encode_mixins(tbl):
360361
if encode_tbl is tbl and not info_lost:
361362
return tbl
362363

364+
# Copy the meta dict if it was not copied by represent_mixins_as_columns
365+
if encode_tbl is tbl:
366+
meta_copy = deepcopy(tbl.meta)
367+
encode_tbl = Table(tbl.columns, meta=meta_copy, copy=False)
368+
363369
# Get the YAML serialization of information describing the table columns.
364370
# This is re-using ECSV code that combined existing table.meta with with
365371
# the extra __serialized_columns__ key. For FITS the table.meta is handled

‎astropy/io/fits/tests/test_connect.py‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -904,3 +904,12 @@ def test_read_serialized_without_yaml(tmpdir, monkeypatch):
904904

905905
assert t2.colnames == ['col0.ra', 'col0.dec']
906906
assert len(t2) == 2
907+
908+
909+
@pytest.mark.skipif('not HAS_YAML')
910+
def test_meta_not_modified(tmpdir):
911+
filename = str(tmpdir.join('test.fits'))
912+
t = Table(data=[Column([1, 2], 'a', description='spam')])
913+
assert len(t.meta) == 0
914+
t.write(filename)
915+
assert len(t.meta) == 0

0 commit comments

Comments
 (0)