-
Notifications
You must be signed in to change notification settings - Fork 33
BUG: array_namespace
returns compat for NumPy scalars with use_compat=None
#164
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
discovered in scipy/scipy#21264 (comment). The real problem it causes is that we check for matching namespaces in our tests, and often compare NumPy scalars against NumPy arrays. I suppose we could add extra checks for NumPy scalars to that machinery, but I think this should be fixed here instead. |
Agreed, that should be the right default. |
fix at gh-165 |
Seems like NumPy should be fixed here too. |
Can you spell out what should change in NumPy? It doesn't have an |
Do you mean giving NumPy scalars a matching |
Yes. This should work >>> np.asarray(0).__array_namespace__()
<module 'numpy' from '/Users/aaronmeurer/miniconda3/envs/numpy2/lib/python3.12/site-packages/numpy/__init__.py'>
>>> np.asarray([0])[0].__array_namespace__()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'numpy.int64' object has no attribute '__array_namespace__'. Did you mean: '__array_interface__'? |
NumPy 2.0 and 2.1 both have some incompatibilities with the array API (see data-apis#167 and data-apis#164). Closes data-apis#168.
With array-api-compat 1.8, NumPy 2.0.1
This behaviour is quite problematic for SciPy given NumPy's tendency to throw NumPy scalars at you under very little pressure.
It seems practical to have NumPy scalars return the same namespace as NumPy arrays when
use_compat=None
. Or perhaps a different argument should have to be passed touse_compat
(that would be fine for us).The text was updated successfully, but these errors were encountered: