Skip to content

BUG: fix swallowed cast error in fancy indexing assignment (#31975) - #32115

Merged
charris merged 1 commit into
numpy:maintenance/2.5.xfrom
charris:backport-31975
Jul 27, 2026
Merged

BUG: fix swallowed cast error in fancy indexing assignment (#31975)#32115
charris merged 1 commit into
numpy:maintenance/2.5.xfrom
charris:backport-31975

Conversation

@charris

@charris charris commented Jul 27, 2026

Copy link
Copy Markdown
Member

Backport of #31975.

PR summary

Fixes #31974.

arr[idx] = vals can swallow a cast error when the values are buffered and the cast fails while the iterator refills a buffer chunk (array bigger than one 8192-element chunk). the buffered iternext returns 0 on error which looks exactly like a normal end of iteration, so mapiter_set/mapiter_get returned success with the exception still set. depending on what runs next that's either a silent bogus success (the error surfaces at a later unrelated call) or SystemError: ... returned a result with an exception set (e.g. via np.put_along_axis).

this adds a PyErr_Occurred() check after the iteration loops in mapiter_@name@. small arrays already raise cleanly since first-chunk failures are caught at NpyIter_Reset so this just makes big arrays consistent. kept the check unconditional (not needs_api-gated) because non-object casts can fail too, e.g. a string -> int cast hits the same leak

AI Disclosure

Used Claude to double check my work and mae sure I didn't miss anything

@charris charris added this to the 2.5.2 release milestone Jul 27, 2026
@charris charris added 00 - Bug 08 - Backport Used to tag backport PRs labels Jul 27, 2026
@charris
charris merged commit 3b9ab54 into numpy:maintenance/2.5.x Jul 27, 2026
85 checks passed
@charris
charris deleted the backport-31975 branch July 27, 2026 17:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

00 - Bug 08 - Backport Used to tag backport PRs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants