Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

meet-vasita
Copy link

@meet-vasita meet-vasita commented Aug 28, 2025

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

* 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.
@meet-vasita
Copy link
Author

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.
@seberg
Copy link
Member

seberg commented Aug 29, 2025

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 copy=False is very new).

I wonder what others think about this?

@seberg seberg added the triage review Issue/PR to be discussed at the next triage meeting label Aug 29, 2025
@meet-vasita
Copy link
Author

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.

@ngoldbaum
Copy link
Member

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 [skip cirrus] [skip actions] [skip azp] to your commit message. That will only run the CI on circleci, where we do the doc builds and other doctests.

@meet-vasita
Copy link
Author

Thanks for the clarification! I understand now that it makes more sense to fix the behavior instead of documenting it.

@eendebakpt
Copy link
Contributor

eendebakpt commented Aug 29, 2025

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.

@meet-vasita
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
04 - Documentation triage review Issue/PR to be discussed at the next triage meeting
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants