Skip to content

Conversation

@kounelisagis
Copy link
Member

@kounelisagis kounelisagis commented Aug 19, 2025

This PR fixes NumPy object comparison issues in dense_array.py and sparse_array.py by implementing two changes:

  1. dtype comparisons: Updated to use == operator instead of is, following the NumPy recommendation:

    When checking for a specific data type, use == comparison.
    Do not use is, because data type objects may or may not be singletons.

  2. Array type checks: Updated to use isinstance(x, np.ndarray) instead of type(x) is np.ndarray.

These changes resolve errors in Dask and other distributed computing environments where worker processes compare objects across process boundaries, while also improving compatibility with the broader NumPy ecosystem.

Closes #2234

cc. @kylemann16

@kounelisagis kounelisagis requested a review from ihnorton August 19, 2025 15:42
@kylemann16
Copy link
Contributor

Thank you for taking the time to look at this!

@kounelisagis kounelisagis changed the title Fix numpy dtype comparisons to use == instead of is operator Fix numpy object comparisons; use == for dtypes and isinstance for arrays Aug 19, 2025
Copy link
Member

@ihnorton ihnorton left a comment

Choose a reason for hiding this comment

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

LGTM (regression test would be good though, if possible)

Copy link
Contributor

@kylemann16 kylemann16 left a comment

Choose a reason for hiding this comment

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

Looks good to me, thank you!

@kounelisagis
Copy link
Member Author

LGTM (regression test would be good though, if possible)

I thought about it longer than I should have, but I couldn't create one.

@kounelisagis kounelisagis changed the title Fix numpy object comparisons; use == for dtypes and isinstance for arrays Fix numpy comparisons; use == for dtypes and isinstance for arrays Aug 21, 2025
@kounelisagis kounelisagis merged commit e8b3b1c into main Aug 21, 2025
43 checks passed
@kounelisagis kounelisagis deleted the agis/numpy-dtype-comparison-operators branch August 21, 2025 13:26
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 this pull request may close these issues.

Python class equivalence usage questions

4 participants