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
{{ message }}
Repository navigation
ENH: np.append should cast appended values to the dtype of the first argument #25640
Right now np.append will convert both operands to an array first, then combine the result. This produces suboptimal results for stringdtype and a scalar operand:
Pdb) np.append(stringdtype_array, "hello")
*** ValueError: Cannot find common instance for unequal dtype instances
If instead we cast the second argument to the dtype of the first argument, this would succeed.
Note that this problem is particular to StringDType, but relying on numpy coercing the arguments to built-in dtypes is probably less forward looking than casting to the dtype of the first argument.
Activity
seberg commentedon Jan 20, 2024
See also gh-22429. While I agree that append shouldn't promote, I am not certain how well we can get away with it.
I am surprised about not allowing the promotion here, but I guess it is the conservative thing to do (easier to relax).