Skip to content

Commit

Permalink
add overflow tests for Delta filter
Browse files Browse the repository at this point in the history
  • Loading branch information
ehgus committed Nov 26, 2024
1 parent 0780934 commit cd0b0f7
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions numcodecs/tests/test_delta.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,44 @@ def test_errors():
Delta(dtype=object)
with pytest.raises(ValueError):
Delta(dtype='i8', astype=object)


error_proned_integer_type_pairs = [
('i2', 'i1'),
('i4', 'i2'),
('i8', 'i4'),
('u2', 'u1'),
('u4', 'u2'),
('u8', 'u4'),
]


# # TODO: Keep it until Numpy bug is fixed
# # Numpy does not generate overflow bug properly for integer values
# # Minimal working example:
# # import numpy as np
# # arr = np.zeros((1,), dtype = 'i1')
# # arr[0:] = np.array([128], dtype='i2') # This should raise overflow error or warning, but it does not
# # arr[0] = 128 # This raise overflow error
# def test_error_proned_integer_encode():
# for dtype, astype in error_proned_integer_type_pairs:
# codec = Delta(dtype=dtype, astype=astype)
# arr = np.array([0, np.iinfo(astype).max + 1], dtype=dtype)
# with pytest.raises(RuntimeWarning) as runtime_warning:
# codec.encode(arr)
# assert "overflow" in str(runtime_warning.value)


error_proned_float_type_pairs = [
('f4', 'f2'),
('f8', 'f4'),
]


def test_error_proned_float_encode():
for dtype, astype in error_proned_float_type_pairs:
codec = Delta(dtype=dtype, astype=astype)
arr = np.array([0, np.astype(np.finfo(astype).max, dtype) * 2], dtype=dtype)
with pytest.raises(RuntimeWarning) as runtime_warning:
codec.encode(arr)
assert "overflow" in str(runtime_warning.value)

0 comments on commit cd0b0f7

Please sign in to comment.