-
-
Notifications
You must be signed in to change notification settings - Fork 11k
Regression: Change in behaviour for np.array()
on class that defines __array__
#13958
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
Hmm, we new switch between using the array interface (for filling the array) and using the iteration only for discovery of dimension, that must be the issue, we will have to see how much we have to revert for compatibility in this regard. |
My expectation would have been that But perhaps if we break things, we might as well try to make it more logical? |
The documentation for
So the interaction with non- |
The documentation for
This suggests |
Just for reference, just passing in arrays directly is still consistent between versions:
But neither 1.16 nor 1.17 reproduces the second example. |
I suppose I will look at this tomorrow (unless someone beats me to it). I am not quite sure what the solution is, but I would like to go over to use Worst case, we might have to revert that speed up change for 1.17. |
OK, so basically, I think I can add correct code into |
Just to list/summarize the issue:
I took a bit of a stab at prefering The other options is to just revert the order in gh-13399 in @superbobry do you happen to have an insight into this? |
So even after fixing the dimension discovery to honor |
@mhvk would a result of:
in your example (with object dtype; a failure without dtype) be better? Maybe coercing |
@seberg - for The alternative would be to always immediately use
I guess the problem indeed boils down to not knowing whether to treat the list entries as the objects themselves, as duck arrays, or as further iterables. Overall, your suggestion does seem the most logical: after all, without it, it would be impossible ever to make an array of One question is whether it would not be better to put this off to 1.18 (i.e., revert for now), so that one can also address the whole |
Reversion until 1.18 seems reasonable given how tricky this seems to be. @mhvk What do you mean by "address the whole |
|
Yeah, but I am sorry. If this is the last thing that is needed for the release, and we want to do that soon. I feel like it might be best to revert it at least in the 1.17 branch. Unless someone steps up to advocate that such an object is so inherently broken and rare that we can get away with pretty much anything... |
I'm fine with reverting. Sadly, don't have time to investigate this further at the moment. |
Reverted in 1.17, still in 1.18 while we search for a better solution. |
Thanks all for looking into this! |
PR #14109 still need to be backported (or a better fix found). Note that my new code that hopefull lands (or a different version of it of course). Which does not matter much here, but right now I am personally not very enthusiastic about looking into trying to find a solution because of that. EDIT: I have to double check whether it is true that it needs backporting... |
In the alternatives to NEP 34 it was suggested to add a new array creation function that would add a |
Now that this is pushed off, It sounds like we need to revert the change for 1.18. |
@seberg is it your suggestion that the reversion be in master? |
I guess we should put it into master, unless anyone argues that the regression does not matter much at all. There should be ways to make the speed up happen without the regression, or at least while doing it on purpose (and consistently). It is easy enough to revert to revert as a basis for new work... |
The original PR showed a 30x speedup. Perhaps we should reconsider reverting that? |
Reverting in master seems right, looks like this needs someone to sit down and work out the desired behavior in detail for all reported cases, and some tests to enforce that behavior, and then look again at the original speedup to see if it can be adapted. |
``__array__`` was previously not used during dimension discovery, while bein gused during dtype discovery (if dtype is not given), as well as during filling of the resulting array. This would lead to inconsistencies with respect to array likes that have a shape including a 0 (typically as first dimension). Thus a shape of ``(0, 1, 1)`` would be found as ``(0,)`` because a nested list/sequence cannot represent empty shapes, except 1-D. This uses the `_array_from_array_like` function, which means that some coercions may be tiny bit slower, at the gain of removing a lot of complex code. (this also reverts commit d0d250a or the related change). This is a continuation of work by Sergei Lebedev in numpygh-13663 which had to be reverted due to problems with Pandas, and the general inconsistency. This version may not resolve all issues with pandas, but does resolve the inconsistency. Closes numpygh-13958
An issue has been raised for numpy 1.17rc in astropy (astropy/astropy#8976), which after a bit of digging boils down to the change below in bahaviour for classes that define
__array__
as well as a__len__
and__getitem__
. I must admit I think the behaviour in both cases is strange, as it doesn't simply use__array__
but rather seems to iterate, but the behaviour in 1.17 definitely makes (even) less sense than that in 1.16.Note that the following do not depend on version:
The text was updated successfully, but these errors were encountered: