GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — BUG: Do not forward descending unless explicitly passed by pllim · Pull Request #31458 · numpy/numpy

Conversation

@pllim

@pllim pllim commented May 18, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

PR summary

My interpretation of #31345 (comment) from @seberg

First time committer introduction

👋 from Astropy to fix downstream failure (astropy/astropy#19760)

AI Disclosure

I hate AI and also too cheap to pay for one.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@pllim pllim mentioned this pull request May 18, 2026
ENH: Descending sorts with built-in dtype implementations #31345
Merged
@jorenham jorenham changed the title Do no pass descending if False BUG: Do not pass descending if False May 18, 2026
seberg
seberg reviewed May 18, 2026
View reviewed changes
Comment thread numpy/_core/fromnumeric.py Outdated
extra_kw = {"descending": descending}
else:
extra_kw = {}
a.sort(axis=axis, kind=kind, order=order, stable=stable, **extra_kw)

@seberg seberg May 18, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

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.

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.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@pllim pllim May 18, 2026

Copy link
Copy Markdown
Contributor Author

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.

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.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@MaanasArora MaanasArora May 18, 2026

Copy link
Copy Markdown
Contributor

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.

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.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@pllim
pllim force-pushed the dark-descent branch from 720213d to bfd489a Compare May 18, 2026 18:13
@pllim
Do no pass descending if False for sort and argsort
59ca31f
but also do not unpack kwargs so just duplicate the call.
@pllim
pllim force-pushed the dark-descent branch from bfd489a to 59ca31f Compare May 18, 2026 18:16
@jorisvandenbossche

jorisvandenbossche commented May 19, 2026

Copy link
Copy Markdown
Contributor

For the argsort case (just dispatching to the object, and not going through __array_func__), you could add a test with a small dummy class with just an argsort method with the old signature. I don't know how useful that would be, though (or how long numpy would like to keep the back compat for adding the descending keyword)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@seberg

seberg commented May 19, 2026

Copy link
Copy Markdown
Member

I pushed a test, but someone should have a quick look (verified that it failed for both sort and argsort before).
Was worth it already for noticing the dark-descent branch name ;).

pllim reacted with laugh emoji
All reactions
  • 😄 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@seberg
TST: Add test for non-forwarding of descending=False default
74214ab
@seberg
seberg force-pushed the dark-descent branch from c86725b to 74214ab Compare May 19, 2026 08:34
mhvk
mhvk reviewed May 19, 2026
View reviewed changes
Comment thread numpy/_core/fromnumeric.py Outdated
a = asanyarray(a).copy(order="K")
a.sort(axis=axis, kind=kind, order=order, stable=stable, descending=descending)
# Sanitize for backward-compatibility
if descending:

@mhvk mhvk May 19, 2026

Copy link
Copy Markdown
Contributor

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.

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.

Uh oh!

There was an error while loading. Please reload this page.

seberg and MaanasArora reacted with thumbs up emoji
All reactions
  • 👍 2 reactions

@seberg seberg May 19, 2026

Copy link
Copy Markdown
Member

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.

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.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@pllim

pllim commented May 19, 2026

Copy link
Copy Markdown
Contributor Author

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@pllim pllim mentioned this pull request May 19, 2026
MaskedNDArray.sort() got an unexpected keyword argument 'descending' + array compare failure astropy/astropy#19760
Closed
@seberg
Use np._NoValue for the new descending= kwarg
c9e0857
This is just a bit more precise to not pass things on when explicitly
passed as `descending=False`.
@seberg

seberg commented May 19, 2026

Copy link
Copy Markdown
Member

OK, changed to np._NoValue.

MaanasArora reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

mhvk
mhvk approved these changes May 19, 2026
View reviewed changes

@mhvk mhvk left a comment

Copy link
Copy Markdown
Contributor

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.

Looks good, thanks both!!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@pllim

pllim commented May 19, 2026

Copy link
Copy Markdown
Contributor Author

Hmm CI is failing. Is that related?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@seberg seberg changed the title BUG: Do not pass descending if False BUG: Do not forward descending unless explicitly passed May 19, 2026
@seberg
seberg merged commit 723f2fb into numpy:main May 19, 2026
105 of 111 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@pllim
pllim deleted the dark-descent branch May 19, 2026 19:01
@pllim

pllim commented May 19, 2026

Copy link
Copy Markdown
Contributor Author

Thank you for cleaning up my PR and bringing it over the finish line! I appreciate the timely response.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jorisvandenbossche jorisvandenbossche mentioned this pull request May 19, 2026
CI: Update pixi.lock + TST: Adjust xfails for fastparquet 2026.05.0 pandas-dev/pandas#65668
Merged
@tylerjereddy tylerjereddy added the 00 - Bug label May 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@seberg seberg seberg left review comments
@MaanasArora MaanasArora MaanasArora left review comments
@mhvk mhvk mhvk approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

00 - Bug

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

6 participants

@pllim @jorisvandenbossche @seberg @mhvk @MaanasArora @tylerjereddy
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.