summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Berg <sebastian@sipsolutions.net>2021-03-03 11:17:25 -0600
committerGitHub <noreply@github.com>2021-03-03 11:17:25 -0600
commita9962f2632003399946951c96ac6d6e3d3124ed7 (patch)
tree6240051f63a569473224324092acaad75cfbadf1
parent168978df69efecb07943fd8ce3a7c95aab7122cb (diff)
parent940f7d865d26b0bf5f35683cfc7aa1195d1c7078 (diff)
downloadnumpy-a9962f2632003399946951c96ac6d6e3d3124ed7.tar.gz
Merge pull request #18530 from ahaldane/fixup_gh18450
BUG: incorrect error fallthrough in nditer
-rw-r--r--numpy/core/src/umath/ufunc_object.c7
-rw-r--r--numpy/core/tests/test_nditer.py8
2 files changed, 14 insertions, 1 deletions
diff --git a/numpy/core/src/umath/ufunc_object.c b/numpy/core/src/umath/ufunc_object.c
index f30f31a2e..653e0b5be 100644
--- a/numpy/core/src/umath/ufunc_object.c
+++ b/numpy/core/src/umath/ufunc_object.c
@@ -3525,7 +3525,7 @@ reduce_loop(NpyIter *iter, char **dataptrs, npy_intp const *strides,
strides_copy, innerloopdata);
if (needs_api && PyErr_Occurred()) {
- break;
+ goto finish_loop;
}
/* Jump to the faster loop when skipping is done */
@@ -3539,6 +3539,11 @@ reduce_loop(NpyIter *iter, char **dataptrs, npy_intp const *strides,
}
} while (iternext(iter));
}
+
+ if (needs_api && PyErr_Occurred()) {
+ goto finish_loop;
+ }
+
do {
/* Turn the two items into three for the inner loop */
dataptrs_copy[0] = dataptrs[0];
diff --git a/numpy/core/tests/test_nditer.py b/numpy/core/tests/test_nditer.py
index f34547f9c..b2341fe4e 100644
--- a/numpy/core/tests/test_nditer.py
+++ b/numpy/core/tests/test_nditer.py
@@ -2883,6 +2883,14 @@ def test_object_iter_cleanup():
oarr[:, -1] = None
assert_raises(TypeError, lambda: np.add(oarr[:, ::-1], arr[:, ::-1]))
+ # followup: this tests for a bug introduced in the first pass of gh-18450,
+ # caused by an incorrect fallthrough of the TypeError
+ class T:
+ def __bool__(self):
+ raise TypeError("Ambiguous")
+ assert_raises(TypeError, np.logical_or.reduce,
+ np.array([T(), T()], dtype='O'))
+
def test_iter_too_large():
# The total size of the iterator must not exceed the maximum intp due
# to broadcasting. Dividing by 1024 will keep it small enough to