8000 DEP: Deprecate setting the strides and dtype of a numpy array by eendebakpt · Pull Request #28901 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

DEP: Deprecate setting the strides and dtype of a numpy array #28901

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

Closed
wants to merge 15 commits into from
Prev Previous commit
Next Next commit
ci
  • Loading branch information
eendebakpt committed May 7, 2025
commit aacef24bb11e09c8ca097df7ecdbc67473847622
2 changes: 1 addition & 1 deletion numpy/lib/_stride_tricks_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def as_strided(x, shape=None, strides=None, subok=False, writeable=True):
# dtypes. Since dtype should remain unchanged, we set it explicitly.
with warnings.catch_warnings():
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd prefer not to have _set_dtype at all, but if we keep it, then this seems a good place to use it.

Copy link
Member

Choose a reason for hiding this comment

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

Agreed, the idea of having this work around, is exactly the ability to avoid any warning context managers both in NumPy (and potentially outside of NumPy).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed. I wanted to be on the safe side since there is a difference between .dtype = ... and ._set_dtype(...) for subclasses that override setting attributes. Here array is created by np.asarray so it is fine and I will update the code.

# gh-28901
warnings.filterwarnings("ignore", category=DeprecationWarning)
warnings.filterwarnings(action="ignore", category=DeprecationWarning)
array.dtype = x.dtype

view = _maybe_view_as_subclass(x, array)
Expand Down
0