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
When it receives an out argument, np.take converts the out array to
the dtype of the array being taken from. This results in wrong TypeErrors
being raised when out has a larger dtype than the array (and not being
raised when it has a smaller dtype, even though they should):
a = np.arange(3, dtype=np.int16) + 128
b = np.empty((3,), dtype=np.int8)
a.take([0, 1, 2], out=b) # wrong, should raise an error
array([-128, -127, -126], dtype=int8)
b = np.empty((3,), dtype=np.int32)
a.take([0, 1, 2], out=b) # perfectly OK, but raises an error
Traceback (most recent call last):
File "", line 1, in
TypeError: Cannot cast array data from dtype('int32') to dtype('int16') according to the rule 'safe'
This PR makes an explicit casting check, then either sets NPY_ARRAY_FORCECAST
or explicitly raises the error.
The tests added check the logic for conversion between all pairs of ints and
floats only.
Please see the related PR for the existing work on the issue.
The text was updated successfully, but these errors were encountered:
From the related PR: #4246
The tests added check the logic for conversion between all pairs of ints and
floats only.
Please see the related PR for the existing work on the issue.
The text was updated successfully, but these errors were encountered: