Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: incorrect error fallthrough in nditer #18546

Merged
merged 1 commit into from Mar 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion numpy/core/src/umath/ufunc_object.c
Expand Up @@ -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 */
Expand All @@ -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];
Expand Down
8 changes: 8 additions & 0 deletions numpy/core/tests/test_nditer.py
Expand Up @@ -2738,6 +2738,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
Expand Down