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

Skip to content

Conversation

eendebakpt
Copy link
Contributor

Partly addresses #28800. A continuation of #28901 and #29244.

We deprecate setting the dtype of an numpy arrays. For masked and record arrays no warnings are generated, as the dtype usage is a bit more complex (in a followup PR we can enable deprecation warnings by modifying the dtype setter logic). We skip warnings for pypy as we cannot rely on reference counting to avoid warnings when the dtype is changed via array.view(new_dtype).

Copy link
Member

@ngoldbaum ngoldbaum left a comment

Choose a reason for hiding this comment

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

Have you looked at all at how noisy this is downstream? It's a little hard to search for but I suspect this pattern is used quite a bit. It would probably help us to understand what downstream usage looks like to try running some downstream test suites with a patched numpy to see how noisy it is.

SciPy is probably a good choice, maybe astropy too because they implement an ndarray subclass. I'd skip pandas because its test suite takes a very long time to run outside of github actions.

@eendebakpt
Copy link
Contributor Author

Have you looked at all at how noisy this is downstream? It's a little hard to search for but I suspect this pattern is used quite a bit. It would probably help us to understand what downstream usage looks like to try running some downstream test suites with a patched numpy to see how noisy it is.

SciPy is probably a good choice, maybe astropy too because they implement an ndarray subclass. I'd skip pandas because its test suite takes a very long time to run outside of github actions.

Astropy indeed uses setting the dtype and shape. I created a ticket and a PR astropy/astropy#18562. Lets see how this is picked up before merging this PR.

@eendebakpt
Copy link
Contributor Author

In astropy the only deprecated cases left are cases where we expect to use the new ndarray._set_dtype from this PR. So I think this PR is ready.

Alternatively, we split this PR to first merge the _set_dtype and merge the rest a bit later (when downstream has had some time to adapt).

@mattip
Copy link
Member

mattip commented Sep 10, 2025

Since there is a PR ready to go, I don't think it is worth the effort to split this.

Grepping around in pandas, it seems the only uses are in self.dtype = in non-ndarray class __init__ methods. Maybe I am optimistic.

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.

3 participants