-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
Numpy2 breaks getting a list of supported dtypes #26778
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
Comments
Actually - we decided to put this back with a hard-coded scalar types list for our Nipy / Numpy 2.0 update : https://github.com/matthew-brett/nipy/blob/numpy-20-fixes/nipy/utils/__init__.py#L58 It seems we both have the same use-case - so I too would like to know how best to do this... |
We had to leave in
Note however that this can also include other globally known dtypes inserted by other packages that have been imported, see e.g. #24699. In the long run you'll be able to do this by looking at items in the |
Aha - so would we get closer with something like: [t for t in set(np.sctypeDict.values()) if t.__module__ == 'numpy'] ? In our case, we also sometimes need to type ( |
We could bring it back, but one of the goals of the API cleanup work (see NEP 52) was to reduce the number of cryptic ways to access or refer to dtypes. One issue is that Another problem with expecting NumPy to have a statically specified list of DTypes that it supports is that makes your code brittle when NumPy adds new dtypes in the future or when users pass in custom dtypes. I'll also let @rgommers and @seberg chime in since I'm sure they have opinions. |
I don't have much to add yet. In general we cleaned up a lot of duplicate ways of doing and accessing things. It seems like what you want is still available, and more complete, through The |
So at least for my usecase, the So Thank y'all. |
Just to give an idea our our use-case : https://github.com/matthew-brett/nipy/blob/numpy-20-fixes/nipy/core/reference/coordinate_system.py#L119 - we check whether the dtype is among the dtypes known to be supported. |
Seems like you want to allow some subset of all built-in numpy dtypes. So hardcoding them as done at https://github.com/matthew-brett/nipy/blob/66e5c524cd33a348f0ff8fd9a10f42f063112569/nipy/utils/__init__.py#L58-L62 seems correct. |
More details here: https://numpy.org/doc/stable/dev/depending_on_numpy.html#numpy-2-0-specific-advice and regarding np.sctypes: numpy/numpy#26778
More details here: https://numpy.org/doc/stable/dev/depending_on_numpy.html#numpy-2-0-specific-advice and regarding np.sctypes: numpy/numpy#26778
Uh oh!
There was an error while loading. Please reload this page.
numpy2 has removed
np.sctypes
, which we were using to get a list of all supported dtypes.Here's a code which we were using for this:
This is now broken, and the message redirects users to
np.dtypes
, but I'm not sure if there's a way to get all the names of supported dtypes. The above code on my machine onnumpy<2
would give this:So the question is, how can I reproduce this with numpy2?
For context, skops' persistence is where it's used.
The text was updated successfully, but these errors were encountered: