Skip to content

Bug: unique_values/unique_counts: NaNs should not be treated as equal #855

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

Open
3 tasks done
crusaderky opened this issue Mar 27, 2025 · 1 comment
Open
3 tasks done

Comments

@crusaderky
Copy link
Contributor

crusaderky commented Mar 27, 2025

sparse version checks

  • I checked that this issue has not been reported before list of issues.
  • I have confirmed this bug exists on the latest version of sparse.
  • I have confirmed this bug exists on the main branch of sparse.

Describe the bug

The Array API specification states for unique_* functions:

As nan values compare as False, nan values should be considered distinct.

In other words, it dictates behaviour equal to np.unique(..., equal_nan=False).

sparse.unique_* functions however treat NaNs as equal.

Steps or code to reproduce the bug

>>> from math import nan

>>> import array_api_strict as xp
>>> xp.unique_values(xp.asarray([math.nan, math.nan]))
Array([nan, nan], dtype=array_api_strict.float64)

>>> import sparse
>>> sparse.unique_values(sparse.asarray([math.nan, math.nan]))
array([nan])

Please describe your system.

sparse 0.16.0b4

@crusaderky crusaderky added bug Indicates an unexpected problem or unintended behavior needs triage Issue has not been confirmed nor labeled labels Mar 27, 2025
@hameerabbasi
Copy link
Collaborator

NaN handling in sparse arrays is weird, in general. I'm not sure this is fixable within the realm of sparse arrays.

@hameerabbasi hameerabbasi added discussion and removed bug Indicates an unexpected problem or unintended behavior needs triage Issue has not been confirmed nor labeled labels Apr 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants