-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
Empty arrays should repr valid code to recreate them #16665
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
This has been brought up before, I'll look for the old issue tomorrow |
The PR was #10119 |
What is the status of this? I saw the above PR was closed. This is a pretty regular annoyance for me, so I'd be happy to make a PR to fix it if we know what the fix should be. If I understand correctly, the question was how making the repr give |
I see a few ways this can be fixed:
My preference is 2, because I do think the current form that is printed is the most readable. I also think 2.iii is the best choice of the three, as I think it's what most users would expect a |
This solution seems reasonable to me. Perhaps another option is to:
This naturally guides subclass authors to making an appropriate decision themselves. |
I'd be happy with (2.iii), seems like a sensible API even if not considering the need for |
I would be happy with 2.ii (which may actually be useful for ragged array construction, although an If the input is 1-D, or the reshape is simple it is all great, but the use in being able to reshape an array using:
Do we really want code that doe the above to reshape One could also argue that broadcasting semantics could be nice to make it not equivalent to reshaping, but rather to:
But as I said at the beginning, enforcing the shape explicitly, at least has a use-case (ragged array, and maybe just asserting shapes), which is not already covered by other good, obvious solutions, such as: EDIT: In practice, you would have to use |
Perhaps another reason I like option 2 is that I feel that morally, the |
Can you provide an example or two of where this comes up? IMO the
A shape argument would be fairly useless for the second case, and I'd argue for the first case the caller should pass something more precise than an empty list in the first place. |
Reproducing code example:
Empty arrays repr like
array([], shape=(0, 0), dtype=float64)
, but this is not actually valid becauseshape
cannot be passed to the array constructor:It would be useful if either
array([], shape=(0, 0), dtype=float64)
worked or empty arrays printed to another string that actually did work, likeempty(shape=(0, 0), dtype=float64)
. Aside from copy-pastability being useful, it's very confusing that it shows theshape
keyword like this when it doesn't actually exist.Error message:
Numpy/Python version information:
The text was updated successfully, but these errors were encountered: