Skip to content

Commit

Permalink
Add test for asdf data duplication issue with fits (#105)
Browse files Browse the repository at this point in the history
* Add test for asdf data duplication issue with fits

See asdf issue asdf-format/asdf#1232

This test is currently skipped as it will fail with the current
asdf version.

* bump asdf to 2.14.1 to fix hdu data duplication

* update changelog
  • Loading branch information
braingram committed Nov 29, 2022
1 parent f934400 commit 11721d8
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
2 changes: 1 addition & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Bug Fixes
---------

-
- Increase asdf version to >=2.14.1 to fix hdu data duplication [#105]

Changes to API
--------------
Expand Down
5 changes: 2 additions & 3 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ setup_requires =
install_requires =
jsonschema>=3.0.2
# The tests require code that is in asdf master
# but not yet released. The package itself
# is compatible with asdf 2.7.
asdf>=2.7.1
# but not yet released.
asdf>=2.14.1
psutil>=5.7.2
numpy>=1.16
astropy>=5.0.4
Expand Down
20 changes: 20 additions & 0 deletions tests/test_fits.py
Original file line number Diff line number Diff line change
Expand Up @@ -619,3 +619,23 @@ def test_ndarray_validation(tmp_path):
with pytest.raises(ValidationError, match="Wrong number of dimensions: Expected 2, got 1"):
with FitsModel(file_path, strict_validation=True, cast_fits_arrays=False, validate_arrays=True) as model:
model.validate()


def test_resave_duplication_bug(tmp_path):
"""
An issue in asdf (https://github.com/asdf-format/asdf/issues/1232)
resulted in duplication of data when a model was read from and then
written to a fits file.
"""
fn1 = tmp_path / "test1.fits"
fn2 = tmp_path / "test2.fits"

arr = np.zeros((1000, 100), dtype='f4')
m = FitsModel(arr)
m.save(fn1)

m2 = FitsModel.from_fits(fn1)
m2.save(fn2)

with fits.open(fn1) as ff1, fits.open(fn2) as ff2:
assert ff1['ASDF'].size == ff2['ASDF'].size

0 comments on commit 11721d8

Please sign in to comment.