-
-
Notifications
You must be signed in to change notification settings - Fork 12.2k
BUG: choose does an unnecessary cast of the initial out values #22237
Copy link
Copy link
Closed
Labels
Description
Describe the issue:
Choose (I think) always overwrites all values in the output. It is thus unnecessary to cast a given out to the resulting dtype (if a cast is necesssary).
This can lead to spurious warnings as given in the below example
Reproduce the code example:
import numpy as np
a = np.arange(3)
b = np.ones((3, 3), dtype=np.int64)
out = np.array([np.nan, np.nan, np.nan])
np.choose(a, b, out=out)Error message:
/home/sebastian/forks/numpy/build/testenv/lib/python3.9/site-packages/numpy/core/fromnumeric.py:57: RuntimeWarning: invalid value encountered in cast
return bound(*args, **kwds)NumPy/Python version information:
All versions up to 1.24-dev will do the unnecessary cast, but only the current dev gives the spurious warning.
(We have a typing test that could run into this randomly, although I am changing it in a different PR)
Context for the issue:
No response
Reactions are currently unavailable