Skip to content
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

BUG: unique with NaNs and along an axis inconsistent with flat version #20873

Open
dstansby opened this issue Jan 21, 2022 · 1 comment
Open
Labels

Comments

@dstansby
Copy link
Contributor

Describe the issue:

Running np.unique on a flat array with multiple NaNs only returns one NaN. Running along an axis that has duplicated rows containing NaNs returns both rows however.

I suspect this is related to #20326 - whatever the decision here I think the result should be consistent between axis=None and axis=0.

Reproduce the code example:

import numpy as np

print(np.unique([np.nan, np.nan, 2.]))
# [ 2. nan]

a = np.array([[np.nan, 2.],
              [np.nan, 2.]])
print(np.unique(a))
# [ 2. nan]
print(np.unique(a, axis=0))
# [[nan  2.]
#  [nan  2.]]
#
# Expected:
# [[nan  2.]]

Error message:

No response

NumPy/Python version information:

1.22.1
3.9.7 (default, Sep 16 2021, 08:50:36)
[Clang 10.0.0 ]

@rjeb
Copy link
Contributor

rjeb commented Jan 24, 2022

Reproduced this behavior on Python 3.9.7 and the current numpy build.

The inconsistent behavior with the "axis" keyword was mentioned in the original issue #2111 but an implementation for NaN-equals-Nan seems to not have been made for it yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants