GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||
GeezerVison is showing github.com — BUG: Do not forward descending unless explicitly passed by pllim · Pull Request #31458 · numpy/numpy Conversation
|
| extra_kw = {"descending": descending} | ||
| else: | ||
| extra_kw = {} | ||
| a.sort(axis=axis, kind=kind, order=order, stable=stable, **extra_kw) |
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Awesome, thanks @pllim. I would be tempted to just duplicating the return a.sort(...) (to avoid creating a dict just to unpack it immediately).
A test would be great, but I am also fine if not. (Needs a small dummy object -- I guess in test_multiarray although that file is annoying large.)
(We sometimes use np._NoValue, but I think in this case it should be fine to just not pass on if the user passes descending=False explicitly.)
Both are somewhat nits though, I admit :).
We probably should do the same change to argsort(). (It uses wrapfunc, but that is just because it doesn't work in-place mainly, I guess. We can do just the same and duplicate.)
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the detailed feedback! I implemented the functional code changes, hopefully as you requested.
However, I noticed there are already a bunch of test_sort_descending tests in numpy/_core/tests/test_multiarray.py. I am not sure how to write another test that would trigger this error without introducing that class from astropy. 😬
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Thank you for fixing this @pllim! About the test, I think you could create a small dummy class (does not need to have any real functionality or mirror astropy) that implements argsort with the right (kw)args, then write a test that instantiates an object and checks there is no error when calling np.argsort(a, descending=False).
Sorry, something went wrong.
There was an error while loading. Please reload this page.
but also do not unpack kwargs so just duplicate the call.
|
For the |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I pushed a test, but someone should have a quick look (verified that it failed for both sort and argsort before). |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| a = asanyarray(a).copy(order="K") | ||
| a.sort(axis=axis, kind=kind, order=order, stable=stable, descending=descending) | ||
| # Sanitize for backward-compatibility | ||
| if descending: |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
In other code, we would set the argument to np._NoValue and pass on the argument if it is not that (see, e.g., argmax in the same file). I think that is better, because then if someone explicitly passes in descending=False, they get the correct error that the argument does not exist.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Hmmmm, yeah, let's go with this. I somewhat thought that here the default may be unambiguous enough, but really... it is also for keepdims= probably and safer.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Thank you for adding the test here, @seberg ! Given I am unfamiliar with your testing setup, it is more elegant than what I could have come up with. Is there anything else you need from me? If not, I'll let you do your thing. And thanks for appreciating the branch name. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
This is just a bit more precise to not pass things on when explicitly passed as `descending=False`.
|
OK, changed to |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Looks good, thanks both!!
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Hmm CI is failing. Is that related? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
Thank you for cleaning up my PR and bringing it over the finish line! I appreciate the timely response. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.