ENH: note on the error when out may be partially written#31965
Conversation
1762456 to
c072052
Compare
|
Could you do a scan if there are any other functions where partial modification can occur on the |
c072052 to
4209c33
Compare
caller's array can be left partially modified on error in these
fyi: take/choose weren't fully shielded by their internal copy either so i added to the pr |
|
@seberg do you think one should add the note to all cases where an exception being raised can cause partial modification to out array here in this PR? |
|
This has ballooned into way to much reviewer work for something that is really not a problem. Please don't continue adding on more followup PRs for this. |
the scan was a response to @ikrommyd 's question. The other issues are independent of this specific fix :) I will avoid adding more follow ups from now on. thanks for flagging this! |
|
I was probably not clear enough. I only wanted to identify if there are any other places to put the add_note helper where the user is already visibly experiencing a partial modification in the out array and we can just improve the error they are already getting. |
PR summary
follow up to the discussion in #31940
np.putandnp.putmaskwrite directly into the caller's array and can raise part-way through (e.g. on an out-of-bounds index) which silently leave it partially modified. this adds a central helper that attaches a PEP 678 note to the errorthe note is only added when no internal copy shielded the caller's array.
np.takeandnp.chooseare wired up too but theirmode="raise"paths currently copy first so the note only takes effect there if that copy is removedAI Disclosure
Used Claude for double checking if I missed anything