8000 BUG: `take` casting logic with an `out=` argument · Issue #16319 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

BUG: take casting logic with an out= argument #16319

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

Open
anirudh2290 opened this issue May 20, 2020 · 0 comments
Open

BUG: take casting logic with an out= argument #16319

anirudh2290 opened this issue May 20, 2020 · 0 comments

Comments

@anirudh2290
Copy link
Member

From the related PR: #4246

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.

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

Successfully merging a pull request may close this issue.

2 participants
0