8000 DEP: Deprecate setting the dtype of an exact numpy.ndarray by eendebakpt · Pull Request #29244 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

DEP: Deprecate setting the dtype of an exact numpy.ndarray #29244

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
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

eendebakpt
Copy link
Contributor
@eendebakpt eendebakpt commented Jun 20, 2025

Partly addresses #28800. A continuation of #28901.

We only deprecate setting the dtype of an exact array. For masked and record arrays it will take some more refactoring to avoid setting the dtype. 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).

@eendebakpt eendebakpt force-pushed the deprecate_array_dtype_set branch from 3ad7ba0 to 401cbca Compare June 24, 2025 14:13
< 8000 td class="blob-num blob-num-deletion empty-cell">
.. code-block:: python

>>> x = np.array([1, 2])
>>> x.dtype = np.bool
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jorenham This line gave an error in the CI because it emits a warning with this PR. Since changing the dtype is deprecated, I removed the example altogether.

Let me know if you want to keep it, I will then look for a way to suppress the warning.

Copy link
Member

Choose a reason for hiding this comment

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

I'm fine with removing this now that in-place dtype modifications are officially discouraged in general :)

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.

2 participants
0