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

Use equality instead of hasing for dtype helpers #111

Closed
honno opened this issue Apr 13, 2022 · 2 comments · Fixed by #112
Closed

Use equality instead of hasing for dtype helpers #111

honno opened this issue Apr 13, 2022 · 2 comments · Fixed by #112
Assignees

Comments

@honno
Copy link
Member

honno commented Apr 13, 2022

@asmeurer noted in #110 (comment) that NumPy proper (i.e. numpy, as opposed to numpy.array_api) wasn't working with the test suite due to the following code. The problem was that the dtype attribute of NumPy-proper arrays were being used in conjuction with namespaced dtypes—these two are different objects, and thus have different hashes so they look like different keys in a dict.

>>> import numpy as np
>>> dtypes_map = {np.int64: "foo"}
>>> dtypes_map[np.asarray(0).dtype]
KeyError

This behaviour is isn't specifically ruled out in the spec, as the spec only says dtypes need equality, which NumPy-proper does conform to.

>>> np.asarray(0).dtype == np.int64
True

So the test suite should phase out assumptions of namespaced dtypes and array dtypes sharing the same hash, instead relying on equality.

@asmeurer
Copy link
Member

Could also be something to fix upstream. Technically a == b should imply hash(a) == hash(b), so NumPy isn't really following Python standard practices here.

@asmeurer
Copy link
Member

I found numpy/numpy#17864 which seems to be about this. Making the change here is still a good idea because the spec doesn't require hashing to begin with.

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.

2 participants