DOC: document caveats of ndarray.resize on 3.14 and newer#31058
Merged
charris merged 10 commits intonumpy:maintenance/2.4.xfrom Mar 24, 2026
Merged
DOC: document caveats of ndarray.resize on 3.14 and newer#31058charris merged 10 commits intonumpy:maintenance/2.4.xfrom
charris merged 10 commits intonumpy:maintenance/2.4.xfrom
Conversation
Co-authored-by: Matti Picus <[email protected]>
Co-authored-by: Matti Picus <[email protected]>
Co-authored-by: Matti Picus <[email protected]>
Also fix typo.
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.
Backport of #31021.
Closes #30991.
This doesn't "fix" the regression, because I don't think there's a way to do that without introducing new bugs or depending on interpreter internals and/or trying to argue for yet another
PyUnstableC API function we can use.I'm also a little concerned that the old check is actually incorrect for arrays created by C extensions: the check on 3.13 and older allows resizing an array created directly via e.g.
PyArray_FromAnywith exactly one reference.IMO it's better to keep the logic of the check the same and simply improve the documentation and error messages.
Now when the reference count is exactly 2, the error message on 3.14 and newer explains that this might be a false positive.
I added tests which trigger the behaviors we expect to happen on different Python versions. I also deleted some out-of-date docs about an unused
orderargument and added some notes that resizing in-place can lead to memory fragmentation and worse overall memory usage.Also looking for any ideas for ways to make the error messages and docstrings less wordy.
-->