Skip to content

Commit

Permalink
BUG(io): store toc dtype when opening an existing FITS (#106)
Browse files Browse the repository at this point in the history
Fixes a bug that meant the dtype of the toc of existing FITS files was
not stored.

Also adds a missing test case which would have shown the bug earlier.

Fixes: #105
  • Loading branch information
ntessore authored Jan 6, 2024
1 parent 06ffc27 commit d98e81b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion heracles/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,7 @@ def __init__(self, path, *, clobber=False):
toc = fits[self.ext].read()

# store the dtype for ToC entries
toc.dtype = toc.dtype
self.dtype = toc.dtype

# store the ToC as a mapping
self._toc = TocDict({tuple(key): str(ext) for ext, *key in toc})
Expand Down
11 changes: 11 additions & 0 deletions tests/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@ class TestFits(TocFits):

data12 = np.zeros(5, dtype=[("X", float), ("Y", int)])
data22 = np.ones(5, dtype=[("X", float), ("Y", int)])
data21 = np.full(5, 2, dtype=[("X", float), ("Y", int)])

tocfits[1, 2] = data12

Expand Down Expand Up @@ -400,6 +401,16 @@ class TestFits(TocFits):
np.testing.assert_array_equal(tocfits2[1, 2], data12)
np.testing.assert_array_equal(tocfits2[2, 2], data22)

tocfits2[2, 1] = data21

with fitsio.FITS(path) as fits:
assert len(fits) == 5
toc = fits["TESTTOC"].read()
assert len(toc) == 3
np.testing.assert_array_equal(fits["TEST0"].read(), data12)
np.testing.assert_array_equal(fits["TEST1"].read(), data22)
np.testing.assert_array_equal(fits["TEST2"].read(), data21)


def test_tocfits_is_lazy(tmp_path):
import fitsio
Expand Down

0 comments on commit d98e81b

Please sign in to comment.