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

Skip to content

DEP: Deprecate ndarray.resize#30181

Merged
mhvk merged 8 commits into
numpy:mainfrom
eendebakpt:ndarray_resize_deprecation
Jan 2, 2026
Merged

DEP: Deprecate ndarray.resize#30181
mhvk merged 8 commits into
numpy:mainfrom
eendebakpt:ndarray_resize_deprecation

Conversation

@eendebakpt
Copy link
Copy Markdown
Contributor

Addresses part of #28800

We deprecate ndarray.resize in the type hints. In a followup PR (probably for a next numpy release) we will issue a deprecating working when ndarray.resize is called.

@eendebakpt eendebakpt changed the title Draft: DEP: Deprecate ndarray.resize DEP: Deprecate ndarray.resize Nov 9, 2025
@eendebakpt eendebakpt requested a review from jorenham November 9, 2025 11:57
Copy link
Copy Markdown
Member

@jorenham jorenham left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got nothing to complain 👌

Copy link
Copy Markdown
Contributor

@mhvk mhvk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, makes sense!

@charris charris modified the milestone: 2.4.0 release Nov 9, 2025
Comment thread doc/release/upcoming_changes/30181.deprecation.rst Outdated
Comment thread doc/release/upcoming_changes/30181.deprecation.rst Outdated
Co-authored-by: Joren Hammudoglu <[email protected]>
@seberg
Copy link
Copy Markdown
Member

seberg commented Nov 10, 2025

Will we make type-hint only deprecations a pattern now? FWIW, it seems nice it seems like a nice way to potentially get some feedback about impact (and I guess some libraries may clean it up before there even is a warning, which is a small bonus too)!

I do have a slight worry with this one that while it won't be much code that is affected, it may not always be obvious how to replace resize. Typically, one can concate, sometimes use fromiter occasionally it may just be a reshape anyway.

The least obvious extreme case might be that the resize actually does make sense and one might have to use data = bytearray(...); tmp_view = np.frombuffer(data) (to actually keep reallocating).

@mhvk
Copy link
Copy Markdown
Contributor

mhvk commented Nov 10, 2025

Internally, we seem to use it mostly in places where we're reading from a file, and the array should be extended. I think this would often involve a copy (not sure how likely it is memory right after an array allocated earlier is still available). In any python code at least, this is fairly trivially done with concatenate.

@eendebakpt eendebakpt requested a review from mhvk January 2, 2026 13:18
Copy link
Copy Markdown
Contributor

@mhvk mhvk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this seems a good first step!

@mhvk mhvk merged commit 19fabe8 into numpy:main Jan 2, 2026
77 checks passed
Comment thread numpy/__init__.pyi
@deprecated("Resizing a NumPy array inplace has been deprecated in NumPy 2.4")
def resize(self, new_shape: _ShapeLike, /, *, refcheck: py_bool = True) -> None: ...
@overload
@deprecated("Resizing a NumPy array inplace has been deprecated in NumPy 2.4")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should these have been 2.5?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will make a prnto correct this tonight

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, sorry I missed that in review...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR is up at #30569

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants