Skip to content
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

Inconsistent behavior of "same_kind" casting wrt. signed/unsigned ints #8039

Open
anntzer opened this issue Sep 11, 2016 · 0 comments
Open

Comments

@anntzer
Copy link
Contributor

anntzer commented Sep 11, 2016

Initially noticed in #8034: "same_kind" casting refuses to drop a minus sign when casting signed int -> unsigned int, but happily wraps around large values to negative values when casting unsigned int -> signed int:

In [17]: np.array(-1, np.byte).astype(np.ubyte, casting="same_kind")
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-17-100f7edb5d2f> in <module>()
----> 1 np.array(-1, np.byte).astype(np.ubyte, casting="same_kind")

TypeError: Cannot cast array from dtype('int8') to dtype('uint8') according to the rule 'same_kind'

In [18]: np.array(129, np.ubyte).astype(np.byte, casting="same_kind")
Out[18]: array(-127, dtype=int8)

(This is also affects casting of arrays: their values are specifically checked.)
I personally think the latter behavior (wraparound allowed) should be used in both cases... but at least it should be consistent :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant