Skip to content

Conversation

AnkitAhlawat7742
Copy link
Contributor

What was the Issue

Issue link :- #29336
Bug Description:- The equal_nan parameter in numpy.unique does not work correctly in some cases. Specifically:
For 1D arrays, np.nan values are not treated as equal even when equal_nan=True.
For 2D arrays with axis=0, the issue is similar — np.nan values are not treated as equal.

What This PR Fixes

This pull request fixes the issue for 1D arrays only.
Fixed: np.unique(..., equal_nan=True) now treats NaNs as equal in 1D arrays.

Notes

This PR does not address the 2D case (e.g., np.unique(array, axis=0, equal_nan=True)) described in the same issue.In coming days i will investigate and provide fix for this case as well

corrected white space
@AnkitAhlawat7742 AnkitAhlawat7742 force-pushed the AnkitAhlawat_fix-unique-equal_nan-axis0-1d branch from 63104ca to 7f04ede Compare July 16, 2025 05:56
@AnkitAhlawat7742
Copy link
Contributor Author

Hi @ngoldbaum ,
I noticed the PR hasn't been merged yet — just wanted to check if there's anything I might have missed or need to update.

@seberg
Copy link
Member

seberg commented Jul 21, 2025

Haven't looked at this, but one note/question is how it ties back to: #27345 (and maybe there is even something relevant for this there).

@AnkitAhlawat7742
Copy link
Contributor Author

Haven't looked at this, but one note/question is how it ties back to: #27345 (and maybe there is even something relevant for this there).

@seberg ,
I noticed there are quite a few code changes in PR #27345, but just to clarify — the solution I proposed was specifically targeted at handling the 1D array case with axis=0.However I do see changes related to 1D arrays in the PR as well.

@AnkitAhlawat7742
Copy link
Contributor Author

@seberg are we going to merge this PR ? ,as it is a Quick fix for 1st case(For 1D arrays, np.nan values are not treated as equal even when equal_nan=True.)

Copy link
Member

@seberg seberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks let's give this a shot (I'll just apply the doc fixes).

@AnkitAhlawat7742
Copy link
Contributor Author

Thanks let's give this a shot (I'll just apply the doc fixes).

@seberg Thanks for the feedback on the doc changes — let’s continue the discussion in a second PR as you suggested!
Just to confirm, is there anything else I need to do on this PR ? or it is ready to merge into main

@seberg
Copy link
Member

seberg commented Aug 28, 2025

Nothing to do, thanks for the PR and nice tests! Just waiting for CI to merge.

@ngoldbaum
Copy link
Member

Just waiting for CI to merge.

It's passing now! I'd hit the button but I don't quite have time to read through this whole thread again...

@seberg seberg merged commit 447a903 into numpy:main Aug 28, 2025
76 checks passed
@github-project-automation github-project-automation bot moved this from Awaiting a code review to Completed in NumPy first-time contributor PRs Aug 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Development

Successfully merging this pull request may close these issues.

3 participants