-
Notifications
You must be signed in to change notification settings - Fork 7
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
Should we be implementing __array__? #67
Comments
They were only working because we define __array__, which may be going away (data-apis#67).
I tested removing it and found some more issues where weren't using At the same time, if you remove >>> import numpy as np
>>> import array_api_strict as xp
>>> np.asarray(xp.asarray([10]))
array(Array([10], dtype=array_api_strict.int64), dtype=object) Or we can explicitly make |
A small hiccup here is that we implicitly use this logic in
I believe that should be supported in the standard, but the logic in |
Prototype of this without the fix to asarray at #69. |
If this has to be removed, I'd suggest that the error message at least suggest how such a conversion should be performed (e.g. |
+1 to include a hint about how to fix. Writing that hint is hard - which is a problem. There are more relevant comments on gh-69, so let's keep the discussion there I'd say. |
So do you think this change should be reverted? I can also issue a warning in |
A warning doesn't help, the SciPy test suite will turn those straight into errors. And there'll be either zero or a million warnings probably. |
Can SciPy not disable the specific warning in its tests? This seems to me to be the best way to deliver info to people without breaking stuff. |
Removing it caused issues for SciPy (data-apis#67). I have left the flag in to make it easy to remove it in the future. I also considered raising a warning in __array__, but this is also difficult to handle data-apis#91
Quite a few projects run their CI with "turn warnings into errors", which is very useful to get signal and fix issues quickly (especially I know that is a little annoying, but if this library is to be run in the test suites of the likes of SciPy, scikit-learn, Xarray, etc. then I don't see a way to avoid being careful about these things. |
@lucascolley put up a draft PR at scipy/scipy#21835, so let's look at getting that landed first to ensure removing |
Question: did anyone try implementing the buffer protocol in Python (possible since recently, see PEP 688)? Adding that to |
Evgeni mentioned that in the community meeting yesterday, but would we not have to wait until we can drop Python 3.11? |
It can be implemented conditionally, only for Python >=3.12. For SciPy I don't see a problem with only testing on >=3.12 |
#102 (comment) |
Right now the array type implements
__array__
, but just as convenience. This was done back when the package was numpy.array_api.I'm wondering if we should actually remove this. It isn't part of the array API standard, and could just lead people incorrectly thinking it works. And more notably, it is leading to bugs in array_api_strict itself (like #66) where you can forget to use
._array
when passing an array to a NumPy function and it will still work (but maybe not in the same way, if that function also passes thedtype
argument for instance).The text was updated successfully, but these errors were encountered: