From 22d238ac21ba26b6a726be651a177ec317524ad6 Mon Sep 17 00:00:00 2001 From: jorenham Date: Wed, 24 Dec 2025 14:32:10 +0100 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=91=BD=EF=B8=8F=20`lib.user=5Faray.co?= =?UTF-8?q?ntainer`=20deprecation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/numpy-stubs/lib/_user_array_impl.pyi | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/numpy-stubs/lib/_user_array_impl.pyi b/src/numpy-stubs/lib/_user_array_impl.pyi index 37ab2558..b73e1108 100644 --- a/src/numpy-stubs/lib/_user_array_impl.pyi +++ b/src/numpy-stubs/lib/_user_array_impl.pyi @@ -1,7 +1,7 @@ from _typeshed import Incomplete from types import EllipsisType from typing import Any, Generic, Self, SupportsIndex, TypeAlias, overload -from typing_extensions import TypeAliasType, TypeVar, override +from typing_extensions import TypeAliasType, TypeVar, deprecated, override import _numtype as _nt import numpy as np @@ -16,7 +16,7 @@ _ShapeT_co = TypeVar("_ShapeT_co", bound=_nt.Shape, default=Any, covariant=True) _DTypeT = TypeVar("_DTypeT", bound=np.dtype, default=np.dtype) _DTypeT_co = TypeVar("_DTypeT_co", bound=np.dtype, default=np.dtype, covariant=True) -_Container = TypeAliasType("_Container", container[_ShapeT, np.dtype[_ScalarT]], type_params=(_ScalarT, _ShapeT)) +_Container = TypeAliasType("_Container", container[_ShapeT, np.dtype[_ScalarT]], type_params=(_ScalarT, _ShapeT)) # pyright: ignore[reportDeprecated] _BoolArrayT = TypeVar("_BoolArrayT", bound=_Container[np.bool_]) _IntegralArrayT = TypeVar("_IntegralArrayT", bound=_Container[_nt.co_integer | np.object_]) @@ -32,6 +32,7 @@ _ToIndices: TypeAlias = _ToIndex | tuple[_ToIndex, ...] ### +@deprecated("The numpy.lib.user_array.container class is deprecated and will be removed in a future version.") class container(Generic[_ShapeT_co, _DTypeT_co]): array: np.ndarray[_ShapeT_co, _DTypeT_co] @@ -39,7 +40,7 @@ class container(Generic[_ShapeT_co, _DTypeT_co]): def __init__( self, /, - data: container[_ShapeT_co, _DTypeT_co] | np.ndarray[_ShapeT_co, _DTypeT_co], + data: container[_ShapeT_co, _DTypeT_co] | np.ndarray[_ShapeT_co, _DTypeT_co], # pyright: ignore[reportDeprecated] dtype: None = None, copy: bool = True, ) -> None: ... @@ -78,9 +79,9 @@ class container(Generic[_ShapeT_co, _DTypeT_co]): # keep in sync with np.ndarray @overload - def __getitem__(self, key: _ArrayInt_co | tuple[_ArrayInt_co, ...], /) -> container[_ShapeT_co, _DTypeT_co]: ... + def __getitem__(self, key: _ArrayInt_co | tuple[_ArrayInt_co, ...], /) -> container[_ShapeT_co, _DTypeT_co]: ... # pyright: ignore[reportDeprecated] @overload - def __getitem__(self, key: _ToIndexSlices, /) -> container[Any, _DTypeT_co]: ... + def __getitem__(self, key: _ToIndexSlices, /) -> container[Any, _DTypeT_co]: ... # pyright: ignore[reportDeprecated] @overload def __getitem__(self, key: _ToIndices, /) -> Any: ... @overload @@ -190,11 +191,11 @@ class container(Generic[_ShapeT_co, _DTypeT_co]): # @overload - def __array_wrap__(self, arg0: npt.ArrayLike, /) -> container[_ShapeT_co, _DTypeT_co]: ... + def __array_wrap__(self, arg0: npt.ArrayLike, /) -> container[_ShapeT_co, _DTypeT_co]: ... # pyright: ignore[reportDeprecated] @overload def __array_wrap__( self, a: np.ndarray[_ShapeT, _DTypeT], c: Any = ..., s: Any = ..., / - ) -> container[_ShapeT, _DTypeT]: ... + ) -> container[_ShapeT, _DTypeT]: ... # pyright: ignore[reportDeprecated] # def copy(self, /) -> Self: ... From 3b6e7d8163487df5a1ce54310b9db8a6f548b938 Mon Sep 17 00:00:00 2001 From: jorenham Date: Wed, 24 Dec 2025 14:34:51 +0100 Subject: [PATCH 2/2] =?UTF-8?q?=E2=9C=85=20update=20test=20for=20the=20`li?= =?UTF-8?q?b.user=5Farray.container`=20deprecation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/numpy-stubs/@test/runtime/legacy/lib_user_array.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/numpy-stubs/@test/runtime/legacy/lib_user_array.py b/src/numpy-stubs/@test/runtime/legacy/lib_user_array.py index 6a05d32e..0b6273f1 100644 --- a/src/numpy-stubs/@test/runtime/legacy/lib_user_array.py +++ b/src/numpy-stubs/@test/runtime/legacy/lib_user_array.py @@ -5,7 +5,7 @@ from typing import TYPE_CHECKING import numpy as np -from numpy.lib.user_array import container +from numpy.lib.user_array import container # pyright: ignore[reportDeprecated] if TYPE_CHECKING: import _numtype as _nt @@ -14,14 +14,14 @@ W = H = int(N**0.5) a: _nt.Array2D[np.int32] -ua: container[_nt.Rank2, np.dtype[np.int32]] +ua: container[_nt.Rank2, np.dtype[np.int32]] # pyright: ignore[reportDeprecated] a = np.arange(N, dtype=np.int32).reshape(W, H) -ua = container(a) +ua = container(a) # pyright: ignore[reportDeprecated] -ua_small: container[_nt.Rank2, np.dtype[np.int32]] = ua[:3, :5] +ua_small: container[_nt.Rank2, np.dtype[np.int32]] = ua[:3, :5] # pyright: ignore[reportDeprecated] ua_small[0, 0] = 10 -ua_bool: container[_nt.Rank2, np.dtype[np.bool]] = ua_small > 1 +ua_bool: container[_nt.Rank2, np.dtype[np.bool]] = ua_small > 1 # pyright: ignore[reportDeprecated] shape: tuple[int, int] = np.shape(ua)