Skip to content

Commit cd0b0f7

Browse files
committed
add overflow tests for Delta filter
1 parent 0780934 commit cd0b0f7

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

numcodecs/tests/test_delta.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,44 @@ def test_errors():
6464
Delta(dtype=object)
6565
with pytest.raises(ValueError):
6666
Delta(dtype='i8', astype=object)
67+
68+
69+
error_proned_integer_type_pairs = [
70+
('i2', 'i1'),
71+
('i4', 'i2'),
72+
('i8', 'i4'),
73+
('u2', 'u1'),
74+
('u4', 'u2'),
75+
('u8', 'u4'),
76+
]
77+
78+
79+
# # TODO: Keep it until Numpy bug is fixed
80+
# # Numpy does not generate overflow bug properly for integer values
81+
# # Minimal working example:
82+
# # import numpy as np
83+
# # arr = np.zeros((1,), dtype = 'i1')
84+
# # arr[0:] = np.array([128], dtype='i2') # This should raise overflow error or warning, but it does not
85+
# # arr[0] = 128 # This raise overflow error
86+
# def test_error_proned_integer_encode():
87+
# for dtype, astype in error_proned_integer_type_pairs:
88+
# codec = Delta(dtype=dtype, astype=astype)
89+
# arr = np.array([0, np.iinfo(astype).max + 1], dtype=dtype)
90+
# with pytest.raises(RuntimeWarning) as runtime_warning:
91+
# codec.encode(arr)
92+
# assert "overflow" in str(runtime_warning.value)
93+
94+
95+
error_proned_float_type_pairs = [
96+
('f4', 'f2'),
97+
('f8', 'f4'),
98+
]
99+
100+
101+
def test_error_proned_float_encode():
102+
for dtype, astype in error_proned_float_type_pairs:
103+
codec = Delta(dtype=dtype, astype=astype)
104+
arr = np.array([0, np.astype(np.finfo(astype).max, dtype) * 2], dtype=dtype)
105+
with pytest.raises(RuntimeWarning) as runtime_warning:
106+
codec.encode(arr)
107+
assert "overflow" in str(runtime_warning.value)

0 commit comments

Comments
 (0)