-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
numpy array printing regression for ndarray subclasses in NumPy 1.14 #10360
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
Also apologies for not testing NumPy's beta and bringing this up before you shipped 1.14.0 :( |
Thanks for the minimal test case. I'll try to take a look at this, since the blame is likely on me and/or @ahaldane |
This only happens on 0d arrays - because The idea here it to make the string of a 0d array equivalent to the string of the scalar. In your case, it's not clear how to get hold of the scalar any more to do that. Perhaps we simply need recursion detection that calls |
Yeah, this is sort of a quirk in our design, using an array subclass to represent a scalar. We probably shouldn't have done that but that ship sailed a long time ago. If there's a way to poison the recursion somehow that sounds like the best approach. |
Here's what I think should happen:
|
Thanks for the explanation. |
It's expected :) I think of the *.0 releases as the true betas, it's why I move to them so quickly these days. There just aren't enough folks who test the the rc's and waiting around is just a waste of time. |
Note that this is a problem even if in the above
Option (2) is perhaps the safest, and also closest to the legacy behaviour. p.s. It is just luck that in |
This unfortunately is not safe, as we could be indexing an object array. We already have questionable legacy behavior in |
You mean an object array of arrays? I'm confused. Anyway, my main point really is that we should do something that does not cause a warning or exception. Something like the following should cover most cases: # the str of 0d arrays is a special case: It should appear like a scalar,
# so floats are not truncated by `precision`, and strings are not wrapped
# in quotes. So we return the str of the scalar value.
if a.shape == ():
item = a[()]
# Many subclasses wrap any scalar output back into the
# subclass. Avoid recursion for those (but allow arrays containing
# arrays)
if type(a) is np.ndarray or not isinstance(item, type(a)):
return str(item) |
Option 1 would be:
Of course, an option (3) would be to add a recursion guard but just not raise a warning. |
@eric-wieser @ahaldane What is the status of this for 1.14? |
Just took a look at this. Let's try what @mhvk said, it seems reasonable. |
Uh oh!
There was an error while loading. Please reload this page.
It looks like some of the array printing changes in NumPy 1.14 are causing issues in yt. Specifically, printing yt's object that represents a scalar with units is triggering a recursion error. Here is a simplified example that is sufficient to trigger the same error:
This script triggers an infinite recursion error on NumPy 1.14.0 and prints
1
on NumPy 1.13.3.Is there any chance that this can be fixed on NumPy's side for a 1.14.1 release? I'm honestly not sure how to fix this on the yt side without making major changes to our ndarray subclasses.
Ping @mhvk
The text was updated successfully, but these errors were encountered: