diff options
| author | Simon Surland Andersen <syrlander98@gmail.com> | 2022-02-08 14:43:36 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-02-08 07:43:36 -0600 |
| commit | f69ddd7111048111a7e486a2d7d008bd231af33d (patch) | |
| tree | cc3e7ca5e30ff8b6668a7311be8eb24a12ff7d33 /numpy/testing | |
| parent | 4b3ddd74610d1975e0d0eb9c32df2a2d54c8dafd (diff) | |
| download | numpy-f69ddd7111048111a7e486a2d7d008bd231af33d.tar.gz | |
ENH: Suppress over-/underflow RuntimeWarning in assert_array_equal (#21003)
* TST: Test suppression of asset_array_equal RuntimeWarning See #18992
* ENH: Suppress over-/underflow warnings on asset_array_equal - Closes #18992
* MAINT: Resolve linting issues of prior commit
* MAINT: Simplified ignore and test case of asset_array_equal
* MAINT: Removed unused import in test_utils.py
Diffstat (limited to 'numpy/testing')
| -rw-r--r-- | numpy/testing/_private/utils.py | 2 | ||||
| -rw-r--r-- | numpy/testing/tests/test_utils.py | 8 |
2 files changed, 9 insertions, 1 deletions
diff --git a/numpy/testing/_private/utils.py b/numpy/testing/_private/utils.py index 2c71e45bd..80a6fdd10 100644 --- a/numpy/testing/_private/utils.py +++ b/numpy/testing/_private/utils.py @@ -810,7 +810,7 @@ def assert_array_compare(comparison, x, y, err_msg='', verbose=True, header='', 'Mismatched elements: {} / {} ({:.3g}%)'.format( n_mismatch, n_elements, percent_mismatch)] - with errstate(invalid='ignore', divide='ignore'): + with errstate(all='ignore'): # ignore errors for non-numeric types with contextlib.suppress(TypeError): error = abs(x - y) diff --git a/numpy/testing/tests/test_utils.py b/numpy/testing/tests/test_utils.py index 31d2cdc76..919ca751f 100644 --- a/numpy/testing/tests/test_utils.py +++ b/numpy/testing/tests/test_utils.py @@ -207,6 +207,14 @@ class TestArrayEqual(_GenericTest): self._test_not_equal(a, b) self._test_not_equal(b, a) + def test_suppress_overflow_warnings(self): + # Based on issue #18992 + with pytest.raises(AssertionError): + with np.errstate(all="raise"): + np.testing.assert_array_equal( + np.array([1, 2, 3], np.float32), + np.array([1, 1e-40, 3], np.float32)) + class TestBuildErrorMessage: |
