Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug that caused serialized FITS tables to be duplicated #411

Merged
merged 2 commits into from
Dec 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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:')