-
-
Notifications
You must be signed in to change notification settings - Fork 10.8k
np.random.randint no longer supports non-native byteorder #13159
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
Probably from #11324; cc @eric-wieser. |
I think your example is proof that it silently ignored the byte order, not that it "worked". The current implementation is more honest in stating that nonnative byte order is not supported. For example,
It is worked, then the final 2 values would be identical. |
@bashtage is right, the order was ignored
However, this seems pretty par-for-the-course for numpy:
I think a patch that explicitly discards the byteorder (via |
@bashtage you are correct that byteorder is ignored, but this check is not correct. That is not the behaviour that's desired, nor is it consistent with other creation functions. Specifying byteorder does not change values, it changes storage. It's clearer to compare the result of In [2]: np.ones(3, dtype='>i4').tobytes()
Out[2]: b'\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00\x01'
In [3]: np.ones(3, dtype='<i4').tobytes()
Out[3]: b'\x01\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00' vs In [8]: np.random.seed(0); np.random.randint(200, size=10, dtype='>i4').tobytes()
Out[8]: b'\xac\x00\x00\x00/\x00\x00\x00u\x00\x00\x00\xc0\x00\x00\x00C\x00\x00\x00\xc3\x00\x00\x00g\x00\x00\x00\t\x00\x00\x00\x15\x00\x00\x00$\x00\x00\x00'
In [9]: np.random.seed(0); np.random.randint(200, size=10, dtype='<i4').tobytes()
Out[9]: b'\xac\x00\x00\x00/\x00\x00\x00u\x00\x00\x00\xc0\x00\x00\x00C\x00\x00\x00\xc3\x00\x00\x00g\x00\x00\x00\t\x00\x00\x00\x15\x00\x00\x00$\x00\x00\x00' |
Ping to everyone :) |
What do you think the right fix is here. Do you think it should explicitly
raise? Or do you think it should silently accept?
…On Mon, May 27, 2019, 17:05 Charles Harris ***@***.***> wrote:
Ping to everyone :)
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#13159?email_source=notifications&email_token=ABKTSRI7RM3LIKPV32WO4VTPXQBDJA5CNFSM4G7VL2XKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODWKEJEY#issuecomment-496256147>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABKTSRP3SRWLGGFLQ3OQZD3PXQBDJANCNFSM4G7VL2XA>
.
|
We could argue that it should go through deprecation before going to |
This is a patch in mattip#36 that produces a FutureWarning on this. It isn't a bug in the randomgen branch and would have silently run without doing any byte swapping. IMO it is better to leave this to users rather than push a |
Warn that non-native byte order is not supported in randint and integers closes numpy#13159
This used to work in NumPy 1.15:
Reproducing code example:
vs.
Error message:
Numpy/Python version information:
Python 3.6.7; NumPy 1.15.4 vs 1.16.2
The text was updated successfully, but these errors were encountered: