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
ENH: Reverse param in ordering functions #14989
Conversation
A
|
I'm in favor of adding this keyword, but only if we implement it everywhere as Warren says - which would mean implementing it in C. It's also not immediately clear to me how this would interact with the
Can you provide an example of where this fails, @WarrenWeckesser? |
It will fail if there are repeated values, because simply reversing the a = np.argsort([1, 1], kind="stable")[::-1] (Because a reverse parameter would return |
Hameer summed up the issue with For example, suppose
|
If you didn't flip the indices for argsort then the result would just be wrong anyway. |
Right. I confess that I didn't fully think through the implication of the initial reversal of the input when I made my first comment about stable argsort. 😳 |
I think adding I can submit pull request with those changes. Adding |
@mproszewska do you want to keep working on this?I think the only thing left is some conflicting fix. |
I could, but I'm not sure how numpy team feels about my solution or what else they expect |
The first flip, while perfectly valid for Also it would be nice to accept lists or tuples in case you need to sort by one column ascending and by other descending (with the I also think that having 'reverse' for It might also consider skipping the first flip for |
We discussed this a bit in today and considering the age of the PR decided to close this. There is a bit of an API question open. Generally, we think the feature itself is good though. However, it seems to us that this should (unfortunately) be done "properly" on the C level, that may be quite a bit harder (so unfortunately). |
ENH: add reverse parameter in np.sort (not in ndarray.sort()).
See #14728
It is done by flipping (np.flip) array before and after sort. I think that adding reverse in ndarray.sort() would include way more changes in code than it's worth (e.g. changing PyArray_SortFunc signature), but I'm open to any suggestions.