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

np.unique raises a deprecation warning when all entries are nan. #19300

Closed
thomasjpfan opened this issue Jun 22, 2021 · 0 comments · Fixed by #19301
Closed

np.unique raises a deprecation warning when all entries are nan. #19300

thomasjpfan opened this issue Jun 22, 2021 · 0 comments · Fixed by #19301

Comments

@thomasjpfan
Copy link
Contributor

np.unique raises a deprecation warning when all entries are nan.

Reproducing code example:

import numpy as np
import warnings

warnings.filterwarnings("error", category=DeprecationWarning)

a = np.array([np.nan] * 10)
result = np.unique(a)
print(result)

Error message:

ValueError: operands could not be broadcast together with shapes (0,) (9,) 

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users/thomasfan/Repos/numpy/wow.py", line 7, in <module>
    result = np.unique(a)
  File "<__array_function__ internals>", line 5, in unique
  File "/Users/thomasfan/Repos/numpy/numpy/lib/arraysetops.py", line 272, in unique
    ret = _unique1d(ar, return_index, return_inverse, return_counts)
  File "/Users/thomasfan/Repos/numpy/numpy/lib/arraysetops.py", line 343, in _unique1d
    mask[1:aux_firstnan] = (aux[1:aux_firstnan] != aux[:aux_firstnan - 1])
DeprecationWarning: elementwise comparison failed; this will raise an error in the future.

NumPy/Python version information:

1.21.0.dev0+1989.g80b387c66 3.9.5 | packaged by conda-forge | (default, Jun 19 2021, 00:27:35) 
[Clang 11.1.0 ]
seberg pushed a commit that referenced this issue Jun 29, 2021
This PR adjusts np.unique for the edge cases where all values are nan.

Fixes gh-19300
charris pushed a commit to charris/numpy that referenced this issue Jul 1, 2021
…9301)

This PR adjusts np.unique for the edge cases where all values are nan.

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

Successfully merging a pull request may close this issue.

1 participant