summaryrefslogtreecommitdiff
path: root/numpy/testing
diff options
context:
space:
mode:
Diffstat (limited to 'numpy/testing')
-rw-r--r--numpy/testing/_private/utils.py3
-rw-r--r--numpy/testing/tests/test_utils.py14
2 files changed, 17 insertions, 0 deletions
diff --git a/numpy/testing/_private/utils.py b/numpy/testing/_private/utils.py
index 4957ef6d7..c553658cb 100644
--- a/numpy/testing/_private/utils.py
+++ b/numpy/testing/_private/utils.py
@@ -828,6 +828,9 @@ def assert_array_compare(comparison, x, y, err_msg='', verbose=True, header='',
# ignore errors for non-numeric types
with contextlib.suppress(TypeError):
error = abs(x - y)
+ if np.issubdtype(x.dtype, np.unsignedinteger):
+ error2 = abs(y - x)
+ np.minimum(error, error2, out=error)
max_abs_error = max(error)
if getattr(error, 'dtype', object_) == object_:
remarks.append('Max absolute difference: '
diff --git a/numpy/testing/tests/test_utils.py b/numpy/testing/tests/test_utils.py
index c82343f0c..377f570bd 100644
--- a/numpy/testing/tests/test_utils.py
+++ b/numpy/testing/tests/test_utils.py
@@ -953,6 +953,20 @@ class TestAssertAllclose:
a = np.array([[1, 2, 3, "NaT"]], dtype="m8[ns]")
assert_allclose(a, a)
+ def test_error_message_unsigned(self):
+ """Check the the message is formatted correctly when overflow can occur
+ (gh21768)"""
+ # Ensure to test for potential overflow in the case of:
+ # x - y
+ # and
+ # y - x
+ x = np.asarray([0, 1, 8], dtype='uint8')
+ y = np.asarray([4, 4, 4], dtype='uint8')
+ with pytest.raises(AssertionError) as exc_info:
+ assert_allclose(x, y, atol=3)
+ msgs = str(exc_info.value).split('\n')
+ assert_equal(msgs[4], 'Max absolute difference: 4')
+
class TestArrayAlmostEqualNulp: