Repository navigation
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. |
To be clear, just because I think that this is an interesting idea, doesn't mean that I think it is important or even worthwhile right now. In fact, the whole thought of "there are a lot of places" might mean that we should just not do it, because it is general NumPy behavior. |
|
Yeah this makes sense. This was actually why I asked for the locations where this happens. I did not expect an error being raised causing a partial state modification to be super common cause if it is, one can argue is that this is common numpy behavior and it probably doesn’t deserve special treatment. |
|
I'll just close this for now. I don't care about re-opening it, but the motivatio nneeds to be better then us musing about it maybe being nice. |
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