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
DEP: deprecate scalar conversions for arrays with ndim > 0 #10615
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. |
I've updated SciPy again to be warnings-free after this PR (scipy/scipy#17698). Changes are now usually minimal. I'd be great if this PR could be looked at again. We'll soon be celebrating it's 5th birthday. :) |
Are there plans to also deprecate the related reverse broadcasting behavior which was discussed on the list? |
I marked this for triage review, it also has a conflict. |
Planning to put this in later today and give it a shot. There is always the (correct) worry here that it might be noisy for downstream. OTOH, this has also repeatedly come up over the time. We had brought it up very briefly yesterday, but @mattip, if you had a different intention when marking it, just let me know. What makes me optimistic is that the scipy changes are far larger than the other libraries (all of which seem very simple, the optimizers really were most of it probably). So to be clear: I am happy to roll it back if this annoys downstream libraries or anyone has serious concerns (libs like dask or xarray for example). |
@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.