Skip to content
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

ENH: np.append should cast appended values to the dtype of the first argument #25640

Open
ngoldbaum opened this issue Jan 19, 2024 · 1 comment

Comments

@ngoldbaum
Copy link
Member

ngoldbaum commented Jan 19, 2024

Proposed new feature or change:

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.

@seberg
Copy link
Member

seberg commented 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).

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

No branches or pull requests

2 participants