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

Add test for asdf data duplication issue with fits #105

Merged
merged 3 commits into from
Nov 29, 2022
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
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