Skip to content

TSK: deprecate setting strides, dtype, and shape on arrays. #28800

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
ngoldbaum opened this issue Apr 23, 2025 · 3 comments
Open

TSK: deprecate setting strides, dtype, and shape on arrays. #28800

ngoldbaum opened this issue Apr 23, 2025 · 3 comments
Labels
17 - Task 39 - free-threading PRs and issues related to support for free-threading CPython (a.k.a. no-GIL, PEP 703)
Milestone

Comments

@ngoldbaum
Copy link
Member

As seen in #28727, mutating arrays like this is dangerous in surprising ways, particularly on the free-threaded build.

We should guide people towards safer alternatives that create new views or copies of arrays instead of mutating.

We should first try deprecating strides and dtype, then shape, since we expect that setting shape is used the most (before np.reshape it was the only way to do it).

To do the actual deprecation, first someone needs to add the warning and deal with any fallout in the NumPy tests. Make sure the deprecation warnings indicate clearly how to update affected code. It would also be good to look at some downstream libraries like SciPy, matplotlib, pandas, and scikit-learn to see how much noise these deprecations cause in downstream tests.

If it isn't too bad and the fixes are straightforward, we should be good to go.

@ngoldbaum ngoldbaum added 17 - Task 39 - free-threading PRs and issues related to support for free-threading CPython (a.k.a. no-GIL, PEP 703) labels Apr 23, 2025
@seberg
Copy link
Member

seberg commented Apr 23, 2025

(before np.reshape it was the only way to do it).

Tiny correction: Reshape always existed, but raising an error when it failed with copy=False is new (i.e. knowing that the result is a view). Although, the copy was made even on error before.

But yeah, shape assignment was/is pretty common (I have seen it in educational materials, maybe it still is).

@jorenham
Copy link
Member

jorenham commented Apr 23, 2025

Yes please! The no. 1 rule of typing is that types don't change, and dtype and shape are part of the ndarray type.

@ricardoV94
Copy link

ricardoV94 commented May 8, 2025

It may be useful to make as_strided faster. It's rather slow compared to transpose / reshape (for the cases where it is identical), even though it shouldn't be doing more work than either of those

@charris charris modified the milestones: 2.3.0 release, 2.4.0 release May 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
17 - Task 39 - free-threading PRs and issues related to support for free-threading CPython (a.k.a. no-GIL, PEP 703)
Projects
None yet
Development

No branches or pull requests

5 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy