Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/numpy-stubs/@test/runtime/legacy/lib_user_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
15 changes: 8 additions & 7 deletions src/numpy-stubs/lib/_user_array_impl.pyi
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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_])
Expand All @@ -32,14 +32,15 @@ _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]

@overload
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: ...
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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: ...
Expand Down