You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 :-)
The text was updated successfully, but these errors were encountered:
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:
(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 :-)
The text was updated successfully, but these errors were encountered: