Repository navigation
DOC: Clarify copy parameter semantics in nan_to_num (gh-29045) - #32575
Merged
Merged
Conversation
jorenham
reviewed
Sep 10, 2026
jorenham
left a comment
Member
There was a problem hiding this comment.
don't forget to also update the type stubs :)
numpy/numpy/lib/_type_check_impl.pyi
Lines 102 to 205 in 9a1b9dd
Contributor
Author
Done! Updated all Thanks for pointing that out! |
ngoldbaum
reviewed
Sep 10, 2026
Comment on lines
-393
to
-394
| in-place (False). The in-place operation only occurs if | ||
| casting to an array does not require a copy. |
Member
There was a problem hiding this comment.
You shouldn't remove this sentence you deleted
Contributor
Author
There was a problem hiding this comment.
Good catch, thanks! I've restored the sentence and pushed an update in commit 623baa3.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR summary
Closes gh-29045
This PR updates the docstring of
np.nan_to_numand itsReturnssection innumpy/lib/_type_check_impl.pyto accurately reflect NumPy 2.0+copykeyword semantics:copyparameter description frombooltobool or None.copy=Falseraises aValueErrorif a copy cannot be avoided (such as when passing sequences or when type casting is required), rather than silently copying.copy=Noneprovides the "copy only if needed" behavior (or in-place if possible).Returnssection to state thatxitself may be returned whencopyisFalseorNone.This follows the guidance from @seberg on gh-29045 noting that this was purely a documentation discrepancy with the NumPy 2.0 copy keyword policy.
First time committer introduction
Hi everyone! I am Anush, first-time contributor to NumPy. I use Python and NumPy regularly for my projects and open-source learning. I noticed this documentation discrepancy regarding NumPy 2.0's copy semantics in
nan_to_numand wanted to contribute by clarifying it for users.AI Disclosure
An AI coding assistant (Google Antigravity / Gemini) was used to help locate the issue and draft the initial docstring wording. The changes, runtime behavior (
copy=True,copy=False,copy=None), and edge cases were manually tested and verified locally, and this pull request is reviewed and submitted by me.