Skip to content

Commit 81a744d

Browse files
committed
add floating point overflow unit test for Delta filter
1 parent 0780934 commit 81a744d

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

numcodecs/tests/test_delta.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,35 @@ def test_errors():
6464
Delta(dtype=object)
6565
with pytest.raises(ValueError):
6666
Delta(dtype='i8', astype=object)
67+
68+
69+
# overflow tests
70+
# Note: Before implementing similar test for integer -> integer types, check numpy/numpy#8987.
71+
oveflow_proned_float_float_pairs = [
72+
('f4', 'f2'),
73+
('f8', 'f4'),
74+
]
75+
76+
77+
def test_oveflow_proned_float_float_encode():
78+
for dtype, astype in oveflow_proned_float_float_pairs:
79+
codec = Delta(dtype=dtype, astype=astype)
80+
arr = np.array([0, np.finfo(astype).max.astype(dtype) * 2], dtype=dtype)
81+
with pytest.warns(RuntimeWarning, match=r"overflow encountered"):
82+
codec.encode(arr)
83+
84+
85+
overflow_proned_integer_float_paris = [
86+
('i4', 'f2'),
87+
('i8', 'f2'),
88+
('u4', 'f2'),
89+
('u8', 'f2'),
90+
]
91+
92+
93+
def test_oveflow_proned_integer_float_encode():
94+
for dtype, astype in overflow_proned_integer_float_paris:
95+
codec = Delta(dtype=dtype, astype=astype)
96+
arr = np.array([0, int(np.rint(np.finfo(astype).max)) * 2], dtype=dtype)
97+
with pytest.warns(RuntimeWarning, match=r"overflow encountered"):
98+
codec.encode(arr)

0 commit comments

Comments
 (0)