Repository navigation
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR summary
While working on #33213 I noticed a similar pattern of writing to the output buffer before checking for errors ufuncs and operations that rely on the internal StringDType comparison API.
Currently StringDType's string comparison helper has no way to report errors. If it sees a null that isn't nan-like or a string, it raises an exception but returns 0, and its callers keep going as if the two strings compared equal:
Note how
np.maximumkeeps writing tooutafter the error, including the element that caused it. Even worse:argmaxandargminwithout=raises aSystemErrorand writes toouttoo.The fix is to have the comparison helper return an error code.
minimum/maximumand the StringDTypeargmax/argminimplementations now stop at the first error without writing the failing element, and the sharedargmax/argminloop now stops after the first failing row, including for object arrays. ThePyArray_CompareFuncwrappers used for sorting andsearchsortedkeep their current behavior because that signature can't report errors. I also extended the existing null sorting test to coverargmax,argmin, andmaximumwithout=, and added tests that reductions stop before writing subsequent rows.StringDType reductions also skip allocator locking for singleton rows, and comparisons only read missing-value metadata when an operand is null.
It's possible to backport this but it's pretty niche and it would need to be done manually so I'm not marking this for backport.
AI Disclosure
I iterated on this with an AI model.