summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authorSebastian Berg <sebastian@sipsolutions.net>2022-06-06 11:42:03 -0700
committerSebastian Berg <sebastian@sipsolutions.net>2022-06-13 09:36:57 -0700
commitf7b0493d51198b1cbb204409795398d7c8b5b059 (patch)
tree12abff8ae6d9c77eabe6819cfb58126ee0391fc2 /numpy
parenta7e58a7e22ce95d05648987a49227d8cadf3182b (diff)
downloadnumpy-f7b0493d51198b1cbb204409795398d7c8b5b059.tar.gz
TST: Add final set of cast (and FPE in cast) test to ufuncs
The remaining uncovered paths seem to me like code that should be effectively unreachable. (I do actually wonder if `PyArray_MapIterReset` should be removed.)
Diffstat (limited to 'numpy')
-rw-r--r--numpy/core/tests/test_ufunc.py24
1 files changed, 23 insertions, 1 deletions
diff --git a/numpy/core/tests/test_ufunc.py b/numpy/core/tests/test_ufunc.py
index 56ca7f4bd..3466178a3 100644
--- a/numpy/core/tests/test_ufunc.py
+++ b/numpy/core/tests/test_ufunc.py
@@ -2457,7 +2457,7 @@ def test_ufunc_warn_with_nan(ufunc):
@pytest.mark.skipif(not HAS_REFCOUNT, reason="Python lacks refcounts")
-def test_ufunc_casterrors():
+def test_ufunc_out_casterrors():
# Tests that casting errors are correctly reported and buffers are
# cleared.
# The following array can be added to itself as an object array, but
@@ -2488,6 +2488,28 @@ def test_ufunc_casterrors():
assert out[-1] == 1
+@pytest.mark.parametrize("bad_offset", [0, int(np.BUFSIZE * 1.5)])
+def test_ufunc_input_casterrors(bad_offset):
+ value = 123
+ arr = np.array([value] * bad_offset +
+ ["string"] +
+ [value] * int(1.5 * np.BUFSIZE), dtype=object)
+ with pytest.raises(ValueError):
+ # Force cast inputs, but the buffered cast of `arr` to intp fails:
+ np.add(arr, arr, dtype=np.intp, casting="unsafe")
+
+
+@pytest.mark.parametrize("bad_offset", [0, int(np.BUFSIZE * 1.5)])
+def test_ufunc_input_floatingpoint_error(bad_offset):
+ value = 123
+ arr = np.array([value] * bad_offset +
+ [np.nan] +
+ [value] * int(1.5 * np.BUFSIZE))
+ with np.errstate(invalid="raise"), pytest.raises(FloatingPointError):
+ # Force cast inputs, but the buffered cast of `arr` to intp fails:
+ np.add(arr, arr, dtype=np.intp, casting="unsafe")
+
+
def test_trivial_loop_invalid_cast():
# This tests the fast-path "invalid cast", see gh-19904.
with pytest.raises(TypeError,