summaryrefslogtreecommitdiff
path: root/numpy/core/fromnumeric.pyi
diff options
context:
space:
mode:
Diffstat (limited to 'numpy/core/fromnumeric.pyi')
-rw-r--r--numpy/core/fromnumeric.pyi378
1 files changed, 128 insertions, 250 deletions
diff --git a/numpy/core/fromnumeric.pyi b/numpy/core/fromnumeric.pyi
index 66eb3bfb8..3342ec3ac 100644
--- a/numpy/core/fromnumeric.pyi
+++ b/numpy/core/fromnumeric.pyi
@@ -6,12 +6,11 @@ from numpy import (
ndarray,
number,
integer,
+ intp,
bool_,
generic,
_OrderKACF,
_OrderACF,
- _ArrayLikeBool,
- _ArrayLikeIntOrBool,
_ModeKind,
_PartitionKind,
_SortKind,
@@ -22,9 +21,9 @@ from numpy.typing import (
ArrayLike,
_ShapeLike,
_Shape,
- _IntLike,
- _BoolLike,
- _NumberLike,
+ _ArrayLikeBool_co,
+ _ArrayLikeInt_co,
+ _NumberLike_co,
)
if sys.version_info >= (3, 8):
@@ -42,11 +41,7 @@ _ScalarBuiltin = Union[str, bytes, dt.date, dt.timedelta, bool, int, float, comp
_Scalar = Union[_ScalarBuiltin, _ScalarNumpy]
# Integers and booleans can generally be used interchangeably
-_ScalarIntOrBool = TypeVar("_ScalarIntOrBool", bound=Union[integer, bool_])
_ScalarGeneric = TypeVar("_ScalarGeneric", bound=generic)
-_ScalarGenericDT = TypeVar(
- "_ScalarGenericDT", bound=Union[dt.datetime, dt.timedelta, generic]
-)
_Number = TypeVar("_Number", bound=number)
@@ -55,144 +50,145 @@ _Number = TypeVar("_Number", bound=number)
# 2. A scalar comes in; a generic comes out
# 3. An array-like object comes in; some keyword ensures that a generic comes out
# 4. An array-like object comes in; an ndarray or generic comes out
-@overload
-def take(
- a: _ScalarGenericDT,
- indices: int,
- axis: Optional[int] = ...,
- out: Optional[ndarray] = ...,
- mode: _ModeKind = ...,
-) -> _ScalarGenericDT: ...
-@overload
-def take(
- a: _Scalar,
- indices: int,
- axis: Optional[int] = ...,
- out: Optional[ndarray] = ...,
- mode: _ModeKind = ...,
-) -> _ScalarNumpy: ...
-@overload
def take(
a: ArrayLike,
- indices: int,
+ indices: _ArrayLikeInt_co,
axis: Optional[int] = ...,
out: Optional[ndarray] = ...,
mode: _ModeKind = ...,
-) -> _ScalarNumpy: ...
-@overload
-def take(
+) -> Any: ...
+
+def reshape(
a: ArrayLike,
- indices: _ArrayLikeIntOrBool,
- axis: Optional[int] = ...,
- out: Optional[ndarray] = ...,
- mode: _ModeKind = ...,
-) -> Union[_ScalarNumpy, ndarray]: ...
-def reshape(a: ArrayLike, newshape: _ShapeLike, order: _OrderACF = ...) -> ndarray: ...
-@overload
-def choose(
- a: _ScalarIntOrBool,
- choices: ArrayLike,
- out: Optional[ndarray] = ...,
- mode: _ModeKind = ...,
-) -> _ScalarIntOrBool: ...
-@overload
-def choose(
- a: Union[_IntLike, _BoolLike], choices: ArrayLike, out: Optional[ndarray] = ..., mode: _ModeKind = ...
-) -> Union[integer, bool_]: ...
-@overload
+ newshape: _ShapeLike,
+ order: _OrderACF = ...,
+) -> ndarray: ...
+
def choose(
- a: _ArrayLikeIntOrBool,
+ a: _ArrayLikeInt_co,
choices: ArrayLike,
out: Optional[ndarray] = ...,
mode: _ModeKind = ...,
-) -> ndarray: ...
+) -> Any: ...
+
def repeat(
- a: ArrayLike, repeats: _ArrayLikeIntOrBool, axis: Optional[int] = ...
+ a: ArrayLike,
+ repeats: _ArrayLikeInt_co,
+ axis: Optional[int] = ...,
) -> ndarray: ...
+
def put(
- a: ndarray, ind: _ArrayLikeIntOrBool, v: ArrayLike, mode: _ModeKind = ...
+ a: ndarray,
+ ind: _ArrayLikeInt_co,
+ v: ArrayLike,
+ mode: _ModeKind = ...,
) -> None: ...
-def swapaxes(a: ArrayLike, axis1: int, axis2: int) -> ndarray: ...
+
+def swapaxes(
+ a: ArrayLike,
+ axis1: int,
+ axis2: int,
+) -> ndarray: ...
+
def transpose(
- a: ArrayLike, axes: Union[None, Sequence[int], ndarray] = ...
+ a: ArrayLike,
+ axes: Union[None, Sequence[int], ndarray] = ...
) -> ndarray: ...
+
def partition(
a: ArrayLike,
- kth: _ArrayLikeIntOrBool,
+ kth: _ArrayLikeInt_co,
axis: Optional[int] = ...,
kind: _PartitionKind = ...,
order: Union[None, str, Sequence[str]] = ...,
) -> ndarray: ...
-@overload
-def argpartition(
- a: generic,
- kth: _ArrayLikeIntOrBool,
- axis: Optional[int] = ...,
- kind: _PartitionKind = ...,
- order: Union[None, str, Sequence[str]] = ...,
-) -> integer: ...
-@overload
-def argpartition(
- a: _ScalarBuiltin,
- kth: _ArrayLikeIntOrBool,
- axis: Optional[int] = ...,
- kind: _PartitionKind = ...,
- order: Union[None, str, Sequence[str]] = ...,
-) -> ndarray: ...
-@overload
+
def argpartition(
a: ArrayLike,
- kth: _ArrayLikeIntOrBool,
+ kth: _ArrayLikeInt_co,
axis: Optional[int] = ...,
kind: _PartitionKind = ...,
order: Union[None, str, Sequence[str]] = ...,
-) -> ndarray: ...
+) -> Any: ...
+
def sort(
a: ArrayLike,
axis: Optional[int] = ...,
kind: Optional[_SortKind] = ...,
order: Union[None, str, Sequence[str]] = ...,
) -> ndarray: ...
+
def argsort(
a: ArrayLike,
axis: Optional[int] = ...,
kind: Optional[_SortKind] = ...,
order: Union[None, str, Sequence[str]] = ...,
) -> ndarray: ...
+
@overload
-def argmax(a: ArrayLike, axis: None = ..., out: Optional[ndarray] = ...) -> integer: ...
+def argmax(
+ a: ArrayLike,
+ axis: None = ...,
+ out: Optional[ndarray] = ...,
+) -> intp: ...
@overload
def argmax(
- a: ArrayLike, axis: int = ..., out: Optional[ndarray] = ...
-) -> Union[integer, ndarray]: ...
+ a: ArrayLike,
+ axis: Optional[int] = ...,
+ out: Optional[ndarray] = ...,
+) -> Any: ...
+
@overload
-def argmin(a: ArrayLike, axis: None = ..., out: Optional[ndarray] = ...) -> integer: ...
+def argmin(
+ a: ArrayLike,
+ axis: None = ...,
+ out: Optional[ndarray] = ...,
+) -> intp: ...
@overload
def argmin(
- a: ArrayLike, axis: int = ..., out: Optional[ndarray] = ...
-) -> Union[integer, ndarray]: ...
+ a: ArrayLike,
+ axis: Optional[int] = ...,
+ out: Optional[ndarray] = ...,
+) -> Any: ...
+
@overload
def searchsorted(
a: ArrayLike,
v: _Scalar,
side: _SortSide = ...,
- sorter: Optional[_ArrayLikeIntOrBool] = ..., # 1D int array
-) -> integer: ...
+ sorter: Optional[_ArrayLikeInt_co] = ..., # 1D int array
+) -> intp: ...
@overload
def searchsorted(
a: ArrayLike,
v: ArrayLike,
side: _SortSide = ...,
- sorter: Optional[_ArrayLikeIntOrBool] = ..., # 1D int array
+ sorter: Optional[_ArrayLikeInt_co] = ..., # 1D int array
) -> ndarray: ...
-def resize(a: ArrayLike, new_shape: _ShapeLike) -> ndarray: ...
+
+def resize(
+ a: ArrayLike,
+ new_shape: _ShapeLike,
+) -> ndarray: ...
+
@overload
-def squeeze(a: _ScalarGeneric, axis: Optional[_ShapeLike] = ...) -> _ScalarGeneric: ...
+def squeeze(
+ a: _ScalarGeneric,
+ axis: Optional[_ShapeLike] = ...,
+) -> _ScalarGeneric: ...
@overload
-def squeeze(a: ArrayLike, axis: Optional[_ShapeLike] = ...) -> ndarray: ...
+def squeeze(
+ a: ArrayLike,
+ axis: Optional[_ShapeLike] = ...,
+) -> ndarray: ...
+
def diagonal(
- a: ArrayLike, offset: int = ..., axis1: int = ..., axis2: int = ... # >= 2D array
+ a: ArrayLike,
+ offset: int = ...,
+ axis1: int = ...,
+ axis2: int = ..., # >= 2D array
) -> ndarray: ...
+
def trace(
a: ArrayLike, # >= 2D array
offset: int = ...,
@@ -200,32 +196,21 @@ def trace(
axis2: int = ...,
dtype: DTypeLike = ...,
out: Optional[ndarray] = ...,
-) -> Union[number, ndarray]: ...
+) -> Any: ...
+
def ravel(a: ArrayLike, order: _OrderKACF = ...) -> ndarray: ...
+
def nonzero(a: ArrayLike) -> Tuple[ndarray, ...]: ...
+
def shape(a: ArrayLike) -> _Shape: ...
+
def compress(
condition: ArrayLike, # 1D bool array
a: ArrayLike,
axis: Optional[int] = ...,
out: Optional[ndarray] = ...,
) -> ndarray: ...
-@overload
-def clip(
- a: _Number,
- a_min: ArrayLike,
- a_max: Optional[ArrayLike],
- out: Optional[ndarray] = ...,
- **kwargs: Any,
-) -> _Number: ...
-@overload
-def clip(
- a: _Number,
- a_min: None,
- a_max: ArrayLike,
- out: Optional[ndarray] = ...,
- **kwargs: Any,
-) -> _Number: ...
+
@overload
def clip(
a: ArrayLike,
@@ -233,7 +218,7 @@ def clip(
a_max: Optional[ArrayLike],
out: Optional[ndarray] = ...,
**kwargs: Any,
-) -> Union[number, ndarray]: ...
+) -> Any: ...
@overload
def clip(
a: ArrayLike,
@@ -241,32 +226,23 @@ def clip(
a_max: ArrayLike,
out: Optional[ndarray] = ...,
**kwargs: Any,
-) -> Union[number, ndarray]: ...
-@overload
-def sum(
- a: _Number,
- axis: Optional[_ShapeLike] = ...,
- dtype: DTypeLike = ...,
- out: Optional[ndarray] = ...,
- keepdims: bool = ...,
- initial: _NumberLike = ...,
- where: _ArrayLikeBool = ...,
-) -> _Number: ...
-@overload
+) -> Any: ...
+
def sum(
a: ArrayLike,
axis: _ShapeLike = ...,
dtype: DTypeLike = ...,
out: Optional[ndarray] = ...,
keepdims: bool = ...,
- initial: _NumberLike = ...,
- where: _ArrayLikeBool = ...,
-) -> Union[number, ndarray]: ...
+ initial: _NumberLike_co = ...,
+ where: _ArrayLikeBool_co = ...,
+) -> Any: ...
+
@overload
def all(
a: ArrayLike,
axis: None = ...,
- out: Optional[ndarray] = ...,
+ out: None = ...,
keepdims: Literal[False] = ...,
) -> bool_: ...
@overload
@@ -275,12 +251,13 @@ def all(
axis: Optional[_ShapeLike] = ...,
out: Optional[ndarray] = ...,
keepdims: bool = ...,
-) -> Union[bool_, ndarray]: ...
+) -> Any: ...
+
@overload
def any(
a: ArrayLike,
axis: None = ...,
- out: Optional[ndarray] = ...,
+ out: None = ...,
keepdims: Literal[False] = ...,
) -> bool_: ...
@overload
@@ -289,88 +266,39 @@ def any(
axis: Optional[_ShapeLike] = ...,
out: Optional[ndarray] = ...,
keepdims: bool = ...,
-) -> Union[bool_, ndarray]: ...
+) -> Any: ...
+
def cumsum(
a: ArrayLike,
axis: Optional[int] = ...,
dtype: DTypeLike = ...,
out: Optional[ndarray] = ...,
) -> ndarray: ...
-@overload
-def ptp(
- a: _Number,
- axis: Optional[_ShapeLike] = ...,
- out: Optional[ndarray] = ...,
- keepdims: bool = ...,
-) -> _Number: ...
-@overload
-def ptp(
- a: ArrayLike,
- axis: None = ...,
- out: Optional[ndarray] = ...,
- keepdims: Literal[False] = ...,
-) -> number: ...
-@overload
+
def ptp(
a: ArrayLike,
axis: Optional[_ShapeLike] = ...,
out: Optional[ndarray] = ...,
keepdims: bool = ...,
-) -> Union[number, ndarray]: ...
-@overload
-def amax(
- a: _Number,
- axis: Optional[_ShapeLike] = ...,
- out: Optional[ndarray] = ...,
- keepdims: bool = ...,
- initial: _NumberLike = ...,
- where: _ArrayLikeBool = ...,
-) -> _Number: ...
-@overload
-def amax(
- a: ArrayLike,
- axis: None = ...,
- out: Optional[ndarray] = ...,
- keepdims: Literal[False] = ...,
- initial: _NumberLike = ...,
- where: _ArrayLikeBool = ...,
-) -> number: ...
-@overload
+) -> Any: ...
+
def amax(
a: ArrayLike,
axis: Optional[_ShapeLike] = ...,
out: Optional[ndarray] = ...,
keepdims: bool = ...,
- initial: _NumberLike = ...,
- where: _ArrayLikeBool = ...,
-) -> Union[number, ndarray]: ...
-@overload
-def amin(
- a: _Number,
- axis: Optional[_ShapeLike] = ...,
- out: Optional[ndarray] = ...,
- keepdims: bool = ...,
- initial: _NumberLike = ...,
- where: _ArrayLikeBool = ...,
-) -> _Number: ...
-@overload
-def amin(
- a: ArrayLike,
- axis: None = ...,
- out: Optional[ndarray] = ...,
- keepdims: Literal[False] = ...,
- initial: _NumberLike = ...,
- where: _ArrayLikeBool = ...,
-) -> number: ...
-@overload
+ initial: _NumberLike_co = ...,
+ where: _ArrayLikeBool_co = ...,
+) -> Any: ...
+
def amin(
a: ArrayLike,
axis: Optional[_ShapeLike] = ...,
out: Optional[ndarray] = ...,
keepdims: bool = ...,
- initial: _NumberLike = ...,
- where: _ArrayLikeBool = ...,
-) -> Union[number, ndarray]: ...
+ initial: _NumberLike_co = ...,
+ where: _ArrayLikeBool_co = ...,
+) -> Any: ...
# TODO: `np.prod()``: For object arrays `initial` does not necessarily
# have to be a numerical scalar.
@@ -379,82 +307,41 @@ def amin(
# Note that the same situation holds for all wrappers around
# `np.ufunc.reduce`, e.g. `np.sum()` (`.__add__()`).
-@overload
-def prod(
- a: _Number,
- axis: Optional[_ShapeLike] = ...,
- dtype: DTypeLike = ...,
- out: None = ...,
- keepdims: bool = ...,
- initial: _NumberLike = ...,
- where: _ArrayLikeBool = ...,
-) -> _Number: ...
-@overload
-def prod(
- a: ArrayLike,
- axis: None = ...,
- dtype: DTypeLike = ...,
- out: None = ...,
- keepdims: Literal[False] = ...,
- initial: _NumberLike = ...,
- where: _ArrayLikeBool = ...,
-) -> number: ...
-@overload
def prod(
a: ArrayLike,
axis: Optional[_ShapeLike] = ...,
dtype: DTypeLike = ...,
out: Optional[ndarray] = ...,
keepdims: bool = ...,
- initial: _NumberLike = ...,
- where: _ArrayLikeBool = ...,
-) -> Union[number, ndarray]: ...
+ initial: _NumberLike_co = ...,
+ where: _ArrayLikeBool_co = ...,
+) -> Any: ...
+
def cumprod(
a: ArrayLike,
axis: Optional[int] = ...,
dtype: DTypeLike = ...,
out: Optional[ndarray] = ...,
) -> ndarray: ...
+
def ndim(a: ArrayLike) -> int: ...
+
def size(a: ArrayLike, axis: Optional[int] = ...) -> int: ...
-@overload
-def around(
- a: _Number, decimals: int = ..., out: Optional[ndarray] = ...
-) -> _Number: ...
-@overload
-def around(
- a: _NumberLike, decimals: int = ..., out: Optional[ndarray] = ...
-) -> number: ...
-@overload
+
def around(
- a: ArrayLike, decimals: int = ..., out: Optional[ndarray] = ...
-) -> ndarray: ...
-@overload
-def mean(
a: ArrayLike,
- axis: None = ...,
- dtype: DTypeLike = ...,
- out: None = ...,
- keepdims: Literal[False] = ...,
-) -> number: ...
-@overload
+ decimals: int = ...,
+ out: Optional[ndarray] = ...,
+) -> Any: ...
+
def mean(
a: ArrayLike,
axis: Optional[_ShapeLike] = ...,
dtype: DTypeLike = ...,
out: Optional[ndarray] = ...,
keepdims: bool = ...,
-) -> Union[number, ndarray]: ...
-@overload
-def std(
- a: ArrayLike,
- axis: None = ...,
- dtype: DTypeLike = ...,
- out: None = ...,
- ddof: int = ...,
- keepdims: Literal[False] = ...,
-) -> number: ...
-@overload
+) -> Any: ...
+
def std(
a: ArrayLike,
axis: Optional[_ShapeLike] = ...,
@@ -462,17 +349,8 @@ def std(
out: Optional[ndarray] = ...,
ddof: int = ...,
keepdims: bool = ...,
-) -> Union[number, ndarray]: ...
-@overload
-def var(
- a: ArrayLike,
- axis: None = ...,
- dtype: DTypeLike = ...,
- out: None = ...,
- ddof: int = ...,
- keepdims: Literal[False] = ...,
-) -> number: ...
-@overload
+) -> Any: ...
+
def var(
a: ArrayLike,
axis: Optional[_ShapeLike] = ...,
@@ -480,4 +358,4 @@ def var(
out: Optional[ndarray] = ...,
ddof: int = ...,
keepdims: bool = ...,
-) -> Union[number, ndarray]: ...
+) -> Any: ...