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: Fix order of real and imaginary NaNs when sorting complex in descending order by MaanasArora · Pull Request #31557 · numpy/numpy

Conversation

@MaanasArora

@MaanasArora MaanasArora commented Jun 3, 2026 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor

Fixes a bug from #31345 where complex numbers with only imaginary nans get sorted before those with only real nans in descending sorts, when keeping in with our NaN semantics they should be sorted after (real nans are the primary key). This should probably be backported to 2.5, cc @seberg @charris

The longstanding less implementation is a bit confusing, but I didn't refactor/simplify and kept this change minimal. It would be good to confirm this is the correct behavior, though, as the greater is a bit hard to read (hopefully less so now):

  1. if greater, only push to right if the imaginary part is strictly NaN but the other is not,
  2. if less, only push to right if the other imaginary part is strictly NaN but this one is not,
  3. If real parts are equal or both are NaN, break the tie by float-like comparison of imaginary,
  4. Failing all (i.e., only one of the real parts is NaN), push to the right only if first is NaN.

So for the real part at least:

  • If both reals are non-NaN -> branch 1-2
  • If exactly one real is NaN -> branch 4
  • If both reals are NaN -> branch 3

Sorry, verbose, but hopefully that clears things, thank you for reviewing!

AI Disclosure

No AI tools used.

Sorry, something went wrong.

Uh oh!

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

All reactions
@MaanasArora
BUG: Fix order of real and imaginary NaNs when sorting complex in des…
a764b09
…cending order
@MaanasArora
MaanasArora force-pushed the fix-complex-desc-sort branch from 68597f4 to a764b09 Compare June 3, 2026 17:30
@seberg seberg added the 09 - Backport-Candidate PRs tagged should be backported label Jun 3, 2026
@charris charris added the 00 - Bug label Jun 4, 2026
seberg
seberg approved these changes Jun 4, 2026
View reviewed changes

@seberg seberg left a comment

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.

Thanks, can simplify it more and align with the first, but I'll just apply that. Not sure what kind of merge mess caused this, but good to have the test fixed.

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread numpy/_core/src/common/numpy_tag.hpp Resolved

Uh oh!

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

Comment thread numpy/_core/src/common/numpy_tag.hpp Resolved

Uh oh!

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

@seberg
Apply suggestions from code review
d90f393
Co-authored-by: Sebastian Berg <[email protected]>
@seberg
seberg merged commit 4440a76 into numpy:main Jun 4, 2026
85 checks passed

Uh oh!

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

@charris charris mentioned this pull request Jun 5, 2026
BUG: Fix order of real and imaginary NaNs when sorting complex in descending order (#31557) #31572
Merged
@charris charris removed the 09 - Backport-Candidate PRs tagged should be backported label Jun 5, 2026
charris pushed a commit that referenced this pull request Jun 5, 2026
@MaanasArora @seberg @charris
BUG: Fix order of real and imaginary NaNs when sorting complex in des…
62096a0
…cending order (#31557)

Co-authored-by: Sebastian Berg <[email protected]>
charris added a commit that referenced this pull request Jun 5, 2026
@charris
Merge pull request #31572 from charris/backport-31557
9bc0b7b
BUG: Fix order of real and imaginary NaNs when sorting complex in descending order (#31557)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@seberg seberg seberg 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.

3 participants

@MaanasArora @seberg @charris
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.