-
-
Notifications
You must be signed in to change notification settings - Fork 10.8k
DEP: deprecate scalar conversions for arrays with ndim > 0 #10615
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
Conversation
Would be interesting to see how extensive the changes need to be to make CI pass, and whether this impacts the scipy or pandas test suites. |
Looks like randomgen added more tests that rely on this behavior, should be straightforward to just remove them |
I'm on it. |
So I've been working on scipy a bit (scipy/scipy#11147) and found that in parts it was quite lax when it came to float conversion of arrays. I'll fix all the inconsistencies there and in panda (if any). All of what I discovered are actual bugs which is what makes me like this PR here even more. It will break (buggy/inefficient) code though, so there'll perhaps have to be a deprecation process. What do you think? |
To me there's no question that if we do this, it will need to be after a deprecation period. I'm definitely in favor of tracking down bugs in downstream projects with this change, whether or not we decide to merge this. Make sure to link those fixes to here so we can get a feel for the impact. |
@seberg in pandas, how should we treat size 1 arrays with PyObject list/tuples that we want to treat as scalars for assignment e.g.
|
@mroeschke you can work around that by doing |
Even this deprecation notwithstanding it's a good idea to use 0-D arrays instead of scalars everywhere if you're dealing with object dtype arrays with elements that themselves could be interpreted as arrays by The issue is that |
Thanks @asmeurer. Yeah using 0D arrays in pandas seems to work for our use case |
Provided my reading of the patch, and in particular the comment attached to the deprecation code, is correct, the error that will be raised after this deprecation is expired is For context, I'm working on a case where the implicit conversion from size-1 array to scalar happens in a |
Yes, it will be a |
This PR reflects some of the progress achieved in issue #10404 and is used to asses the impact of the changes.
With the changes in this PR,
float(numpy.array([1.0])
now gives a warning; likewise some other things:This aligns the behavior of numpy arrays with that of lists:
Fixes #10404.