-
-
Notifications
You must be signed in to change notification settings - Fork 10.8k
ENH: Print funny-shaped empty arrays using "empty" #10119
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
@@ -3908,6 +3908,8 @@ def __repr__(self): | |||
self.size == 0 | |||
) | |||
|
|||
is_ndim_empty = self.size == 0 and len(self.shape) > 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: self.ndim
mask=False, | ||
fill_value=1e+20, | ||
dtype=float64)''') | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a test for non-unusual shapes too?
Well, that's fun:
Only one of our test instances actually catches this. I suppose we could do |
Also, we didn't consider subclasses. Currently: >>> class MyArray(np.ndarray): pass
>>> np.empty((0, 20)).view(MyArray)
MyArray([], shape=(0, 20), dtype=float64)
>>> np.ma.array(_)
masked_MyArray(data=[],
mask=False,
fill_value=1e+20) With this patch, I think we lose the subclass information |
Not true, it prints as We could also print it as |
Hmm yeah. The The ouptut for the size-0 array in your example is not evaluable, it gives Non-empty subclassed ndarrays also don't work: >>> MyArray(shape=(2), dtype=float64)
MyArray([ 7.74860419e-304, 7.74860419e-304])
>>> MyArray([ 7.74860419e-304, 7.74860419e-304])
TypeError: 'float' object cannot be interpreted as an index Since there seem to be so many cases already that aren't evaluable, I am tempted to give up on this PR and just say "the repr often isn't evaluable", and leave the non-evaluable |
I'm in favor of leaving this the way it is. If anyone else wants to give it a shot feel free, I'm going to close this one. |
Makes arrays like
np.empty((2,0,1))
print asnp.empty((2,0,1), dtype=float64)
. The old behavior was to print asnp.array([], dtype=float64)
no matte the shape, which could be misleading.This was discussed in #9792