-
-
Notifications
You must be signed in to change notification settings - Fork 10.8k
NEP: Make NEP 51 to propose changing the scalar representation #22261
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
f36efef
to
6fdfffc
Compare
Is there any way for the repr of a bytes or Unicode scalar to include the actual size? |
There is no point right now:
is still "S1", the length is not currently preserved when creating a scalar. If we had, that I guess we would also have |
Good point, thanks. One can create instances with padded zeros directly:
In that case, it would be nice for the repr to show the actual storage size, but I don't know if that possibility is enough incentive to do so. Perhaps it could be displayed only when there are padded zeros. E.g. |
Will this affect the repr of a structured data type? E.g.
Would |
Like @WarrenWeckesser, curious about I like the NEP otherwise; do include the strings too. |
Hmm, I had forgotten about structured, after thinking we print
since that also gives the field names. Do you have a different suggestion? We would have to add that as a valid constructor, but that should not be hard. About strings, I had not thought about the fact that it is possible to create larger strings at all. I suppose that might be something to change: If the string is longer, include the length as |
Yes, I like the suggested
|
Is there any way the name |
This is getting a bit unwieldy. I think right now things are fine, because I believe Python always prints I am hoping to discuss this in the call on wednesday a bit, maybe you can come? For the question of structured dtypes, my current angle would be that I am not sure how salvageable |
@seberg - indeed, let the perfect not be the enemy of the good. For the NEP, maybe the most important thing is to mention structured types and postponing a decision on those... |
I thought this would be a relatively straight forward nut to start cracking on 🤦... But, in some cases we just use the This is half thinking out loud for how to extend the NEP: I have to extend the NEP to include a new way to do
Now, that new And, unfortunately, that means designing that API first. Probably not too bad, but I suspect we should for example move the print option to a contextvar while at it. |
Also mention the backwards-incompatible break of changing ``arr.tofile()``
6fdfffc
to
959fed7
Compare
The current choice is `np.float64(nan)` and not one of the alterntives...
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.
Generally looks good, thanks for writing this up @seberg .
I took the liberty of making some minor wording/formatting fixups. There were just a few places where I wasn't quite sure what was being said. I think these instances could use just one more pass to really nail down the intended meaning (see comments below).
Another thing that I think would be really useful would be a table that compares the current repr
with the proposed repr
. I'd vote that this waits until the NEP is merged with draft status however, as that might spur more instance-specific discussion.
Had a look just to see what the status was -- it looks good to me! |
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.
LGTM, thanks for the writeup @seberg ! Let's get this in so it can hit the mailing list for further discussion
Thanks for the reviews! |
As mentioned on the mailing list, I have been looking into changing the representation of scalars. This is also because the distinction between NumPy scalars and Python scalars would become larger with NEP 50.
This is an early draft for broad feedback for now. The current (not quite settled!) angle is that everything should print as:
np.float32(3.0)
, etc.longdouble
would have additional quotes (to round trip) and always uselongdouble
as name. (same for the type name)np.True_
(although that PR spells outnumpy
)np.longlong
prints asnumpy.longlong
butnp.longlong(3)
would show asnp.int64(3)
. I think that is the best way to do it.In any case, there are some details that can be discussed, and I am not sure if we may need a better way to spell
decimal.Decimal(repr(numpy_scalar))
(which is used in our tests).EDIT: The implementation to this is in gh-22449 (besides quite a bit of janitorial work, e.g. to actually update all of the docs. It seems refguide-check executes the
repr
and doesn't actually notice the change mostly.)