-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
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
MAINT: extend delete single value optimization #16895
Conversation
Allow arrays of shape (1,) for delete's obj parameter to utilize the optimization for a single value. See numpy#16685.
Co-authored-by: Eric Wieser <wieser.eric@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Closes #16685
numpy/lib/function_base.py
Outdated
obj = obj.astype(intp) | ||
|
||
elif obj.shape == (1,): | ||
obj = obj.item() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
item()
makes me worry here...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this patch change the behavior of np.delete(np.arange(10), np.array([1], dtype=object))
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think obj = obj.reshape(())
would avoid that shortcoming - please add a test!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could your clarify the behavior you are concerned about for np.delete(np.arange(10), np.array([1], dtype=object))
. I will change it to obj = obj.reshape(())
either way but the behavior appears the same to me. What would you like to see in the test?
Also, is there anything else you would like to see tested?
@DevinShanahan Do you think you could finish this PR? It would be nice to fix #16685. |
@InessaPawson Yes, I will try to complete this as soon as possible. |
@InessaPawson I've re-requested a review, anything else you need from me on this at this time? |
@DevinShanahan Thank you for updating the PR! We will review it shortly. |
Thanks @DevinShanahan |
Hi-five on merging your first pull request to NumPy, @DevinShanahan! We hope you stick around! Your choices aren’t limited to programming – you can review pull requests, help us stay on top of new and old issues, develop educational material, work on our website, add or improve graphic design, create marketing materials, translate website content, write grant proposals, and help with other fundraising initiatives. For more info, check out: https://numpy.org/contribute |
This PR broke bolean array inputs, see gh-21840 (at least I am practically certain). Unfortunately, we need to either carefully check all the paths the "integer array" paths (which seem to accept booleans arrays now) or simply revert it and give it another shot some other time. |
Non integer array-likes were not correctly rejected when a new fast-path was added to `np.delete` in numpygh-16895. This includes the _explicitly_ added `dtype=object` which should not be allowed since it is not allowed in normal indexing either. Closes numpygh-21840
Non integer array-likes were not correctly rejected when a new fast-path was added to `np.delete` in numpygh-16895. This includes the _explicitly_ added `dtype=object` which should not be allowed since it is not allowed in normal indexing either. Closes numpygh-21840
Allow arrays of shape (1,) for
np.delete
'sobj
parameter to utilize the optimization for a single value. See #16685.