8000 numpy 2.0: a possible API inconsistency in `numpy.ndarray.astype` (copy semantics) ? · Issue #25925 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

numpy 2.0: a possible API inconsistency in numpy.ndarray.astype (copy semantics) ? #25925

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

Closed
neutrinoceros opened this issue Mar 4, 2024 · 2 comments
Milestone

Comments

@neutrinoceros
Copy link
Contributor
neutrinoceros commented Mar 4, 2024

As I'm adapting astropy to the new copy semantics from #25168 and #25922, I observe that numpy.ndarray.astype wasn't updated to follow these changes. As a result, it still supports the old semantics where copy=False means "copy only if you must" but never raises an error. Is that intended ?

numpy.astype, introduced in #25079, is also affected by this question.

@mattip mattip added this to the 2.0.0 release milestone Mar 4, 2024
@rgommers
Copy link
Member
rgommers commented Mar 4, 2024

@neutrinoceros thanks for the question. Yes, this was intentional, since there wasn't too much appetite for changing the behavior of copy=False given that astype explicitly casts to a different dtype - and that usually cannot be done without a copy. It's noted in NEP 56: https://numpy.org/neps/nep-0056-array-api-main-namespace.html#copy-keyword-semantics.

I checked that astype does accept all of True/False/None. False just doesn't mean "never copy". Does that seem reasonable?

@neutrinoceros
Copy link
Contributor Author

Absolutely ! Just wanted to check with you before the first release candidate if I could :)
Let's just close this then. Good luck with the release !

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

3 participants
0