summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
Diffstat (limited to 'numpy')
-rw-r--r--numpy/__init__.pyi75
-rw-r--r--numpy/core/multiarray.py18
-rw-r--r--numpy/core/multiarray.pyi378
-rw-r--r--numpy/core/numeric.pyi17
-rw-r--r--numpy/lib/index_tricks.pyi33
-rw-r--r--numpy/typing/_ufunc.pyi26
-rw-r--r--numpy/typing/tests/data/fail/array_constructors.py4
-rw-r--r--numpy/typing/tests/data/fail/multiarray.py32
-rw-r--r--numpy/typing/tests/data/pass/multiarray.py84
-rw-r--r--numpy/typing/tests/data/reveal/array_constructors.py42
-rw-r--r--numpy/typing/tests/data/reveal/multiarray.py80
11 files changed, 621 insertions, 168 deletions
diff --git a/numpy/__init__.pyi b/numpy/__init__.pyi
index a83e5d9c7..066ac2451 100644
--- a/numpy/__init__.pyi
+++ b/numpy/__init__.pyi
@@ -294,11 +294,33 @@ from numpy.core.einsumfunc import (
einsum_path as einsum_path,
)
+from numpy.core.multiarray import (
+ array as array,
+ empty_like as empty_like,
+ empty as empty,
+ zeros as zeros,
+ concatenate as concatenate,
+ inner as inner,
+ where as where,
+ lexsort as lexsort,
+ can_cast as can_cast,
+ min_scalar_type as min_scalar_type,
+ result_type as result_type,
+ dot as dot,
+ vdot as vdot,
+ bincount as bincount,
+ copyto as copyto,
+ putmask as putmask,
+ packbits as packbits,
+ unpackbits as unpackbits,
+ shares_memory as shares_memory,
+ may_share_memory as may_share_memory,
+)
+
from numpy.core.numeric import (
zeros_like as zeros_like,
ones as ones,
ones_like as ones_like,
- empty_like as empty_like,
full as full,
full_like as full_like,
count_nonzero as count_nonzero,
@@ -868,13 +890,9 @@ def busday_offset(
busdaycal=...,
out=...,
): ...
-def can_cast(from_, to, casting=...): ...
def compare_chararrays(a, b, cmp_op, rstrip): ...
-def concatenate(__a, axis=..., out=..., dtype=..., casting=...): ...
-def copyto(dst, src, casting=..., where=...): ...
def datetime_as_string(arr, unit=..., timezone=..., casting=...): ...
def datetime_data(__dtype): ...
-def dot(a, b, out=...): ...
def frombuffer(buffer, dtype=..., count=..., offset=..., *, like=...): ...
def fromfile(
file, dtype=..., count=..., sep=..., offset=..., *, like=...
@@ -883,24 +901,12 @@ def fromiter(iter, dtype, count=..., *, like=...): ...
def frompyfunc(func, nin, nout, * identity): ...
def fromstring(string, dtype=..., count=..., sep=..., *, like=...): ...
def geterrobj(): ...
-def inner(a, b): ...
def is_busday(
dates, weekmask=..., holidays=..., busdaycal=..., out=...
): ...
-def lexsort(keys, axis=...): ...
-def may_share_memory(a, b, max_work=...): ...
-def min_scalar_type(a): ...
def nested_iters(*args, **kwargs): ... # TODO: Sort out parameters
def promote_types(type1, type2): ...
-def putmask(a, mask, values): ...
-def result_type(*arrays_and_dtypes): ...
def seterrobj(errobj): ...
-def shares_memory(a, b, max_work=...): ...
-def vdot(a, b): ...
-@overload
-def where(__condition): ...
-@overload
-def where(__condition, __x, __y): ...
_NdArraySubClass = TypeVar("_NdArraySubClass", bound=ndarray)
_DTypeScalar_co = TypeVar("_DTypeScalar_co", covariant=True, bound=generic)
@@ -1616,7 +1622,7 @@ _BufferType = Union[ndarray, bytes, bytearray, memoryview]
_T = TypeVar("_T")
_T_co = TypeVar("_T_co", covariant=True)
_2Tuple = Tuple[_T, _T]
-_Casting = L["no", "equiv", "safe", "same_kind", "unsafe"]
+_CastingKind = L["no", "equiv", "safe", "same_kind", "unsafe"]
_DTypeLike = Union[
dtype[_ScalarType],
@@ -1866,7 +1872,7 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeType, _DType_co]):
self,
dtype: _DTypeLike[_ScalarType],
order: _OrderKACF = ...,
- casting: _Casting = ...,
+ casting: _CastingKind = ...,
subok: bool = ...,
copy: bool = ...,
) -> NDArray[_ScalarType]: ...
@@ -1875,7 +1881,7 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeType, _DType_co]):
self,
dtype: DTypeLike,
order: _OrderKACF = ...,
- casting: _Casting = ...,
+ casting: _CastingKind = ...,
subok: bool = ...,
copy: bool = ...,
) -> NDArray[Any]: ...
@@ -2886,7 +2892,7 @@ class generic(_ArrayOrScalarCommon):
self,
dtype: _DTypeLike[_ScalarType],
order: _OrderKACF = ...,
- casting: _Casting = ...,
+ casting: _CastingKind = ...,
subok: bool = ...,
copy: bool = ...,
) -> _ScalarType: ...
@@ -2895,7 +2901,7 @@ class generic(_ArrayOrScalarCommon):
self,
dtype: DTypeLike,
order: _OrderKACF = ...,
- casting: _Casting = ...,
+ casting: _CastingKind = ...,
subok: bool = ...,
copy: bool = ...,
) -> Any: ...
@@ -3430,31 +3436,6 @@ class str_(character, str):
unicode_ = str_
str0 = str_
-def array(
- object: object,
- dtype: DTypeLike = ...,
- *,
- copy: bool = ...,
- order: _OrderKACF = ...,
- subok: bool = ...,
- ndmin: int = ...,
- like: ArrayLike = ...,
-) -> ndarray: ...
-def zeros(
- shape: _ShapeLike,
- dtype: DTypeLike = ...,
- order: _OrderCF = ...,
- *,
- like: ArrayLike = ...,
-) -> ndarray: ...
-def empty(
- shape: _ShapeLike,
- dtype: DTypeLike = ...,
- order: _OrderCF = ...,
- *,
- like: ArrayLike = ...,
-) -> ndarray: ...
-
#
# Constants
#
diff --git a/numpy/core/multiarray.py b/numpy/core/multiarray.py
index b7a3a8d67..78aa7a65c 100644
--- a/numpy/core/multiarray.py
+++ b/numpy/core/multiarray.py
@@ -249,7 +249,7 @@ def concatenate(arrays, axis=None, out=None, *, dtype=None, casting=None):
@array_function_from_c_func_and_dispatcher(_multiarray_umath.inner)
def inner(a, b):
"""
- inner(a, b)
+ inner(a, b, /)
Inner product of two arrays.
@@ -341,7 +341,7 @@ def inner(a, b):
@array_function_from_c_func_and_dispatcher(_multiarray_umath.where)
def where(condition, x=None, y=None):
"""
- where(condition, [x, y])
+ where(condition, [x, y], /)
Return elements chosen from `x` or `y` depending on `condition`.
@@ -613,7 +613,7 @@ def can_cast(from_, to, casting=None):
@array_function_from_c_func_and_dispatcher(_multiarray_umath.min_scalar_type)
def min_scalar_type(a):
"""
- min_scalar_type(a)
+ min_scalar_type(a, /)
For scalar ``a``, returns the data type with the smallest size
and smallest scalar kind which can hold its value. For non-scalar
@@ -825,7 +825,7 @@ def dot(a, b, out=None):
@array_function_from_c_func_and_dispatcher(_multiarray_umath.vdot)
def vdot(a, b):
"""
- vdot(a, b)
+ vdot(a, b, /)
Return the dot product of two vectors.
@@ -883,7 +883,7 @@ def vdot(a, b):
@array_function_from_c_func_and_dispatcher(_multiarray_umath.bincount)
def bincount(x, weights=None, minlength=None):
"""
- bincount(x, weights=None, minlength=0)
+ bincount(x, /, weights=None, minlength=0)
Count number of occurrences of each value in array of non-negative ints.
@@ -1151,7 +1151,7 @@ def putmask(a, mask, values):
@array_function_from_c_func_and_dispatcher(_multiarray_umath.packbits)
def packbits(a, axis=None, bitorder='big'):
"""
- packbits(a, axis=None, bitorder='big')
+ packbits(a, /, axis=None, bitorder='big')
Packs the elements of a binary-valued array into bits in a uint8 array.
@@ -1209,7 +1209,7 @@ def packbits(a, axis=None, bitorder='big'):
@array_function_from_c_func_and_dispatcher(_multiarray_umath.unpackbits)
def unpackbits(a, axis=None, count=None, bitorder='big'):
"""
- unpackbits(a, axis=None, count=None, bitorder='big')
+ unpackbits(a, /, axis=None, count=None, bitorder='big')
Unpacks elements of a uint8 array into a binary-valued output array.
@@ -1293,7 +1293,7 @@ def unpackbits(a, axis=None, count=None, bitorder='big'):
@array_function_from_c_func_and_dispatcher(_multiarray_umath.shares_memory)
def shares_memory(a, b, max_work=None):
"""
- shares_memory(a, b, max_work=None)
+ shares_memory(a, b, /, max_work=None)
Determine if two arrays share memory.
@@ -1368,7 +1368,7 @@ def shares_memory(a, b, max_work=None):
@array_function_from_c_func_and_dispatcher(_multiarray_umath.may_share_memory)
def may_share_memory(a, b, max_work=None):
"""
- may_share_memory(a, b, max_work=None)
+ may_share_memory(a, b, /, max_work=None)
Determine if two arrays might share memory
diff --git a/numpy/core/multiarray.pyi b/numpy/core/multiarray.pyi
new file mode 100644
index 000000000..70048d0e6
--- /dev/null
+++ b/numpy/core/multiarray.pyi
@@ -0,0 +1,378 @@
+# TODO: Sort out any and all missing functions in this namespace
+
+import sys
+from typing import (
+ Any,
+ Optional,
+ overload,
+ TypeVar,
+ List,
+ Type,
+ Union,
+ Sequence,
+ Tuple,
+)
+
+from numpy import (
+ busdaycalendar as busdaycalendar,
+ ndarray,
+ dtype,
+ str_,
+ bool_,
+ uint8,
+ intp,
+ float64,
+ timedelta64,
+ generic,
+ unsignedinteger,
+ signedinteger,
+ floating,
+ complexfloating,
+ _OrderKACF,
+ _OrderCF,
+ _CastingKind,
+ _ModeKind,
+)
+
+from numpy.typing import (
+ # Shapes
+ _ShapeLike,
+
+ # DTypes
+ DTypeLike,
+ _SupportsDType,
+
+ # Arrays
+ NDArray,
+ ArrayLike,
+ _SupportsArray,
+ _NestedSequence,
+ _ArrayLikeBool_co,
+ _ArrayLikeUInt_co,
+ _ArrayLikeInt_co,
+ _ArrayLikeFloat_co,
+ _ArrayLikeComplex_co,
+ _ArrayLikeTD64_co,
+ _ArrayLikeObject_co,
+ _IntLike_co,
+)
+
+if sys.version_info >= (3, 8):
+ from typing import SupportsIndex, Literal as L
+else:
+ from typing_extensions import SupportsIndex, Literal as L
+
+_SCT = TypeVar("_SCT", bound=generic)
+_ArrayType = TypeVar("_ArrayType", bound=NDArray[Any])
+
+_DTypeLike = Union[
+ dtype[_SCT],
+ Type[_SCT],
+ _SupportsDType[dtype[_SCT]],
+]
+_ArrayLike = _NestedSequence[_SupportsArray[dtype[_SCT]]]
+
+__all__: List[str]
+
+@overload
+def empty_like(
+ prototype: _ArrayLike[_SCT],
+ dtype: None = ...,
+ order: _OrderKACF = ...,
+ subok: bool = ...,
+ shape: Optional[_ShapeLike] = ...,
+) -> NDArray[_SCT]: ...
+@overload
+def empty_like(
+ prototype: object,
+ dtype: None = ...,
+ order: _OrderKACF = ...,
+ subok: bool = ...,
+ shape: Optional[_ShapeLike] = ...,
+) -> NDArray[Any]: ...
+@overload
+def empty_like(
+ prototype: Any,
+ dtype: _DTypeLike[_SCT],
+ order: _OrderKACF = ...,
+ subok: bool = ...,
+ shape: Optional[_ShapeLike] = ...,
+) -> NDArray[_SCT]: ...
+@overload
+def empty_like(
+ prototype: Any,
+ dtype: DTypeLike,
+ order: _OrderKACF = ...,
+ subok: bool = ...,
+ shape: Optional[_ShapeLike] = ...,
+) -> NDArray[Any]: ...
+
+@overload
+def array(
+ object: _ArrayLike[_SCT],
+ dtype: None = ...,
+ *,
+ copy: bool = ...,
+ order: _OrderKACF = ...,
+ subok: bool = ...,
+ ndmin: int = ...,
+ like: ArrayLike = ...,
+) -> NDArray[_SCT]: ...
+@overload
+def array(
+ object: object,
+ dtype: None = ...,
+ *,
+ copy: bool = ...,
+ order: _OrderKACF = ...,
+ subok: bool = ...,
+ ndmin: int = ...,
+ like: ArrayLike = ...,
+) -> NDArray[Any]: ...
+@overload
+def array(
+ object: Any,
+ dtype: _DTypeLike[_SCT],
+ *,
+ copy: bool = ...,
+ order: _OrderKACF = ...,
+ subok: bool = ...,
+ ndmin: int = ...,
+ like: ArrayLike = ...,
+) -> NDArray[_SCT]: ...
+@overload
+def array(
+ object: Any,
+ dtype: DTypeLike,
+ *,
+ copy: bool = ...,
+ order: _OrderKACF = ...,
+ subok: bool = ...,
+ ndmin: int = ...,
+ like: ArrayLike = ...,
+) -> NDArray[Any]: ...
+
+@overload
+def zeros(
+ shape: _ShapeLike,
+ dtype: None = ...,
+ order: _OrderCF = ...,
+ *,
+ like: ArrayLike = ...,
+) -> NDArray[float64]: ...
+@overload
+def zeros(
+ shape: _ShapeLike,
+ dtype: _DTypeLike[_SCT],
+ order: _OrderCF = ...,
+ *,
+ like: ArrayLike = ...,
+) -> NDArray[_SCT]: ...
+@overload
+def zeros(
+ shape: _ShapeLike,
+ dtype: DTypeLike,
+ order: _OrderCF = ...,
+ *,
+ like: ArrayLike = ...,
+) -> NDArray[Any]: ...
+
+@overload
+def empty(
+ shape: _ShapeLike,
+ dtype: None = ...,
+ order: _OrderCF = ...,
+ *,
+ like: ArrayLike = ...,
+) -> NDArray[float64]: ...
+@overload
+def empty(
+ shape: _ShapeLike,
+ dtype: _DTypeLike[_SCT],
+ order: _OrderCF = ...,
+ *,
+ like: ArrayLike = ...,
+) -> NDArray[_SCT]: ...
+@overload
+def empty(
+ shape: _ShapeLike,
+ dtype: DTypeLike,
+ order: _OrderCF = ...,
+ *,
+ like: ArrayLike = ...,
+) -> NDArray[Any]: ...
+
+@overload
+def unravel_index( # type: ignore[misc]
+ indices: _IntLike_co,
+ shape: _ShapeLike,
+ order: _OrderCF = ...,
+) -> Tuple[intp, ...]: ...
+@overload
+def unravel_index(
+ indices: _ArrayLikeInt_co,
+ shape: _ShapeLike,
+ order: _OrderCF = ...,
+) -> Tuple[NDArray[intp], ...]: ...
+
+@overload
+def ravel_multi_index( # type: ignore[misc]
+ multi_index: Sequence[_IntLike_co],
+ dims: Sequence[SupportsIndex],
+ mode: Union[_ModeKind, Tuple[_ModeKind, ...]] = ...,
+ order: _OrderCF = ...,
+) -> intp: ...
+@overload
+def ravel_multi_index(
+ multi_index: Sequence[_ArrayLikeInt_co],
+ dims: Sequence[SupportsIndex],
+ mode: Union[_ModeKind, Tuple[_ModeKind, ...]] = ...,
+ order: _OrderCF = ...,
+) -> NDArray[intp]: ...
+
+@overload
+def concatenate( # type: ignore[misc]
+ __arrays: _ArrayLike[_SCT],
+ axis: Optional[SupportsIndex] = ...,
+ out: None = ...,
+ *,
+ dtype: None = ...,
+ casting: Optional[_CastingKind] = ...
+) -> NDArray[_SCT]: ...
+@overload
+def concatenate( # type: ignore[misc]
+ __arrays: ArrayLike,
+ axis: Optional[SupportsIndex] = ...,
+ out: None = ...,
+ *,
+ dtype: None = ...,
+ casting: Optional[_CastingKind] = ...
+) -> NDArray[Any]: ...
+@overload
+def concatenate( # type: ignore[misc]
+ __arrays: ArrayLike,
+ axis: Optional[SupportsIndex] = ...,
+ out: None = ...,
+ *,
+ dtype: _DTypeLike[_SCT],
+ casting: Optional[_CastingKind] = ...
+) -> NDArray[_SCT]: ...
+@overload
+def concatenate( # type: ignore[misc]
+ __arrays: ArrayLike,
+ axis: Optional[SupportsIndex] = ...,
+ out: None = ...,
+ *,
+ dtype: DTypeLike,
+ casting: Optional[_CastingKind] = ...
+) -> NDArray[Any]: ...
+@overload
+def concatenate(
+ __arrays: ArrayLike,
+ axis: Optional[SupportsIndex] = ...,
+ out: _ArrayType = ...,
+ *,
+ dtype: DTypeLike = ...,
+ casting: Optional[_CastingKind] = ...
+) -> _ArrayType: ...
+
+def inner(
+ __a: ArrayLike,
+ __b: ArrayLike,
+) -> Any: ...
+
+@overload
+def where(
+ __condition: ArrayLike,
+) -> Tuple[NDArray[intp], ...]: ...
+@overload
+def where(
+ __condition: ArrayLike,
+ __x: ArrayLike,
+ __y: ArrayLike,
+) -> NDArray[Any]: ...
+
+def lexsort(
+ keys: ArrayLike,
+ axis: Optional[SupportsIndex] = ...,
+) -> Any: ...
+
+def can_cast(
+ from_: Union[ArrayLike, DTypeLike],
+ to: DTypeLike,
+ casting: Optional[_CastingKind] = ...,
+) -> bool: ...
+
+def min_scalar_type(
+ __a: ArrayLike,
+) -> dtype[Any]: ...
+
+def result_type(
+ *arrays_and_dtypes: Union[ArrayLike, DTypeLike],
+) -> dtype[Any]: ...
+
+@overload
+def dot(a: ArrayLike, b: ArrayLike, out: None = ...) -> Any: ...
+@overload
+def dot(a: ArrayLike, b: ArrayLike, out: _ArrayType) -> _ArrayType: ...
+
+@overload
+def vdot(__a: _ArrayLikeBool_co, __b: _ArrayLikeBool_co) -> bool_: ... # type: ignore[misc]
+@overload
+def vdot(__a: _ArrayLikeUInt_co, __b: _ArrayLikeUInt_co) -> unsignedinteger[Any]: ... # type: ignore[misc]
+@overload
+def vdot(__a: _ArrayLikeInt_co, __b: _ArrayLikeInt_co) -> signedinteger[Any]: ... # type: ignore[misc]
+@overload
+def vdot(__a: _ArrayLikeFloat_co, __b: _ArrayLikeFloat_co) -> floating[Any]: ... # type: ignore[misc]
+@overload
+def vdot(__a: _ArrayLikeComplex_co, __b: _ArrayLikeComplex_co) -> complexfloating[Any, Any]: ... # type: ignore[misc]
+@overload
+def vdot(__a: _ArrayLikeTD64_co, __b: _ArrayLikeTD64_co) -> timedelta64: ...
+@overload
+def vdot(__a: _ArrayLikeObject_co, __b: Any) -> Any: ...
+@overload
+def vdot(__a: Any, __b: _ArrayLikeObject_co) -> Any: ...
+
+def bincount(
+ __x: ArrayLike,
+ weights: Optional[ArrayLike] = ...,
+ minlength: SupportsIndex = ...,
+) -> NDArray[intp]: ...
+
+def copyto(
+ dst: NDArray[Any],
+ src: ArrayLike,
+ casting: Optional[_CastingKind] = ...,
+ where: Optional[_ArrayLikeBool_co] = ...,
+) -> None: ...
+
+def putmask(
+ a: NDArray[Any],
+ mask: _ArrayLikeBool_co,
+ values: ArrayLike,
+) -> None: ...
+
+def packbits(
+ __a: _ArrayLikeInt_co,
+ axis: Optional[SupportsIndex] = ...,
+ bitorder: L["big", "little"] = ...,
+) -> NDArray[uint8]: ...
+
+def unpackbits(
+ __a: _ArrayLike[uint8],
+ axis: Optional[SupportsIndex] = ...,
+ count: Optional[SupportsIndex] = ...,
+ bitorder: L["big", "little"] = ...,
+) -> NDArray[uint8]: ...
+
+def shares_memory(
+ __a: object,
+ __b: object,
+ max_work: Optional[int] = ...,
+) -> bool: ...
+
+def may_share_memory(
+ __a: object,
+ __b: object,
+ max_work: Optional[int] = ...,
+) -> bool: ...
diff --git a/numpy/core/numeric.pyi b/numpy/core/numeric.pyi
index f57951434..3c2b553ec 100644
--- a/numpy/core/numeric.pyi
+++ b/numpy/core/numeric.pyi
@@ -67,23 +67,6 @@ def ones_like(
shape: Optional[_ShapeLike] = ...,
) -> ndarray: ...
-@overload
-def empty_like(
- a: _ArrayType,
- dtype: None = ...,
- order: _OrderKACF = ...,
- subok: Literal[True] = ...,
- shape: None = ...,
-) -> _ArrayType: ...
-@overload
-def empty_like(
- a: ArrayLike,
- dtype: DTypeLike = ...,
- order: _OrderKACF = ...,
- subok: bool = ...,
- shape: Optional[_ShapeLike] = ...,
-) -> ndarray: ...
-
def full(
shape: _ShapeLike,
fill_value: Any,
diff --git a/numpy/lib/index_tricks.pyi b/numpy/lib/index_tricks.pyi
index a3bfef6b6..0f9ae94a9 100644
--- a/numpy/lib/index_tricks.pyi
+++ b/numpy/lib/index_tricks.pyi
@@ -44,6 +44,11 @@ from numpy.typing import (
_ShapeLike,
)
+from numpy.core.multiarray import (
+ unravel_index as unravel_index,
+ ravel_multi_index as ravel_multi_index,
+)
+
if sys.version_info >= (3, 8):
from typing import Literal, SupportsIndex
else:
@@ -58,34 +63,6 @@ _ArrayType = TypeVar("_ArrayType", bound=ndarray[Any, Any])
__all__: List[str]
@overload
-def unravel_index( # type: ignore[misc]
- indices: Union[int, integer[Any]],
- shape: _ShapeLike,
- order: _OrderCF = ...
-) -> Tuple[intp, ...]: ...
-@overload
-def unravel_index(
- indices: _ArrayLikeInt,
- shape: _ShapeLike,
- order: _OrderCF = ...
-) -> Tuple[NDArray[intp], ...]: ...
-
-@overload
-def ravel_multi_index( # type: ignore[misc]
- multi_index: Sequence[Union[int, integer[Any]]],
- dims: _ShapeLike,
- mode: Union[_ModeKind, Tuple[_ModeKind, ...]] = ...,
- order: _OrderCF = ...
-) -> intp: ...
-@overload
-def ravel_multi_index(
- multi_index: Sequence[_ArrayLikeInt],
- dims: _ShapeLike,
- mode: Union[_ModeKind, Tuple[_ModeKind, ...]] = ...,
- order: _OrderCF = ...
-) -> NDArray[intp]: ...
-
-@overload
def ix_(*args: _NestedSequence[_SupportsDType[_DType]]) -> Tuple[ndarray[Any, _DType], ...]: ...
@overload
def ix_(*args: _NestedSequence[str]) -> Tuple[NDArray[str_], ...]: ...
diff --git a/numpy/typing/_ufunc.pyi b/numpy/typing/_ufunc.pyi
index f4fead504..be1e654c2 100644
--- a/numpy/typing/_ufunc.pyi
+++ b/numpy/typing/_ufunc.pyi
@@ -16,7 +16,7 @@ from typing import (
TypeVar,
)
-from numpy import ufunc, _Casting, _OrderKACF
+from numpy import ufunc, _CastingKind, _OrderKACF
from numpy.typing import NDArray
from ._shape import _ShapeLike
@@ -81,7 +81,7 @@ class _UFunc_Nin1_Nout1(ufunc, Generic[_NameType, _NTypes, _IDType]):
out: None = ...,
*,
where: None | _ArrayLikeBool_co = ...,
- casting: _Casting = ...,
+ casting: _CastingKind = ...,
order: _OrderKACF = ...,
dtype: DTypeLike = ...,
subok: bool = ...,
@@ -95,7 +95,7 @@ class _UFunc_Nin1_Nout1(ufunc, Generic[_NameType, _NTypes, _IDType]):
out: None | NDArray[Any] | Tuple[NDArray[Any]] = ...,
*,
where: None | _ArrayLikeBool_co = ...,
- casting: _Casting = ...,
+ casting: _CastingKind = ...,
order: _OrderKACF = ...,
dtype: DTypeLike = ...,
subok: bool = ...,
@@ -133,7 +133,7 @@ class _UFunc_Nin2_Nout1(ufunc, Generic[_NameType, _NTypes, _IDType]):
out: None = ...,
*,
where: None | _ArrayLikeBool_co = ...,
- casting: _Casting = ...,
+ casting: _CastingKind = ...,
order: _OrderKACF = ...,
dtype: DTypeLike = ...,
subok: bool = ...,
@@ -148,7 +148,7 @@ class _UFunc_Nin2_Nout1(ufunc, Generic[_NameType, _NTypes, _IDType]):
out: None | NDArray[Any] | Tuple[NDArray[Any]] = ...,
*,
where: None | _ArrayLikeBool_co = ...,
- casting: _Casting = ...,
+ casting: _CastingKind = ...,
order: _OrderKACF = ...,
dtype: DTypeLike = ...,
subok: bool = ...,
@@ -200,7 +200,7 @@ class _UFunc_Nin2_Nout1(ufunc, Generic[_NameType, _NTypes, _IDType]):
*,
out: None = ...,
where: None | _ArrayLikeBool_co = ...,
- casting: _Casting = ...,
+ casting: _CastingKind = ...,
order: _OrderKACF = ...,
dtype: DTypeLike = ...,
subok: bool = ...,
@@ -215,7 +215,7 @@ class _UFunc_Nin2_Nout1(ufunc, Generic[_NameType, _NTypes, _IDType]):
*,
out: None | NDArray[Any] | Tuple[NDArray[Any]] = ...,
where: None | _ArrayLikeBool_co = ...,
- casting: _Casting = ...,
+ casting: _CastingKind = ...,
order: _OrderKACF = ...,
dtype: DTypeLike = ...,
subok: bool = ...,
@@ -257,7 +257,7 @@ class _UFunc_Nin1_Nout2(ufunc, Generic[_NameType, _NTypes, _IDType]):
__out2: None = ...,
*,
where: None | _ArrayLikeBool_co = ...,
- casting: _Casting = ...,
+ casting: _CastingKind = ...,
order: _OrderKACF = ...,
dtype: DTypeLike = ...,
subok: bool = ...,
@@ -273,7 +273,7 @@ class _UFunc_Nin1_Nout2(ufunc, Generic[_NameType, _NTypes, _IDType]):
*,
out: _2Tuple[NDArray[Any]] = ...,
where: None | _ArrayLikeBool_co = ...,
- casting: _Casting = ...,
+ casting: _CastingKind = ...,
order: _OrderKACF = ...,
dtype: DTypeLike = ...,
subok: bool = ...,
@@ -316,7 +316,7 @@ class _UFunc_Nin2_Nout2(ufunc, Generic[_NameType, _NTypes, _IDType]):
__out2: None = ...,
*,
where: None | _ArrayLikeBool_co = ...,
- casting: _Casting = ...,
+ casting: _CastingKind = ...,
order: _OrderKACF = ...,
dtype: DTypeLike = ...,
subok: bool = ...,
@@ -333,7 +333,7 @@ class _UFunc_Nin2_Nout2(ufunc, Generic[_NameType, _NTypes, _IDType]):
*,
out: _2Tuple[NDArray[Any]] = ...,
where: None | _ArrayLikeBool_co = ...,
- casting: _Casting = ...,
+ casting: _CastingKind = ...,
order: _OrderKACF = ...,
dtype: DTypeLike = ...,
subok: bool = ...,
@@ -378,7 +378,7 @@ class _GUFunc_Nin2_Nout1(ufunc, Generic[_NameType, _NTypes, _IDType]):
__x2: ArrayLike,
out: None = ...,
*,
- casting: _Casting = ...,
+ casting: _CastingKind = ...,
order: _OrderKACF = ...,
dtype: DTypeLike = ...,
subok: bool = ...,
@@ -393,7 +393,7 @@ class _GUFunc_Nin2_Nout1(ufunc, Generic[_NameType, _NTypes, _IDType]):
__x2: ArrayLike,
out: NDArray[Any] | Tuple[NDArray[Any]],
*,
- casting: _Casting = ...,
+ casting: _CastingKind = ...,
order: _OrderKACF = ...,
dtype: DTypeLike = ...,
subok: bool = ...,
diff --git a/numpy/typing/tests/data/fail/array_constructors.py b/numpy/typing/tests/data/fail/array_constructors.py
index f13fdacb2..eb57e5c00 100644
--- a/numpy/typing/tests/data/fail/array_constructors.py
+++ b/numpy/typing/tests/data/fail/array_constructors.py
@@ -7,12 +7,12 @@ np.require(a, requirements=1) # E: No overload variant
np.require(a, requirements="TEST") # E: incompatible type
np.zeros("test") # E: incompatible type
-np.zeros() # E: Missing positional argument
+np.zeros() # E: require at least one argument
np.ones("test") # E: incompatible type
np.ones() # E: Missing positional argument
-np.array(0, float, True) # E: Too many positional
+np.array(0, float, True) # E: No overload variant
np.linspace(None, 'bob') # E: No overload variant
np.linspace(0, 2, num=10.0) # E: No overload variant
diff --git a/numpy/typing/tests/data/fail/multiarray.py b/numpy/typing/tests/data/fail/multiarray.py
new file mode 100644
index 000000000..e931e9d5c
--- /dev/null
+++ b/numpy/typing/tests/data/fail/multiarray.py
@@ -0,0 +1,32 @@
+from typing import List
+import numpy as np
+import numpy.typing as npt
+
+i8: np.int64
+
+AR_b: npt.NDArray[np.bool_]
+AR_u1: npt.NDArray[np.uint8]
+AR_i8: npt.NDArray[np.int64]
+AR_f8: npt.NDArray[np.float64]
+AR_M: npt.NDArray[np.datetime64]
+
+AR_LIKE_f: List[float]
+
+np.where(AR_b, 1) # E: No overload variant
+
+np.can_cast(AR_f8, 1) # E: incompatible type
+
+np.vdot(AR_M, AR_M) # E: incompatible type
+
+np.copyto(AR_LIKE_f, AR_f8) # E: incompatible type
+
+np.putmask(AR_LIKE_f, [True, True, False], 1.5) # E: incompatible type
+
+np.packbits(AR_f8) # E: incompatible type
+np.packbits(AR_u1, bitorder=">") # E: incompatible type
+
+np.unpackbits(AR_i8) # E: incompatible type
+np.unpackbits(AR_u1, bitorder=">") # E: incompatible type
+
+np.shares_memory(1, 1, max_work=i8) # E: incompatible type
+np.may_share_memory(1, 1, max_work=i8) # E: incompatible type
diff --git a/numpy/typing/tests/data/pass/multiarray.py b/numpy/typing/tests/data/pass/multiarray.py
index e2b5d16a0..e5d33c673 100644
--- a/numpy/typing/tests/data/pass/multiarray.py
+++ b/numpy/typing/tests/data/pass/multiarray.py
@@ -1,37 +1,77 @@
-from __future__ import annotations
-
from typing import Any
import numpy as np
+import numpy.typing as npt
+
+AR_f8: npt.NDArray[np.float64] = np.array([1.0])
+AR_i4 = np.array([1], dtype=np.int32)
+AR_u1 = np.array([1], dtype=np.uint8)
-AR_f8: np.ndarray[Any, np.dtype[np.float64]] = np.array([1.0])
-AR_i8: np.ndarray[Any, np.dtype[np.int_]] = np.array([1])
+AR_LIKE_f = [1.5]
+AR_LIKE_i = [1]
b_f8 = np.broadcast(AR_f8)
-b_i8_f8_f8 = np.broadcast(AR_i8, AR_f8, AR_f8)
+b_i4_f8_f8 = np.broadcast(AR_i4, AR_f8, AR_f8)
next(b_f8)
-next(b_i8_f8_f8)
-
b_f8.reset()
-b_i8_f8_f8.reset()
-
b_f8.index
-b_i8_f8_f8.index
-
b_f8.iters
-b_i8_f8_f8.iters
-
b_f8.nd
-b_i8_f8_f8.nd
-
b_f8.ndim
-b_i8_f8_f8.ndim
-
b_f8.numiter
-b_i8_f8_f8.numiter
-
b_f8.shape
-b_i8_f8_f8.shape
-
b_f8.size
-b_i8_f8_f8.size
+
+next(b_i4_f8_f8)
+b_i4_f8_f8.reset()
+b_i4_f8_f8.ndim
+b_i4_f8_f8.index
+b_i4_f8_f8.iters
+b_i4_f8_f8.nd
+b_i4_f8_f8.numiter
+b_i4_f8_f8.shape
+b_i4_f8_f8.size
+
+np.inner(AR_f8, AR_i4)
+
+np.where([True, True, False])
+np.where([True, True, False], 1, 0)
+
+np.lexsort([0, 1, 2])
+
+np.can_cast(np.dtype("i8"), int)
+np.can_cast(AR_f8, "f8")
+np.can_cast(AR_f8, np.complex128, casting="unsafe")
+
+np.min_scalar_type([1])
+np.min_scalar_type(AR_f8)
+
+np.result_type(int, AR_i4)
+np.result_type(AR_f8, AR_u1)
+np.result_type(AR_f8, np.complex128)
+
+np.dot(AR_LIKE_f, AR_i4)
+np.dot(AR_u1, 1)
+np.dot(1.5j, 1)
+np.dot(AR_u1, 1, out=AR_f8)
+
+np.vdot(AR_LIKE_f, AR_i4)
+np.vdot(AR_u1, 1)
+np.vdot(1.5j, 1)
+
+np.bincount(AR_i4)
+
+np.copyto(AR_f8, [1.6])
+
+np.putmask(AR_f8, [True], 1.5)
+
+np.packbits(AR_i4)
+np.packbits(AR_u1)
+
+np.unpackbits(AR_u1)
+
+np.shares_memory(1, 2)
+np.shares_memory(AR_f8, AR_f8, max_work=1)
+
+np.may_share_memory(1, 2)
+np.may_share_memory(AR_f8, AR_f8, max_work=1)
diff --git a/numpy/typing/tests/data/reveal/array_constructors.py b/numpy/typing/tests/data/reveal/array_constructors.py
index 2e803a365..775b0e1e0 100644
--- a/numpy/typing/tests/data/reveal/array_constructors.py
+++ b/numpy/typing/tests/data/reveal/array_constructors.py
@@ -1,21 +1,46 @@
from typing import List, Any
import numpy as np
+import numpy.typing as npt
class SubClass(np.ndarray): ...
i8: np.int64
-A: np.ndarray
+A: npt.NDArray[np.float64]
B: SubClass
C: List[int]
def func(i: int, j: int, **kwargs: Any) -> SubClass: ...
+reveal_type(np.empty_like(A)) # E: numpy.ndarray[Any, numpy.dtype[{float64}]]
+reveal_type(np.empty_like([1, 1.0])) # E: numpy.ndarray[Any, numpy.dtype[Any]]
+reveal_type(np.empty_like(A, dtype=np.int64)) # E: numpy.ndarray[Any, numpy.dtype[{int64}]]
+reveal_type(np.empty_like(A, dtype='c16')) # E: numpy.ndarray[Any, numpy.dtype[Any]]
+
+reveal_type(np.array(A)) # E: numpy.ndarray[Any, numpy.dtype[{float64}]]
+reveal_type(np.array([1, 1.0])) # E: numpy.ndarray[Any, numpy.dtype[Any]]
+reveal_type(np.array(A, dtype=np.int64)) # E: numpy.ndarray[Any, numpy.dtype[{int64}]]
+reveal_type(np.array(A, dtype='c16')) # E: numpy.ndarray[Any, numpy.dtype[Any]]
+
+reveal_type(np.zeros([1, 5, 6])) # E: numpy.ndarray[Any, numpy.dtype[{float64}]]
+reveal_type(np.zeros([1, 5, 6], dtype=np.int64)) # E: numpy.ndarray[Any, numpy.dtype[{int64}]]
+reveal_type(np.zeros([1, 5, 6], dtype='c16')) # E: numpy.ndarray[Any, numpy.dtype[Any]]
+
+reveal_type(np.empty([1, 5, 6])) # E: numpy.ndarray[Any, numpy.dtype[{float64}]]
+reveal_type(np.empty([1, 5, 6], dtype=np.int64)) # E: numpy.ndarray[Any, numpy.dtype[{int64}]]
+reveal_type(np.empty([1, 5, 6], dtype='c16')) # E: numpy.ndarray[Any, numpy.dtype[Any]]
+
+reveal_type(np.concatenate(A)) # E: numpy.ndarray[Any, numpy.dtype[{float64}]]
+reveal_type(np.concatenate([1, 1.0])) # E: numpy.ndarray[Any, numpy.dtype[Any]]
+reveal_type(np.concatenate(A, dtype=np.int64)) # E: numpy.ndarray[Any, numpy.dtype[{int64}]]
+reveal_type(np.concatenate(A, dtype='c16')) # E: numpy.ndarray[Any, numpy.dtype[Any]]
+reveal_type(np.concatenate([1, 1.0], out=A)) # E: numpy.ndarray[Any, numpy.dtype[{float64}]]
+
reveal_type(np.asarray(A)) # E: numpy.ndarray[Any, Any]
reveal_type(np.asarray(B)) # E: numpy.ndarray[Any, Any]
reveal_type(np.asarray(C)) # E: numpy.ndarray[Any, Any]
-reveal_type(np.asanyarray(A)) # E: numpy.ndarray[Any, Any]
+reveal_type(np.asanyarray(A)) # E: numpy.ndarray[Any, numpy.dtype[{float64}]]
reveal_type(np.asanyarray(B)) # E: SubClass
reveal_type(np.asanyarray(B, dtype=int)) # E: numpy.ndarray[Any, Any]
reveal_type(np.asanyarray(C)) # E: numpy.ndarray[Any, Any]
@@ -28,7 +53,7 @@ reveal_type(np.asfortranarray(A)) # E: numpy.ndarray[Any, Any]
reveal_type(np.asfortranarray(B)) # E: numpy.ndarray[Any, Any]
reveal_type(np.asfortranarray(C)) # E: numpy.ndarray[Any, Any]
-reveal_type(np.require(A)) # E: numpy.ndarray[Any, Any]
+reveal_type(np.require(A)) # E: numpy.ndarray[Any, numpy.dtype[{float64}]]
reveal_type(np.require(B)) # E: SubClass
reveal_type(np.require(B, requirements=None)) # E: SubClass
reveal_type(np.require(B, dtype=int)) # E: numpy.ndarray[Any, Any]
@@ -45,22 +70,17 @@ reveal_type(np.linspace(0, 10, retstep=True)) # E: Tuple[numpy.ndarray[Any, Any
reveal_type(np.logspace(0, 10)) # E: numpy.ndarray[Any, Any]
reveal_type(np.geomspace(1, 10)) # E: numpy.ndarray[Any, Any]
-reveal_type(np.zeros_like(A)) # E: numpy.ndarray[Any, Any]
+reveal_type(np.zeros_like(A)) # E: numpy.ndarray[Any, numpy.dtype[{float64}]]
reveal_type(np.zeros_like(C)) # E: numpy.ndarray[Any, Any]
reveal_type(np.zeros_like(B)) # E: SubClass
reveal_type(np.zeros_like(B, dtype=np.int64)) # E: numpy.ndarray[Any, Any]
-reveal_type(np.ones_like(A)) # E: numpy.ndarray[Any, Any]
+reveal_type(np.ones_like(A)) # E: numpy.ndarray[Any, numpy.dtype[{float64}]]
reveal_type(np.ones_like(C)) # E: numpy.ndarray[Any, Any]
reveal_type(np.ones_like(B)) # E: SubClass
reveal_type(np.ones_like(B, dtype=np.int64)) # E: numpy.ndarray[Any, Any]
-reveal_type(np.empty_like(A)) # E: numpy.ndarray[Any, Any]
-reveal_type(np.empty_like(C)) # E: numpy.ndarray[Any, Any]
-reveal_type(np.empty_like(B)) # E: SubClass
-reveal_type(np.empty_like(B, dtype=np.int64)) # E: numpy.ndarray[Any, Any]
-
-reveal_type(np.full_like(A, i8)) # E: numpy.ndarray[Any, Any]
+reveal_type(np.full_like(A, i8)) # E: numpy.ndarray[Any, numpy.dtype[{float64}]]
reveal_type(np.full_like(C, i8)) # E: numpy.ndarray[Any, Any]
reveal_type(np.full_like(B, i8)) # E: SubClass
reveal_type(np.full_like(B, i8, dtype=np.int64)) # E: numpy.ndarray[Any, Any]
diff --git a/numpy/typing/tests/data/reveal/multiarray.py b/numpy/typing/tests/data/reveal/multiarray.py
index 33e9ede7c..2811b1f35 100644
--- a/numpy/typing/tests/data/reveal/multiarray.py
+++ b/numpy/typing/tests/data/reveal/multiarray.py
@@ -1,35 +1,77 @@
-from typing import Any
+from typing import Any, List
import numpy as np
+import numpy.typing as npt
-AR_f8: np.ndarray[Any, np.dtype[np.float64]]
-AR_i8: np.ndarray[Any, np.dtype[np.int64]]
+AR_f8: npt.NDArray[np.float64]
+AR_i8: npt.NDArray[np.int64]
+AR_u1: npt.NDArray[np.uint8]
+
+AR_LIKE_f: List[float]
+AR_LIKE_i: List[int]
b_f8 = np.broadcast(AR_f8)
b_i8_f8_f8 = np.broadcast(AR_i8, AR_f8, AR_f8)
reveal_type(next(b_f8)) # E: tuple[Any]
-reveal_type(next(b_i8_f8_f8)) # E: tuple[Any]
-
reveal_type(b_f8.reset()) # E: None
-reveal_type(b_i8_f8_f8.reset()) # E: None
-
reveal_type(b_f8.index) # E: int
-reveal_type(b_i8_f8_f8.index) # E: int
-
reveal_type(b_f8.iters) # E: tuple[numpy.flatiter[Any]]
-reveal_type(b_i8_f8_f8.iters) # E: tuple[numpy.flatiter[Any]]
-
reveal_type(b_f8.nd) # E: int
-reveal_type(b_i8_f8_f8.nd) # E: int
-
reveal_type(b_f8.ndim) # E: int
-reveal_type(b_i8_f8_f8.ndim) # E: int
-
reveal_type(b_f8.numiter) # E: int
-reveal_type(b_i8_f8_f8.numiter) # E: int
-
reveal_type(b_f8.shape) # E: tuple[builtins.int]
-reveal_type(b_i8_f8_f8.shape) # E: tuple[builtins.int]
-
reveal_type(b_f8.size) # E: int
+
+reveal_type(next(b_i8_f8_f8)) # E: tuple[Any]
+reveal_type(b_i8_f8_f8.reset()) # E: None
+reveal_type(b_i8_f8_f8.index) # E: int
+reveal_type(b_i8_f8_f8.iters) # E: tuple[numpy.flatiter[Any]]
+reveal_type(b_i8_f8_f8.nd) # E: int
+reveal_type(b_i8_f8_f8.ndim) # E: int
+reveal_type(b_i8_f8_f8.numiter) # E: int
+reveal_type(b_i8_f8_f8.shape) # E: tuple[builtins.int]
reveal_type(b_i8_f8_f8.size) # E: int
+
+reveal_type(np.inner(AR_f8, AR_i8)) # E: Any
+
+reveal_type(np.where([True, True, False])) # E: tuple[numpy.ndarray[Any, numpy.dtype[{intp}]]]
+reveal_type(np.where([True, True, False], 1, 0)) # E: numpy.ndarray[Any, numpy.dtype[Any]]
+
+reveal_type(np.lexsort([0, 1, 2])) # E: Any
+
+reveal_type(np.can_cast(np.dtype("i8"), int)) # E: bool
+reveal_type(np.can_cast(AR_f8, "f8")) # E: bool
+reveal_type(np.can_cast(AR_f8, np.complex128, casting="unsafe")) # E: bool
+
+reveal_type(np.min_scalar_type([1])) # E: numpy.dtype[Any]
+reveal_type(np.min_scalar_type(AR_f8)) # E: numpy.dtype[Any]
+
+reveal_type(np.result_type(int, [1])) # E: numpy.dtype[Any]
+reveal_type(np.result_type(AR_f8, AR_u1)) # E: numpy.dtype[Any]
+reveal_type(np.result_type(AR_f8, np.complex128)) # E: numpy.dtype[Any]
+
+reveal_type(np.dot(AR_LIKE_f, AR_i8)) # E: Any
+reveal_type(np.dot(AR_u1, 1)) # E: Any
+reveal_type(np.dot(1.5j, 1)) # E: Any
+reveal_type(np.dot(AR_u1, 1, out=AR_f8)) # E: numpy.ndarray[Any, numpy.dtype[{float64}]]
+
+reveal_type(np.vdot(AR_LIKE_f, AR_i8)) # E: numpy.floating[Any]
+reveal_type(np.vdot(AR_u1, 1)) # E: numpy.signedinteger[Any]
+reveal_type(np.vdot(1.5j, 1)) # E: numpy.complexfloating[Any, Any]
+
+reveal_type(np.bincount(AR_i8)) # E: numpy.ndarray[Any, numpy.dtype[{intp}]]
+
+reveal_type(np.copyto(AR_f8, [1., 1.5, 1.6])) # E: None
+
+reveal_type(np.putmask(AR_f8, [True, True, False], 1.5)) # E: None
+
+reveal_type(np.packbits(AR_i8)) # numpy.ndarray[Any, numpy.dtype[{uint8}]]
+reveal_type(np.packbits(AR_u1)) # numpy.ndarray[Any, numpy.dtype[{uint8}]]
+
+reveal_type(np.unpackbits(AR_u1)) # numpy.ndarray[Any, numpy.dtype[{uint8}]]
+
+reveal_type(np.shares_memory(1, 2)) # E: bool
+reveal_type(np.shares_memory(AR_f8, AR_f8, max_work=1)) # E: bool
+
+reveal_type(np.may_share_memory(1, 2)) # E: bool
+reveal_type(np.may_share_memory(AR_f8, AR_f8, max_work=1)) # E: bool