-
-
Notifications
You must be signed in to change notification settings - Fork 11.3k
DOC: Document scalar.astype() always returns array, copy=False ignored #29638
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
base: main
Are you sure you want to change the base?
Conversation
* Add note in scalars documentation explaining astype behavior difference * Clarify that scalar.astype() always returns ndarray, never scalar * Document that copy=False parameter has no effect for scalars * Helps resolve user confusion about inconsistent behavior vs arrays The current documentation only covers numpy.ndarray.astype() but scalars also have an astype() method with different behavior. This addition makes the difference explicit and prevents user confusion.
Im Trying to solve this ''BUG: np.astype(copy=False) copies for scalars #29455'' |
* Add note in scalars documentation explaining astype behavior difference * Clarify that scalar.astype() always returns ndarray, never scalar * Document that copy=False parameter has no effect for scalars * Helps resolve user confusion about inconsistent behavior vs arrays The current documentation only covers numpy.ndarray.astype() but scalars also have an astype() method with different behavior. This addition makes the difference explicit and prevents user confusion.
Thank you, but I think we should probably consider this a bug, although I could imagine it being common enough that I am not 100% sure about it (and it might even be good to go via a deprecation, even though I wonder what others think about this? |
Thanks for the feedback! I see your point about this being more of a bug than just a documentation issue. I’m happy to adjust the PR depending on what the maintainers decide (e.g., updating docs, working on a deprecation path, or helping with a fix). Please let me know the preferred next step. |
I agree it doesn't make much sense to document this bad behavior. We should just fix it. Also for future documentation-only PRs, consider adding |
Thanks for the clarification! I understand now that it makes more sense to fix the behavior instead of documenting it. |
I have a branch that addresses part of the issue main...eendebakpt:numpy:astype. It relaxes the documentation a bit and (for the common case) avoids the copy. @meet-vasita If you are interested, feel free to convert the branch into a PR. |
Thanks for sharing this! 🙏 I’d be happy to pick up your branch and convert it into a PR. I’ll test it locally and update the docs/tests as needed |
Add note in scalars documentation explaining astype behavior difference
Clarify that scalar.astype() always returns ndarray, never scalar
Document that copy=False parameter has no effect for scalars
Helps resolve user confusion about inconsistent behavior vs arrays