Skip to content

Commit ec51d47

Browse files
committed
test: add more tests to cover nans and infs
1 parent 5f20b02 commit ec51d47

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

fitsio/tests/test_image_compression.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,7 @@ def test_image_mem_reopen_noop():
610610
assert np.array_equal(rimg, img)
611611

612612

613+
@pytest.mark.parametrize("nan_value", [np.nan, np.inf, -np.inf])
613614
@pytest.mark.parametrize("dtype", [np.float32, np.float64])
614615
@pytest.mark.parametrize(
615616
"fname",
@@ -618,9 +619,17 @@ def test_image_mem_reopen_noop():
618619
"mem://",
619620
],
620621
)
621-
def test_image_compression_nulls(fname, dtype):
622+
def test_image_compression_nulls(fname, dtype, nan_value):
622623
data = np.arange(36).reshape((6, 6)).astype(dtype)
623-
data[1, 1] = np.nan
624+
data[1, 1] = nan_value
625+
626+
# everything comes back as nan
627+
if nan_value is not np.nan:
628+
msk = ~np.isfinite(data)
629+
cdata = data.copy()
630+
cdata[msk] = np.nan
631+
else:
632+
cdata = data
624633

625634
with tempfile.TemporaryDirectory() as tmpdir:
626635
if "mem://" not in fname:
@@ -629,20 +638,26 @@ def test_image_compression_nulls(fname, dtype):
629638
fpth = fname
630639

631640
with FITS(fpth, "rw") as fits:
632-
fits.write(data, compress='RICE_1', tile_dims=(3, 3))
641+
fits.write(
642+
data,
643+
compress='RICE_1',
644+
tile_dims=(3, 3),
645+
dither_seed=10,
646+
qlevel=2,
647+
)
633648
read_data = fits[1].read()
634649

635650
np.testing.assert_allclose(
636651
read_data,
637-
data,
652+
cdata,
638653
)
639654

640655
if "mem://" not in fpth:
641656
with FITS(fpth, "r") as fits:
642657
read_data = fits[1].read()
643658
np.testing.assert_allclose(
644659
read_data,
645-
data,
660+
cdata,
646661
)
647662

648663

fitsio/tests/test_util.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ def test_nonfinite_as_cfitsio_floating_null_value(
4141
assert not any_nan
4242
np.testing.assert_array_equal(nan_data, data)
4343

44+
if with_nan and "f" in dtype:
45+
np.testing.assert_array_equal(data[3, 13], np.nan)
46+
np.testing.assert_array_equal(data[1, 7], np.inf)
47+
np.testing.assert_array_equal(data[1, 9], -np.inf)
48+
4449

4550
def test_cfitsio_floating_null_value_float32():
4651
assert np.float32(np.inf) == FLOATING_NULL_VALUE

0 commit comments

Comments
 (0)