Skip to content

DOC: document caveats of ndarray.resize on 3.14 and newer#31058

Merged
charris merged 10 commits intonumpy:maintenance/2.4.xfrom
charris:backport-31021
Mar 24, 2026
Merged

DOC: document caveats of ndarray.resize on 3.14 and newer#31058
charris merged 10 commits intonumpy:maintenance/2.4.xfrom
charris:backport-31021

Conversation

@charris
Copy link
Copy Markdown
Member

@charris charris commented Mar 24, 2026

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 PyUnstable C 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_FromAny with 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 order argument 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.
-->

@charris charris added this to the 2.4.4 release milestone Mar 24, 2026
@charris charris added 04 - Documentation 08 - Backport Used to tag backport PRs labels Mar 24, 2026
@charris charris merged commit 8052c4b into numpy:maintenance/2.4.x Mar 24, 2026
73 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

04 - Documentation 08 - Backport Used to tag backport PRs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants