Skip to content

Commit

Permalink
Merge pull request #411 from drdavella/fix-fits-table
Browse files Browse the repository at this point in the history
Fix bug that caused serialized FITS tables to be duplicated
  • Loading branch information
drdavella authored Dec 14, 2017
2 parents e8e57d2 + 1fc1294 commit 63c11ff
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
``tag_to_schema_resolver`` property for ``AsdfFile`` and
``AsdfExtensionList``. [#399]

- Fix bug that caused serialized FITS tables to be duplicated in embedded ASDF
HDU. [#411]

1.3.2 (unreleased)
------------------

Expand Down
4 changes: 3 additions & 1 deletion asdf/fits_embed.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ def find_or_create_block_for_array(self, arr, ctx):
if not isinstance(arr, ndarray.NDArrayType):
base = util.get_array_base(arr)
for hdu in self._hdulist:
if base is hdu.data:
if hdu.data is None:
continue
if base is util.get_array_base(hdu.data):
return _FitsBlock(hdu)

return super(
Expand Down
19 changes: 19 additions & 0 deletions asdf/tests/test_fits_embed.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

astropy = pytest.importorskip('astropy')
from astropy.io import fits
from astropy.table import Table
from astropy.tests.helper import catch_warnings

from .. import asdf
Expand Down Expand Up @@ -259,3 +260,21 @@ def test_version_mismatch_file():
with fits_embed.AsdfInFits.open(testfile) as fits_handle:
assert fits_handle.tree['a'] == complex(0j)
assert len(w) == 0, display_warnings(w)

def test_serialize_table(tmpdir):
tmpfile = str(tmpdir.join('table.fits'))

data = np.random.random((10, 10))
table = Table(data)

hdu = fits.BinTableHDU(table)
hdulist = fits.HDUList()
hdulist.append(hdu)

tree = {'my_table': hdulist[1].data}
with fits_embed.AsdfInFits(hdulist, tree) as ff:
ff.write_to(tmpfile)

with asdf.AsdfFile.open(tmpfile) as ff:
data = ff.tree['my_table']
assert data._source.startswith('fits:')

0 comments on commit 63c11ff

Please sign in to comment.