_user_array_impl.pyi 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. from _typeshed import Incomplete
  2. from types import EllipsisType
  3. from typing import Any, Generic, Self, SupportsIndex, TypeAlias, overload
  4. from typing_extensions import TypeVar, deprecated, override
  5. import numpy as np
  6. import numpy.typing as npt
  7. from numpy._typing import (
  8. _AnyShape,
  9. _ArrayLike,
  10. _ArrayLikeBool_co,
  11. _ArrayLikeInt_co,
  12. _DTypeLike,
  13. )
  14. ###
  15. _ScalarT = TypeVar("_ScalarT", bound=np.generic)
  16. _ShapeT = TypeVar("_ShapeT", bound=tuple[int, ...])
  17. _ShapeT_co = TypeVar("_ShapeT_co", bound=tuple[int, ...], default=_AnyShape, covariant=True)
  18. _DTypeT = TypeVar("_DTypeT", bound=np.dtype)
  19. _DTypeT_co = TypeVar("_DTypeT_co", bound=np.dtype, default=np.dtype, covariant=True)
  20. _BoolArrayT = TypeVar("_BoolArrayT", bound=container[Any, np.dtype[np.bool]])
  21. _IntegralArrayT = TypeVar("_IntegralArrayT", bound=container[Any, np.dtype[np.bool | np.integer | np.object_]])
  22. _RealContainerT = TypeVar(
  23. "_RealContainerT",
  24. bound=container[Any, np.dtype[np.bool | np.integer | np.floating | np.timedelta64 | np.object_]],
  25. )
  26. _NumericContainerT = TypeVar("_NumericContainerT", bound=container[Any, np.dtype[np.number | np.timedelta64 | np.object_]])
  27. _ArrayInt_co: TypeAlias = npt.NDArray[np.integer | np.bool]
  28. _ToIndexSlice: TypeAlias = slice | EllipsisType | _ArrayInt_co | None
  29. _ToIndexSlices: TypeAlias = _ToIndexSlice | tuple[_ToIndexSlice, ...]
  30. _ToIndex: TypeAlias = SupportsIndex | _ToIndexSlice
  31. _ToIndices: TypeAlias = _ToIndex | tuple[_ToIndex, ...]
  32. ###
  33. # pyright: reportDeprecated = false
  34. @deprecated("The numpy.lib.user_array.container class is deprecated and will be removed in a future version.")
  35. class container(Generic[_ShapeT_co, _DTypeT_co]):
  36. array: np.ndarray[_ShapeT_co, _DTypeT_co]
  37. @overload
  38. def __init__(
  39. self,
  40. /,
  41. data: container[_ShapeT_co, _DTypeT_co] | np.ndarray[_ShapeT_co, _DTypeT_co],
  42. dtype: None = None,
  43. copy: bool = True,
  44. ) -> None: ...
  45. @overload
  46. def __init__(
  47. self: container[Any, np.dtype[_ScalarT]],
  48. /,
  49. data: _ArrayLike[_ScalarT],
  50. dtype: None = None,
  51. copy: bool = True,
  52. ) -> None: ...
  53. @overload
  54. def __init__(
  55. self: container[Any, np.dtype[_ScalarT]],
  56. /,
  57. data: npt.ArrayLike,
  58. dtype: _DTypeLike[_ScalarT],
  59. copy: bool = True,
  60. ) -> None: ...
  61. @overload
  62. def __init__(self, /, data: npt.ArrayLike, dtype: npt.DTypeLike | None = None, copy: bool = True) -> None: ...
  63. #
  64. def __complex__(self, /) -> complex: ...
  65. def __float__(self, /) -> float: ...
  66. def __int__(self, /) -> int: ...
  67. def __hex__(self, /) -> str: ...
  68. def __oct__(self, /) -> str: ...
  69. #
  70. @override
  71. def __eq__(self, other: object, /) -> container[_ShapeT_co, np.dtype[np.bool]]: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
  72. @override
  73. def __ne__(self, other: object, /) -> container[_ShapeT_co, np.dtype[np.bool]]: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
  74. #
  75. def __lt__(self, other: npt.ArrayLike, /) -> container[_ShapeT_co, np.dtype[np.bool]]: ...
  76. def __le__(self, other: npt.ArrayLike, /) -> container[_ShapeT_co, np.dtype[np.bool]]: ...
  77. def __gt__(self, other: npt.ArrayLike, /) -> container[_ShapeT_co, np.dtype[np.bool]]: ...
  78. def __ge__(self, other: npt.ArrayLike, /) -> container[_ShapeT_co, np.dtype[np.bool]]: ...
  79. #
  80. def __len__(self, /) -> int: ...
  81. # keep in sync with np.ndarray
  82. @overload
  83. def __getitem__(self, key: _ArrayInt_co | tuple[_ArrayInt_co, ...], /) -> container[_ShapeT_co, _DTypeT_co]: ...
  84. @overload
  85. def __getitem__(self, key: _ToIndexSlices, /) -> container[_AnyShape, _DTypeT_co]: ...
  86. @overload
  87. def __getitem__(self, key: _ToIndices, /) -> Any: ...
  88. @overload
  89. def __getitem__(self: container[Any, np.dtype[np.void]], key: list[str], /) -> container[_ShapeT_co, np.dtype[np.void]]: ...
  90. @overload
  91. def __getitem__(self: container[Any, np.dtype[np.void]], key: str, /) -> container[_ShapeT_co, np.dtype]: ...
  92. # keep in sync with np.ndarray
  93. @overload
  94. def __setitem__(self, index: _ToIndices, value: object, /) -> None: ...
  95. @overload
  96. def __setitem__(self: container[Any, np.dtype[np.void]], key: str | list[str], value: object, /) -> None: ...
  97. # keep in sync with np.ndarray
  98. @overload
  99. def __abs__(self: container[_ShapeT, np.dtype[np.complex64]], /) -> container[_ShapeT, np.dtype[np.float32]]: ... # type: ignore[overload-overlap]
  100. @overload
  101. def __abs__(self: container[_ShapeT, np.dtype[np.complex128]], /) -> container[_ShapeT, np.dtype[np.float64]]: ...
  102. @overload
  103. def __abs__(self: container[_ShapeT, np.dtype[np.complex192]], /) -> container[_ShapeT, np.dtype[np.float96]]: ...
  104. @overload
  105. def __abs__(self: container[_ShapeT, np.dtype[np.complex256]], /) -> container[_ShapeT, np.dtype[np.float128]]: ...
  106. @overload
  107. def __abs__(self: _RealContainerT, /) -> _RealContainerT: ...
  108. #
  109. def __neg__(self: _NumericContainerT, /) -> _NumericContainerT: ... # noqa: PYI019
  110. def __pos__(self: _NumericContainerT, /) -> _NumericContainerT: ... # noqa: PYI019
  111. def __invert__(self: _IntegralArrayT, /) -> _IntegralArrayT: ... # noqa: PYI019
  112. # TODO(jorenham): complete these binary ops
  113. #
  114. def __add__(self, other: npt.ArrayLike, /) -> Incomplete: ...
  115. def __radd__(self, other: npt.ArrayLike, /) -> Incomplete: ...
  116. def __iadd__(self, other: npt.ArrayLike, /) -> Self: ...
  117. #
  118. def __sub__(self, other: npt.ArrayLike, /) -> Incomplete: ...
  119. def __rsub__(self, other: npt.ArrayLike, /) -> Incomplete: ...
  120. def __isub__(self, other: npt.ArrayLike, /) -> Self: ...
  121. #
  122. def __mul__(self, other: npt.ArrayLike, /) -> Incomplete: ...
  123. def __rmul__(self, other: npt.ArrayLike, /) -> Incomplete: ...
  124. def __imul__(self, other: npt.ArrayLike, /) -> Self: ...
  125. #
  126. def __mod__(self, other: npt.ArrayLike, /) -> Incomplete: ...
  127. def __rmod__(self, other: npt.ArrayLike, /) -> Incomplete: ...
  128. def __imod__(self, other: npt.ArrayLike, /) -> Self: ...
  129. #
  130. def __divmod__(self, other: npt.ArrayLike, /) -> tuple[Incomplete, Incomplete]: ...
  131. def __rdivmod__(self, other: npt.ArrayLike, /) -> tuple[Incomplete, Incomplete]: ...
  132. #
  133. def __pow__(self, other: npt.ArrayLike, /) -> Incomplete: ...
  134. def __rpow__(self, other: npt.ArrayLike, /) -> Incomplete: ...
  135. def __ipow__(self, other: npt.ArrayLike, /) -> Self: ...
  136. #
  137. def __lshift__(self, other: _ArrayLikeInt_co, /) -> container[_AnyShape, np.dtype[np.integer]]: ...
  138. def __rlshift__(self, other: _ArrayLikeInt_co, /) -> container[_AnyShape, np.dtype[np.integer]]: ...
  139. def __ilshift__(self, other: _ArrayLikeInt_co, /) -> Self: ...
  140. #
  141. def __rshift__(self, other: _ArrayLikeInt_co, /) -> container[_AnyShape, np.dtype[np.integer]]: ...
  142. def __rrshift__(self, other: _ArrayLikeInt_co, /) -> container[_AnyShape, np.dtype[np.integer]]: ...
  143. def __irshift__(self, other: _ArrayLikeInt_co, /) -> Self: ...
  144. #
  145. @overload
  146. def __and__(
  147. self: container[Any, np.dtype[np.bool]], other: _ArrayLikeBool_co, /
  148. ) -> container[_AnyShape, np.dtype[np.bool]]: ...
  149. @overload
  150. def __and__(self, other: _ArrayLikeInt_co, /) -> container[_AnyShape, np.dtype[np.bool | np.integer]]: ...
  151. __rand__ = __and__
  152. @overload
  153. def __iand__(self: _BoolArrayT, other: _ArrayLikeBool_co, /) -> _BoolArrayT: ...
  154. @overload
  155. def __iand__(self, other: _ArrayLikeInt_co, /) -> Self: ...
  156. #
  157. @overload
  158. def __xor__(
  159. self: container[Any, np.dtype[np.bool]], other: _ArrayLikeBool_co, /
  160. ) -> container[_AnyShape, np.dtype[np.bool]]: ...
  161. @overload
  162. def __xor__(self, other: _ArrayLikeInt_co, /) -> container[_AnyShape, np.dtype[np.bool | np.integer]]: ...
  163. __rxor__ = __xor__
  164. @overload
  165. def __ixor__(self: _BoolArrayT, other: _ArrayLikeBool_co, /) -> _BoolArrayT: ...
  166. @overload
  167. def __ixor__(self, other: _ArrayLikeInt_co, /) -> Self: ...
  168. #
  169. @overload
  170. def __or__(
  171. self: container[Any, np.dtype[np.bool]], other: _ArrayLikeBool_co, /
  172. ) -> container[_AnyShape, np.dtype[np.bool]]: ...
  173. @overload
  174. def __or__(self, other: _ArrayLikeInt_co, /) -> container[_AnyShape, np.dtype[np.bool | np.integer]]: ...
  175. __ror__ = __or__
  176. @overload
  177. def __ior__(self: _BoolArrayT, other: _ArrayLikeBool_co, /) -> _BoolArrayT: ...
  178. @overload
  179. def __ior__(self, other: _ArrayLikeInt_co, /) -> Self: ...
  180. #
  181. @overload
  182. def __array__(self, /, t: None = None) -> np.ndarray[_ShapeT_co, _DTypeT_co]: ...
  183. @overload
  184. def __array__(self, /, t: _DTypeT) -> np.ndarray[_ShapeT_co, _DTypeT]: ...
  185. #
  186. @overload
  187. def __array_wrap__(self, arg0: npt.ArrayLike, /) -> container[_ShapeT_co, _DTypeT_co]: ...
  188. @overload
  189. def __array_wrap__(self, a: np.ndarray[_ShapeT, _DTypeT], c: Any = ..., s: Any = ..., /) -> container[_ShapeT, _DTypeT]: ...
  190. #
  191. def copy(self, /) -> Self: ...
  192. def tobytes(self, /) -> bytes: ...
  193. def byteswap(self, /) -> Self: ...
  194. def astype(self, /, typecode: _DTypeLike[_ScalarT]) -> container[_ShapeT_co, np.dtype[_ScalarT]]: ...