diff --git a/pyproject.toml b/pyproject.toml index be80634f..912cf05b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -148,6 +148,7 @@ preview = true "DOC", # flake8-docstrings "PYI054", # flake8-pyi: numeric-literal-too-long "PYI064", # flake8-pyi: redundant-final-literal + "SLF001", # flake8-self: private-member-access "PLC2701", # pylint/C: import-private-name "PLR0904", # pylint/R: too-many-public-methods "PLR0913", # pylint/R: too-many-arguments diff --git a/src/numpy-stubs/__init__.pyi b/src/numpy-stubs/__init__.pyi index 9d57e65a..be0256a9 100644 --- a/src/numpy-stubs/__init__.pyi +++ b/src/numpy-stubs/__init__.pyi @@ -1,183 +1,163 @@ -# ruff: noqa: I001 +import abc import builtins -import sys import ctypes as ct import datetime as dt import enum -from abc import abstractmethod -from types import EllipsisType, ModuleType, TracebackType, MappingProxyType, GenericAlias +import sys +from collections.abc import Callable, Iterable, Iterator, Mapping, Sequence from decimal import Decimal from fractions import Fraction +from types import EllipsisType, GenericAlias, MappingProxyType, ModuleType, TracebackType from uuid import UUID import numpy as np from numpy.__config__ import show as show_config -from numpy._pytesttester import PytestTester +from numpy._array_api_info import __array_namespace_info__ from numpy._core._internal import _ctypes - +from numpy._pytesttester import PytestTester from numpy._typing import ( - # Arrays ArrayLike, + DTypeLike, + NBitBase, NDArray, - _SupportsArray, - _NestedSequence, - _FiniteNestedSequence, + _8Bit, + _16Bit, + _32Bit, + _64Bit, _ArrayLike, _ArrayLikeBool_co, - _ArrayLikeUInt_co, - _ArrayLikeInt, - _ArrayLikeInt_co, - _ArrayLikeFloat64_co, - _ArrayLikeFloat_co, _ArrayLikeComplex128_co, _ArrayLikeComplex_co, - _ArrayLikeNumber_co, - _ArrayLikeTD64_co, _ArrayLikeDT64_co, + _ArrayLikeFloat64_co, + _ArrayLikeFloat_co, + _ArrayLikeInt, + _ArrayLikeInt_co, + _ArrayLikeNumber_co, _ArrayLikeObject_co, - # DTypes - DTypeLike, + _ArrayLikeTD64_co, + _ArrayLikeUInt_co, + _BoolCodes, + _ByteCodes, + _BytesCodes, + _CDoubleCodes, + _CLongDoubleCodes, + _CSingleCodes, + _CharLike_co, + _CharacterCodes, + _Complex64Codes, + _Complex128Codes, + _ComplexFloatingCodes, + _DT64Codes, _DTypeLike, _DTypeLikeVoid, - _VoidDTypeLike, - # Shapes - _Shape, - _ShapeLike, - # Scalars - _CharLike_co, - _IntLike_co, + _DoubleCodes, + _FiniteNestedSequence, + _FlexibleCodes, + _Float16Codes, + _Float32Codes, + _Float64Codes, _FloatLike_co, - _TD64Like_co, - _NumberLike_co, - _ScalarLike_co, - # `number` precision - NBitBase, - # NOTE: Do not remove the extended precision bit-types even if seemingly unused; - # they're used by the mypy plugin - _64Bit, - _32Bit, - _16Bit, - _8Bit, + _FloatingCodes, + _GUFunc_Nin2_Nout1, + _GenericCodes, + _HalfCodes, + _InexactCodes, + _Int8Codes, + _Int16Codes, + _Int32Codes, + _Int64Codes, + _IntCCodes, + _IntLike_co, + _IntPCodes, + _IntegerCodes, + _LongCodes, + _LongDoubleCodes, + _LongLongCodes, _NBitByte, - _NBitShort, + _NBitDouble, + _NBitHalf, _NBitIntC, _NBitIntP, _NBitLong, + _NBitLongDouble, _NBitLongLong, - _NBitHalf, + _NBitShort, _NBitSingle, - _NBitDouble, - _NBitLongDouble, - # Character codes - _BoolCodes, + _NestedSequence, + _NumberCodes, + _NumberLike_co, + _ObjectCodes, + _ScalarLike_co, + _Shape, + _ShapeLike, + _ShortCodes, + _SignedIntegerCodes, + _SingleCodes, + _StrCodes, + _StringCodes, + _SupportsArray, + _TD64Codes, + _TD64Like_co, + _UByteCodes, + _UFunc_Nin1_Nout1, + _UFunc_Nin1_Nout2, + _UFunc_Nin2_Nout1, + _UFunc_Nin2_Nout2, _UInt8Codes, _UInt16Codes, _UInt32Codes, _UInt64Codes, - _Int8Codes, - _Int16Codes, - _Int32Codes, - _Int64Codes, - _Float16Codes, - _Float32Codes, - _Float64Codes, - _Complex64Codes, - _Complex128Codes, - _ByteCodes, - _ShortCodes, - _IntCCodes, - _IntPCodes, - _LongCodes, - _LongLongCodes, - _UByteCodes, - _UShortCodes, _UIntCCodes, _UIntPCodes, _ULongCodes, _ULongLongCodes, - _HalfCodes, - _SingleCodes, - _DoubleCodes, - _LongDoubleCodes, - _CSingleCodes, - _CDoubleCodes, - _CLongDoubleCodes, - _DT64Codes, - _TD64Codes, - _StrCodes, - _BytesCodes, - _VoidCodes, - _ObjectCodes, - _StringCodes, + _UShortCodes, _UnsignedIntegerCodes, - _SignedIntegerCodes, - _IntegerCodes, - _FloatingCodes, - _ComplexFloatingCodes, - _InexactCodes, - _NumberCodes, - _CharacterCodes, - _FlexibleCodes, - _GenericCodes, - # Ufuncs - _UFunc_Nin1_Nout1, - _UFunc_Nin2_Nout1, - _UFunc_Nin1_Nout2, - _UFunc_Nin2_Nout2, - _GUFunc_Nin2_Nout1, + _VoidCodes, + _VoidDTypeLike, ) - from numpy._typing._callable import ( - _BoolOp, _BoolBitOp, + _BoolDivMod, + _BoolMod, + _BoolOp, _BoolSub, _BoolTrueDiv, - _BoolMod, - _BoolDivMod, + _ComparisonOpGE, + _ComparisonOpGT, + _ComparisonOpLE, + _ComparisonOpLT, + _FloatDivMod, + _FloatMod, + _FloatOp, _IntTrueDiv, - _UnsignedIntOp, - _UnsignedIntBitOp, - _UnsignedIntMod, - _UnsignedIntDivMod, - _SignedIntOp, + _NumberOp, _SignedIntBitOp, - _SignedIntMod, _SignedIntDivMod, - _FloatOp, - _FloatMod, - _FloatDivMod, - _NumberOp, - _ComparisonOpLT, - _ComparisonOpLE, - _ComparisonOpGT, - _ComparisonOpGE, + _SignedIntMod, + _SignedIntOp, + _UnsignedIntBitOp, + _UnsignedIntDivMod, + _UnsignedIntMod, + _UnsignedIntOp, ) # NOTE: Numpy's mypy plugin is used for removing the types unavailable # to the specific platform from numpy._typing._extended_precision import ( - uint128, - uint256, - int128, - int256, - float80, - float96, - float128, - float256, complex160, complex192, complex256, complex512, -) - -from numpy._array_api_info import __array_namespace_info__ - -from collections.abc import ( - Callable, - Iterable, - Iterator, - Mapping, - Sequence, + float80, + float96, + float128, + float256, + int128, + int256, + uint128, + uint256, ) if sys.version_info >= (3, 12): @@ -185,6 +165,7 @@ if sys.version_info >= (3, 12): else: _SupportsBuffer: TypeAlias = ... +from _typeshed import StrOrBytesPath, SupportsFlush, SupportsLenAndGetItem, SupportsWrite from typing import ( Any, ClassVar, @@ -194,23 +175,18 @@ from typing import ( NoReturn, SupportsComplex, SupportsFloat, - SupportsInt, SupportsIndex, + SupportsInt, TypeAlias, TypedDict, final, + overload, type_check_only, ) +from typing_extensions import CapsuleType, LiteralString, Never, Protocol, Self, TypeVar, deprecated -# NOTE: `typing_extensions` and `_typeshed` are always available in `.pyi` stubs, even -# if not available at runtime. This is because the `typeshed` stubs for the standard -# library include `typing_extensions` stubs: -# https://github.com/python/typeshed/blob/main/stdlib/typing_extensions.pyi -from _typeshed import StrOrBytesPath, SupportsFlush, SupportsLenAndGetItem, SupportsWrite -from typing_extensions import CapsuleType, Protocol, TypeVar, deprecated -from typing import LiteralString, Never, Self, overload - -from numpy import ( +from . import ( + __config__ as __config__, char, core, ctypeslib, @@ -221,216 +197,156 @@ from numpy import ( lib, linalg, ma, + matlib as matlib, + matrixlib as matrixlib, polynomial, random, rec, strings, testing, typing as npt, -) - -# available through `__getattr__`, but not in `__all__` or `__dir__` -from numpy import ( - __config__ as __config__, - matlib as matlib, - matrixlib as matrixlib, version as version, ) if sys.version_info < (3, 12): - from numpy import distutils as distutils + from . import distutils as distutils -from numpy._core.records import ( - record, - recarray, -) - -from numpy._core.function_base import ( - linspace, - logspace, - geomspace, +from numpy._core._asarray import require +from numpy._core._type_aliases import sctypeDict +from numpy._core._ufunc_config import _ErrCall, _ErrKind, getbufsize, geterr, geterrcall, setbufsize, seterr, seterrcall +from numpy._core.arrayprint import ( + array2string, + array_repr, + array_str, + format_float_positional, + format_float_scientific, + get_printoptions, + printoptions, + set_printoptions, ) - +from numpy._core.einsumfunc import einsum, einsum_path from numpy._core.fromnumeric import ( - take, - reshape, - choose, - repeat, - put, - swapaxes, - transpose, - matrix_transpose, - partition, - argpartition, - sort, - argsort, + all, + amax, + amin, + any, argmax, argmin, - searchsorted, - resize, - squeeze, - diagonal, - trace, - ravel, - nonzero, - shape, - compress, + argpartition, + argsort, + around, + choose, clip, - sum, - all, - any, + compress, + cumprod, cumsum, + cumulative_prod, cumulative_sum, - ptp, + diagonal, + matrix_transpose, max, + mean, min, - amax, - amin, - prod, - cumprod, - cumulative_prod, ndim, - size, - around, + nonzero, + partition, + prod, + ptp, + put, + ravel, + repeat, + reshape, + resize, round, - mean, + searchsorted, + shape, + size, + sort, + squeeze, std, + sum, + swapaxes, + take, + trace, + transpose, var, ) - -from numpy._core._asarray import ( - require, -) - -from numpy._core._type_aliases import ( - sctypeDict, -) - -from numpy._core._ufunc_config import ( - seterr, - geterr, - setbufsize, - getbufsize, - seterrcall, - geterrcall, - _ErrKind, - _ErrCall, -) - -from numpy._core.arrayprint import ( - set_printoptions, - get_printoptions, - array2string, - format_float_scientific, - format_float_positional, - array_repr, - array_str, - printoptions, -) - -from numpy._core.einsumfunc import ( - einsum, - einsum_path, -) - +from numpy._core.function_base import geomspace, linspace, logspace from numpy._core.multiarray import ( + arange, array, - empty_like, - empty, - zeros, - concatenate, - inner, - where, - lexsort, - can_cast, - min_scalar_type, - result_type, - dot, - vdot, - bincount, - copyto, - putmask, - packbits, - unpackbits, - shares_memory, - may_share_memory, - asarray, asanyarray, + asarray, ascontiguousarray, asfortranarray, - arange, + bincount, busday_count, busday_offset, + can_cast, + concatenate, + copyto, datetime_as_string, datetime_data, + dot, + empty, + empty_like, + flagsobj, frombuffer, fromfile, fromiter, - is_busday, - promote_types, - fromstring, frompyfunc, + fromstring, + inner, + is_busday, + lexsort, + may_share_memory, + min_scalar_type, nested_iters, - flagsobj, + packbits, + promote_types, + putmask, + result_type, + shares_memory, + unpackbits, + vdot, + where, + zeros, ) - from numpy._core.numeric import ( - zeros_like, - ones, - ones_like, - full, - full_like, - count_nonzero, - isfortran, + allclose, argwhere, - flatnonzero, - correlate, + array_equal, + array_equiv, + astype, + base_repr, + binary_repr, convolve, - outer, - tensordot, - roll, - rollaxis, - moveaxis, + correlate, + count_nonzero, cross, - indices, + flatnonzero, fromfunction, - isscalar, - binary_repr, - base_repr, + full, + full_like, identity, - allclose, + indices, isclose, - array_equal, - array_equiv, - astype, -) - -from numpy._core.numerictypes import ( - isdtype, - issubdtype, - ScalarType, - typecodes, -) - -from numpy._core.shape_base import ( - atleast_1d, - atleast_2d, - atleast_3d, - block, - hstack, - stack, - vstack, - unstack, -) - -from numpy.lib import ( - scimath as emath, -) - -from numpy.lib._arraypad_impl import ( - pad, + isfortran, + isscalar, + moveaxis, + ones, + ones_like, + outer, + roll, + rollaxis, + tensordot, + zeros_like, ) - +from numpy._core.numerictypes import ScalarType, isdtype, issubdtype, typecodes +from numpy._core.records import recarray, record +from numpy._core.shape_base import atleast_1d, atleast_2d, atleast_3d, block, hstack, stack, unstack, vstack +from numpy.lib import scimath as emath +from numpy.lib._arraypad_impl import pad from numpy.lib._arraysetops_impl import ( ediff1d, in1d, @@ -445,182 +361,127 @@ from numpy.lib._arraysetops_impl import ( unique_inverse, unique_values, ) - from numpy.lib._function_base_impl import ( - select, - piecewise, - trim_zeros, - copy, - iterable, - percentile, - diff, - gradient, angle, - unwrap, - sort_complex, - flip, - rot90, - extract, - place, + append, asarray_chkfinite, average, - bincount, - digitize, - cov, + bartlett, + blackman, + copy, corrcoef, - median, - sinc, + cov, + delete, + diff, + digitize, + extract, + flip, + gradient, hamming, hanning, - bartlett, - blackman, - kaiser, - trapezoid, - trapz, i0, - meshgrid, - delete, insert, - append, interp, + iterable, + kaiser, + median, + meshgrid, + percentile, + piecewise, + place, quantile, + rot90, + select, + sinc, + sort_complex, + trapezoid, + trapz, + trim_zeros, + unwrap, ) - -from numpy.lib._histograms_impl import ( - histogram_bin_edges, - histogram, - histogramdd, -) - +from numpy.lib._histograms_impl import histogram, histogram_bin_edges, histogramdd from numpy.lib._index_tricks_impl import ( - ravel_multi_index, - unravel_index, + c_, + diag_indices, + diag_indices_from, + fill_diagonal, + index_exp, + ix_, mgrid, ogrid, r_, - c_, + ravel_multi_index, s_, - index_exp, - ix_, - fill_diagonal, - diag_indices, - diag_indices_from, + unravel_index, ) - from numpy.lib._nanfunctions_impl import ( - nansum, - nanmax, - nanmin, nanargmax, nanargmin, + nancumprod, + nancumsum, + nanmax, nanmean, nanmedian, + nanmin, nanpercentile, - nanvar, - nanstd, nanprod, - nancumsum, - nancumprod, nanquantile, + nanstd, + nansum, + nanvar, ) - -from numpy.lib._npyio_impl import ( - savetxt, - loadtxt, - genfromtxt, - load, - save, - savez, - savez_compressed, - packbits, - unpackbits, - fromregex, -) - -from numpy.lib._polynomial_impl import ( - poly, - roots, - polyint, - polyder, - polyadd, - polysub, - polymul, - polydiv, - polyval, - polyfit, -) - +from numpy.lib._npyio_impl import fromregex, genfromtxt, load, loadtxt, save, savetxt, savez, savez_compressed +from numpy.lib._polynomial_impl import poly, polyadd, polyder, polydiv, polyfit, polyint, polymul, polysub, polyval, roots from numpy.lib._shape_base_impl import ( - column_stack, - dstack, + apply_along_axis, + apply_over_axes, array_split, - split, - hsplit, - vsplit, + column_stack, dsplit, - apply_over_axes, + dstack, expand_dims, - apply_along_axis, + hsplit, kron, - tile, - take_along_axis, put_along_axis, + split, + take_along_axis, + tile, + vsplit, ) - -from numpy.lib._stride_tricks_impl import ( - broadcast_to, - broadcast_arrays, - broadcast_shapes, -) - +from numpy.lib._stride_tricks_impl import broadcast_arrays, broadcast_shapes, broadcast_to from numpy.lib._twodim_base_impl import ( diag, diagflat, eye, fliplr, flipud, - tri, - triu, - tril, - vander, histogram2d, mask_indices, + tri, + tril, tril_indices, tril_indices_from, + triu, triu_indices, triu_indices_from, + vander, ) - from numpy.lib._type_check_impl import ( - mintypecode, - real, + common_type, imag, iscomplex, - isreal, iscomplexobj, + isreal, isrealobj, + mintypecode, nan_to_num, + real, real_if_close, typename, - common_type, -) - -from numpy.lib._ufunclike_impl import ( - fix, - isposinf, - isneginf, -) - -from numpy.lib._utils_impl import ( - get_include, - info, - show_runtime, -) - -from numpy.matrixlib import ( - asmatrix, - bmat, ) +from numpy.lib._ufunclike_impl import fix, isneginf, isposinf +from numpy.lib._utils_impl import get_include, info, show_runtime +from numpy.matrixlib import asmatrix, bmat __all__ = [ # noqa: RUF022 # __numpy_submodules__ @@ -672,7 +533,7 @@ __all__ = [ # noqa: RUF022 "bytes_", "str_", "void", "object_", "datetime64", "timedelta64", "int8", "byte", "uint8", "ubyte", "int16", "short", "uint16", "ushort", "int32", "intc", "uint32", "uintc", "int64", "long", "uint64", "ulong", "longlong", "ulonglong", "intp", - "uintp", "double", "cdouble", "single", "csingle", "half", "bool_", "int_", "uint", + "uintp", "double", "cdouble", "single", "csingle", "half", "bool_", "int_", "uint64", "uint128", "uint256", "int128", "int256", "float80", "float96", "float128", "float256", "complex160", "complex192", "complex256", "complex512", "array2string", "array_str", "array_repr", "set_printoptions", "get_printoptions", @@ -745,8 +606,8 @@ __all__ = [ # noqa: RUF022 # Only use these for functions; never as generic type parameter. _AnyStr = TypeVar("_AnyStr", LiteralString, str, bytes) -_AnyShapeType = TypeVar( - "_AnyShapeType", +_AnyShapeT = TypeVar( + "_AnyShapeT", tuple[()], # 0-d tuple[int], # 1-d tuple[int, int], # 2-d @@ -1179,7 +1040,7 @@ test: Final[PytestTester] = ... @final class dtype(Generic[_SCT_co]): - names: tuple[builtins.str, ...] | None + names: tuple[str, ...] | None def __hash__(self) -> int: ... # `None` results in the default dtype @@ -1189,7 +1050,7 @@ class dtype(Generic[_SCT_co]): dtype: type[float64] | None, align: builtins.bool = ..., copy: builtins.bool = ..., - metadata: dict[builtins.str, Any] = ..., + metadata: dict[str, Any] = ..., ) -> dtype[float64]: ... # Overload for `dtype` instances, scalar types, and instances that have a @@ -1200,7 +1061,7 @@ class dtype(Generic[_SCT_co]): dtype: _DTypeLike[_SCT], align: builtins.bool = ..., copy: builtins.bool = ..., - metadata: dict[builtins.str, Any] = ..., + metadata: dict[str, Any] = ..., ) -> dtype[_SCT]: ... # Builtin types @@ -1324,7 +1185,7 @@ class dtype(Generic[_SCT_co]): dtype: _UInt8Codes | type[ct.c_uint8], align: builtins.bool = ..., copy: builtins.bool = ..., - metadata: dict[builtins.str, Any] = ..., + metadata: dict[str, Any] = ..., ) -> dtype[uint8]: ... @overload def __new__( @@ -1332,7 +1193,7 @@ class dtype(Generic[_SCT_co]): dtype: _UInt16Codes | type[ct.c_uint16], align: builtins.bool = ..., copy: builtins.bool = ..., - metadata: dict[builtins.str, Any] = ..., + metadata: dict[str, Any] = ..., ) -> dtype[uint16]: ... @overload def __new__( @@ -1340,7 +1201,7 @@ class dtype(Generic[_SCT_co]): dtype: _UInt32Codes | type[ct.c_uint32], align: builtins.bool = ..., copy: builtins.bool = ..., - metadata: dict[builtins.str, Any] = ..., + metadata: dict[str, Any] = ..., ) -> dtype[uint32]: ... @overload def __new__( @@ -1348,7 +1209,7 @@ class dtype(Generic[_SCT_co]): dtype: _UInt64Codes | type[ct.c_uint64], align: builtins.bool = ..., copy: builtins.bool = ..., - metadata: dict[builtins.str, Any] = ..., + metadata: dict[str, Any] = ..., ) -> dtype[uint64]: ... @overload def __new__( @@ -1356,7 +1217,7 @@ class dtype(Generic[_SCT_co]): dtype: _UByteCodes | type[ct.c_ubyte], align: builtins.bool = ..., copy: builtins.bool = ..., - metadata: dict[builtins.str, Any] = ..., + metadata: dict[str, Any] = ..., ) -> dtype[ubyte]: ... @overload def __new__( @@ -1364,7 +1225,7 @@ class dtype(Generic[_SCT_co]): dtype: _UShortCodes | type[ct.c_ushort], align: builtins.bool = ..., copy: builtins.bool = ..., - metadata: dict[builtins.str, Any] = ..., + metadata: dict[str, Any] = ..., ) -> dtype[ushort]: ... @overload def __new__( @@ -1372,7 +1233,7 @@ class dtype(Generic[_SCT_co]): dtype: _UIntCCodes | type[ct.c_uint], align: builtins.bool = ..., copy: builtins.bool = ..., - metadata: dict[builtins.str, Any] = ..., + metadata: dict[str, Any] = ..., ) -> dtype[uintc]: ... # NOTE: We're assuming here that `uint_ptr_t == size_t`, # an assumption that does not hold in rare cases (same for `ssize_t`) @@ -1382,7 +1243,7 @@ class dtype(Generic[_SCT_co]): dtype: type[ct.c_void_p | ct.c_size_t] | _UIntPCodes, align: builtins.bool = ..., copy: builtins.bool = ..., - metadata: dict[builtins.str, Any] = ..., + metadata: dict[str, Any] = ..., ) -> dtype[uintp]: ... @overload def __new__( @@ -1390,7 +1251,7 @@ class dtype(Generic[_SCT_co]): dtype: _ULongCodes | type[ct.c_ulong], align: builtins.bool = ..., copy: builtins.bool = ..., - metadata: dict[builtins.str, Any] = ..., + metadata: dict[str, Any] = ..., ) -> dtype[ulong]: ... @overload def __new__( @@ -1398,7 +1259,7 @@ class dtype(Generic[_SCT_co]): dtype: _ULongLongCodes | type[ct.c_ulonglong], align: builtins.bool = ..., copy: builtins.bool = ..., - metadata: dict[builtins.str, Any] = ..., + metadata: dict[str, Any] = ..., ) -> dtype[ulonglong]: ... # `signedinteger` string-based representations and ctypes @@ -1408,7 +1269,7 @@ class dtype(Generic[_SCT_co]): dtype: _Int8Codes | type[ct.c_int8], align: builtins.bool = ..., copy: builtins.bool = ..., - metadata: dict[builtins.str, Any] = ..., + metadata: dict[str, Any] = ..., ) -> dtype[int8]: ... @overload def __new__( @@ -1416,7 +1277,7 @@ class dtype(Generic[_SCT_co]): dtype: _Int16Codes | type[ct.c_int16], align: builtins.bool = ..., copy: builtins.bool = ..., - metadata: dict[builtins.str, Any] = ..., + metadata: dict[str, Any] = ..., ) -> dtype[int16]: ... @overload def __new__( @@ -1424,7 +1285,7 @@ class dtype(Generic[_SCT_co]): dtype: _Int32Codes | type[ct.c_int32], align: builtins.bool = ..., copy: builtins.bool = ..., - metadata: dict[builtins.str, Any] = ..., + metadata: dict[str, Any] = ..., ) -> dtype[int32]: ... @overload def __new__( @@ -1432,7 +1293,7 @@ class dtype(Generic[_SCT_co]): dtype: _Int64Codes | type[ct.c_int64], align: builtins.bool = ..., copy: builtins.bool = ..., - metadata: dict[builtins.str, Any] = ..., + metadata: dict[str, Any] = ..., ) -> dtype[int64]: ... @overload def __new__( @@ -1440,7 +1301,7 @@ class dtype(Generic[_SCT_co]): dtype: _ByteCodes | type[ct.c_byte], align: builtins.bool = ..., copy: builtins.bool = ..., - metadata: dict[builtins.str, Any] = ..., + metadata: dict[str, Any] = ..., ) -> dtype[byte]: ... @overload def __new__( @@ -1448,7 +1309,7 @@ class dtype(Generic[_SCT_co]): dtype: _ShortCodes | type[ct.c_short], align: builtins.bool = ..., copy: builtins.bool = ..., - metadata: dict[builtins.str, Any] = ..., + metadata: dict[str, Any] = ..., ) -> dtype[short]: ... @overload def __new__( @@ -1456,7 +1317,7 @@ class dtype(Generic[_SCT_co]): dtype: _IntCCodes | type[ct.c_int], align: builtins.bool = ..., copy: builtins.bool = ..., - metadata: dict[builtins.str, Any] = ..., + metadata: dict[str, Any] = ..., ) -> dtype[intc]: ... @overload def __new__( @@ -1464,7 +1325,7 @@ class dtype(Generic[_SCT_co]): dtype: _IntPCodes | type[ct.c_ssize_t], align: builtins.bool = ..., copy: builtins.bool = ..., - metadata: dict[builtins.str, Any] = ..., + metadata: dict[str, Any] = ..., ) -> dtype[intp]: ... @overload def __new__( @@ -1472,7 +1333,7 @@ class dtype(Generic[_SCT_co]): dtype: _LongCodes | type[ct.c_long], align: builtins.bool = ..., copy: builtins.bool = ..., - metadata: dict[builtins.str, Any] = ..., + metadata: dict[str, Any] = ..., ) -> dtype[long]: ... @overload def __new__( @@ -1480,25 +1341,41 @@ class dtype(Generic[_SCT_co]): dtype: _LongLongCodes | type[ct.c_longlong], align: builtins.bool = ..., copy: builtins.bool = ..., - metadata: dict[builtins.str, Any] = ..., + metadata: dict[str, Any] = ..., ) -> dtype[longlong]: ... # `floating` string-based representations and ctypes @overload def __new__( - cls, dtype: _Float16Codes, align: builtins.bool = ..., copy: builtins.bool = ..., metadata: dict[builtins.str, Any] = ... + cls, + dtype: _Float16Codes, + align: builtins.bool = ..., + copy: builtins.bool = ..., + metadata: dict[str, Any] = ..., ) -> dtype[float16]: ... @overload def __new__( - cls, dtype: _Float32Codes, align: builtins.bool = ..., copy: builtins.bool = ..., metadata: dict[builtins.str, Any] = ... + cls, + dtype: _Float32Codes, + align: builtins.bool = ..., + copy: builtins.bool = ..., + metadata: dict[str, Any] = ..., ) -> dtype[float32]: ... @overload def __new__( - cls, dtype: _Float64Codes, align: builtins.bool = ..., copy: builtins.bool = ..., metadata: dict[builtins.str, Any] = ... + cls, + dtype: _Float64Codes, + align: builtins.bool = ..., + copy: builtins.bool = ..., + metadata: dict[str, Any] = ..., ) -> dtype[float64]: ... @overload def __new__( - cls, dtype: _HalfCodes, align: builtins.bool = ..., copy: builtins.bool = ..., metadata: dict[builtins.str, Any] = ... + cls, + dtype: _HalfCodes, + align: builtins.bool = ..., + copy: builtins.bool = ..., + metadata: dict[str, Any] = ..., ) -> dtype[half]: ... @overload def __new__( @@ -1506,7 +1383,7 @@ class dtype(Generic[_SCT_co]): dtype: _SingleCodes | type[ct.c_float], align: builtins.bool = ..., copy: builtins.bool = ..., - metadata: dict[builtins.str, Any] = ..., + metadata: dict[str, Any] = ..., ) -> dtype[single]: ... @overload def __new__( @@ -1514,7 +1391,7 @@ class dtype(Generic[_SCT_co]): dtype: _DoubleCodes | type[ct.c_double], align: builtins.bool = ..., copy: builtins.bool = ..., - metadata: dict[builtins.str, Any] = ..., + metadata: dict[str, Any] = ..., ) -> dtype[double]: ... @overload def __new__( @@ -1522,7 +1399,7 @@ class dtype(Generic[_SCT_co]): dtype: _LongDoubleCodes | type[ct.c_longdouble], align: builtins.bool = ..., copy: builtins.bool = ..., - metadata: dict[builtins.str, Any] = ..., + metadata: dict[str, Any] = ..., ) -> dtype[longdouble]: ... # `complexfloating` string-based representations @@ -1532,7 +1409,7 @@ class dtype(Generic[_SCT_co]): dtype: _Complex64Codes, align: builtins.bool = ..., copy: builtins.bool = ..., - metadata: dict[builtins.str, Any] = ..., + metadata: dict[str, Any] = ..., ) -> dtype[complex64]: ... @overload def __new__( @@ -1540,15 +1417,23 @@ class dtype(Generic[_SCT_co]): dtype: _Complex128Codes, align: builtins.bool = ..., copy: builtins.bool = ..., - metadata: dict[builtins.str, Any] = ..., + metadata: dict[str, Any] = ..., ) -> dtype[complex128]: ... @overload def __new__( - cls, dtype: _CSingleCodes, align: builtins.bool = ..., copy: builtins.bool = ..., metadata: dict[builtins.str, Any] = ... + cls, + dtype: _CSingleCodes, + align: builtins.bool = ..., + copy: builtins.bool = ..., + metadata: dict[str, Any] = ..., ) -> dtype[csingle]: ... @overload def __new__( - cls, dtype: _CDoubleCodes, align: builtins.bool = ..., copy: builtins.bool = ..., metadata: dict[builtins.str, Any] = ... + cls, + dtype: _CDoubleCodes, + align: builtins.bool = ..., + copy: builtins.bool = ..., + metadata: dict[str, Any] = ..., ) -> dtype[cdouble]: ... @overload def __new__( @@ -1556,7 +1441,7 @@ class dtype(Generic[_SCT_co]): dtype: _CLongDoubleCodes, align: builtins.bool = ..., copy: builtins.bool = ..., - metadata: dict[builtins.str, Any] = ..., + metadata: dict[str, Any] = ..., ) -> dtype[clongdouble]: ... # Miscellaneous string-based representations and ctypes @@ -1566,19 +1451,31 @@ class dtype(Generic[_SCT_co]): dtype: _BoolCodes | type[ct.c_bool], align: builtins.bool = ..., copy: builtins.bool = ..., - metadata: dict[builtins.str, Any] = ..., + metadata: dict[str, Any] = ..., ) -> dtype[np.bool]: ... @overload def __new__( - cls, dtype: _TD64Codes, align: builtins.bool = ..., copy: builtins.bool = ..., metadata: dict[builtins.str, Any] = ... + cls, + dtype: _TD64Codes, + align: builtins.bool = ..., + copy: builtins.bool = ..., + metadata: dict[str, Any] = ..., ) -> dtype[timedelta64]: ... @overload def __new__( - cls, dtype: _DT64Codes, align: builtins.bool = ..., copy: builtins.bool = ..., metadata: dict[builtins.str, Any] = ... + cls, + dtype: _DT64Codes, + align: builtins.bool = ..., + copy: builtins.bool = ..., + metadata: dict[str, Any] = ..., ) -> dtype[datetime64]: ... @overload def __new__( - cls, dtype: _StrCodes, align: builtins.bool = ..., copy: builtins.bool = ..., metadata: dict[builtins.str, Any] = ... + cls, + dtype: _StrCodes, + align: builtins.bool = ..., + copy: builtins.bool = ..., + metadata: dict[str, Any] = ..., ) -> dtype[str_]: ... @overload def __new__( @@ -1586,7 +1483,7 @@ class dtype(Generic[_SCT_co]): dtype: _BytesCodes | type[ct.c_char], align: builtins.bool = ..., copy: builtins.bool = ..., - metadata: dict[builtins.str, Any] = ..., + metadata: dict[str, Any] = ..., ) -> dtype[bytes_]: ... @overload def __new__( @@ -1594,7 +1491,7 @@ class dtype(Generic[_SCT_co]): dtype: _VoidCodes | _VoidDTypeLike, align: builtins.bool = ..., copy: builtins.bool = ..., - metadata: dict[builtins.str, Any] = ..., + metadata: dict[str, Any] = ..., ) -> dtype[void]: ... @overload def __new__( @@ -1602,7 +1499,7 @@ class dtype(Generic[_SCT_co]): dtype: _ObjectCodes | type[ct.py_object[Any]], align: builtins.bool = ..., copy: builtins.bool = ..., - metadata: dict[builtins.str, Any] = ..., + metadata: dict[str, Any] = ..., ) -> dtype[object_]: ... # `StringDType` requires special treatment because it has no scalar type @@ -1612,7 +1509,7 @@ class dtype(Generic[_SCT_co]): dtype: dtypes.StringDType | _StringCodes, align: builtins.bool = ..., copy: builtins.bool = ..., - metadata: dict[builtins.str, Any] = ..., + metadata: dict[str, Any] = ..., ) -> dtypes.StringDType: ... # Combined char-codes and ctypes, analogous to the scalar-type hierarchy @@ -1622,7 +1519,7 @@ class dtype(Generic[_SCT_co]): dtype: _UnsignedIntegerCodes | _UnsignedIntegerCType, align: builtins.bool = ..., copy: builtins.bool = ..., - metadata: dict[builtins.str, Any] = ..., + metadata: dict[str, Any] = ..., ) -> dtype[unsignedinteger[Any]]: ... @overload def __new__( @@ -1630,7 +1527,7 @@ class dtype(Generic[_SCT_co]): dtype: _SignedIntegerCodes | _SignedIntegerCType, align: builtins.bool = ..., copy: builtins.bool = ..., - metadata: dict[builtins.str, Any] = ..., + metadata: dict[str, Any] = ..., ) -> dtype[signedinteger[Any]]: ... @overload def __new__( @@ -1638,7 +1535,7 @@ class dtype(Generic[_SCT_co]): dtype: _IntegerCodes | _IntegerCType, align: builtins.bool = ..., copy: builtins.bool = ..., - metadata: dict[builtins.str, Any] = ..., + metadata: dict[str, Any] = ..., ) -> dtype[integer[Any]]: ... @overload def __new__( @@ -1646,7 +1543,7 @@ class dtype(Generic[_SCT_co]): dtype: _FloatingCodes | _FloatingCType, align: builtins.bool = ..., copy: builtins.bool = ..., - metadata: dict[builtins.str, Any] = ..., + metadata: dict[str, Any] = ..., ) -> dtype[floating[Any]]: ... @overload def __new__( @@ -1654,7 +1551,7 @@ class dtype(Generic[_SCT_co]): dtype: _ComplexFloatingCodes, align: builtins.bool = ..., copy: builtins.bool = ..., - metadata: dict[builtins.str, Any] = ..., + metadata: dict[str, Any] = ..., ) -> dtype[complexfloating[Any, Any]]: ... @overload def __new__( @@ -1662,7 +1559,7 @@ class dtype(Generic[_SCT_co]): dtype: _InexactCodes | _FloatingCType, align: builtins.bool = ..., copy: builtins.bool = ..., - metadata: dict[builtins.str, Any] = ..., + metadata: dict[str, Any] = ..., ) -> dtype[inexact[Any]]: ... @overload def __new__( @@ -1670,7 +1567,7 @@ class dtype(Generic[_SCT_co]): dtype: _NumberCodes | _NumberCType, align: builtins.bool = ..., copy: builtins.bool = ..., - metadata: dict[builtins.str, Any] = ..., + metadata: dict[str, Any] = ..., ) -> dtype[number[Any]]: ... @overload def __new__( @@ -1678,7 +1575,7 @@ class dtype(Generic[_SCT_co]): dtype: _CharacterCodes | type[ct.c_char], align: builtins.bool = ..., copy: builtins.bool = ..., - metadata: dict[builtins.str, Any] = ..., + metadata: dict[str, Any] = ..., ) -> dtype[character]: ... @overload def __new__( @@ -1686,7 +1583,7 @@ class dtype(Generic[_SCT_co]): dtype: _FlexibleCodes | type[ct.c_char], align: builtins.bool = ..., copy: builtins.bool = ..., - metadata: dict[builtins.str, Any] = ..., + metadata: dict[str, Any] = ..., ) -> dtype[flexible]: ... @overload def __new__( @@ -1694,17 +1591,17 @@ class dtype(Generic[_SCT_co]): dtype: _GenericCodes | _GenericCType, align: builtins.bool = ..., copy: builtins.bool = ..., - metadata: dict[builtins.str, Any] = ..., + metadata: dict[str, Any] = ..., ) -> dtype[generic]: ... # Handle strings that can't be expressed as literals; i.e. "S1", "S2", ... @overload def __new__( cls, - dtype: builtins.str, + dtype: str, align: builtins.bool = ..., copy: builtins.bool = ..., - metadata: dict[builtins.str, Any] = ..., + metadata: dict[str, Any] = ..., ) -> dtype[Any]: ... # Catch-all overload for object-likes @@ -1718,13 +1615,13 @@ class dtype(Generic[_SCT_co]): dtype: type[object], align: builtins.bool = ..., copy: builtins.bool = ..., - metadata: dict[builtins.str, Any] = ..., + metadata: dict[str, Any] = ..., ) -> dtype[object_ | Any]: ... def __class_getitem__(cls, item: Any, /) -> GenericAlias: ... @overload - def __getitem__(self: dtype[void], key: list[builtins.str], /) -> dtype[void]: ... + def __getitem__(self: dtype[void], key: list[str], /) -> dtype[void]: ... @overload - def __getitem__(self: dtype[void], key: builtins.str | SupportsIndex, /) -> dtype[Any]: ... + def __getitem__(self: dtype[void], key: str | SupportsIndex, /) -> dtype[Any]: ... # NOTE: In the future 1-based multiplications will also yield `flexible` dtypes @overload @@ -1778,7 +1675,7 @@ class dtype(Generic[_SCT_co]): @property def kind(self) -> _DTypeKind: ... @property - def metadata(self) -> MappingProxyType[builtins.str, Any] | None: ... + def metadata(self) -> MappingProxyType[str, Any] | None: ... @property def name(self) -> LiteralString: ... @property @@ -1812,11 +1709,13 @@ class flatiter(Generic[_ArrayT_co]): def __getitem__( self: flatiter[NDArray[_SCT]], key: int | integer[Any] | tuple[int | integer[Any]], + /, ) -> _SCT: ... @overload def __getitem__( self, key: _ArrayLikeInt | slice | EllipsisType | tuple[_ArrayLikeInt | slice | EllipsisType], + /, ) -> _ArrayT_co: ... # TODO: `__setitem__` operates via `unsafe` casting rules, and can # thus accept any type accepted by the relevant underlying `np.generic` @@ -1826,6 +1725,7 @@ class flatiter(Generic[_ArrayT_co]): self, key: _ArrayLikeInt | slice | EllipsisType | tuple[_ArrayLikeInt | slice | EllipsisType], value: Any, + /, ) -> None: ... @overload def __array__(self: flatiter[ndarray[_1DShapeT, _DType]], dtype: None = ..., /) -> ndarray[_1DShapeT, _DType]: ... @@ -1870,8 +1770,6 @@ class _ArrayOrScalarCommon: def dump(self, file: StrOrBytesPath | SupportsWrite[bytes]) -> None: ... def dumps(self) -> bytes: ... def tobytes(self, order: _OrderKACF = ...) -> bytes: ... - # NOTE: `tostring()` is deprecated and therefore excluded - # def tostring(self, order=...): ... def tofile(self, fid: StrOrBytesPath | _SupportsFileMethods, sep: str = ..., format: str = ...) -> None: ... # generics and 0d arrays return builtin scalars def tolist(self) -> Any: ... @@ -2362,22 +2260,20 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DType_co]): @overload def resize(self, *new_shape: SupportsIndex, refcheck: builtins.bool = ...) -> None: ... def setflags(self, write: builtins.bool = ..., align: builtins.bool = ..., uic: builtins.bool = ...) -> None: ... - def squeeze( - self, - axis: SupportsIndex | tuple[SupportsIndex, ...] | None = ..., - ) -> ndarray[_Shape, _DType_co]: ... - def swapaxes( - self, - axis1: SupportsIndex, - axis2: SupportsIndex, - ) -> ndarray[_Shape, _DType_co]: ... + def squeeze(self, axis: SupportsIndex | tuple[SupportsIndex, ...] | None = ...) -> ndarray[_Shape, _DType_co]: ... + def swapaxes(self, axis1: SupportsIndex, axis2: SupportsIndex) -> ndarray[_Shape, _DType_co]: ... @overload def transpose(self, axes: _ShapeLike | None, /) -> Self: ... @overload def transpose(self, *axes: SupportsIndex) -> Self: ... @overload def all( - self, axis: None = None, out: None = None, keepdims: L[False, 0] = False, *, where: _ArrayLikeBool_co = True + self, + axis: None = None, + out: None = None, + keepdims: L[False, 0] = False, + *, + where: _ArrayLikeBool_co = True, ) -> np.bool: ... @overload def all( @@ -2408,7 +2304,12 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DType_co]): ) -> _ArrayT: ... @overload def any( - self, axis: None = None, out: None = None, keepdims: L[False, 0] = False, *, where: _ArrayLikeBool_co = True + self, + axis: None = None, + out: None = None, + keepdims: L[False, 0] = False, + *, + where: _ArrayLikeBool_co = True, ) -> np.bool: ... @overload def any( @@ -2472,12 +2373,7 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DType_co]): # `put` is technically available to `generic`, # but is pointless as `generic`s are immutable - def put( - self, - ind: _ArrayLikeInt_co, - v: ArrayLike, - mode: _ModeKind = ..., - ) -> None: ... + def put(self, ind: _ArrayLikeInt_co, v: ArrayLike, mode: _ModeKind = ...) -> None: ... @overload def searchsorted( # type: ignore[misc] self, # >= 1D array @@ -2492,12 +2388,7 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DType_co]): side: _SortSide = ..., sorter: _ArrayLikeInt_co | None = ..., ) -> NDArray[intp]: ... - def setfield( - self, - val: ArrayLike, - dtype: DTypeLike, - offset: SupportsIndex = ..., - ) -> None: ... + def setfield(self, val: ArrayLike, dtype: DTypeLike, offset: SupportsIndex = ...) -> None: ... def sort( self, axis: SupportsIndex = ..., @@ -2525,7 +2416,7 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DType_co]): out: _ArrayT = ..., ) -> _ArrayT: ... @overload - def take( # type: ignore[misc] + def take( self: NDArray[_SCT], indices: _IntLike_co, axis: SupportsIndex | None = ..., @@ -2533,7 +2424,7 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DType_co]): mode: _ModeKind = ..., ) -> _SCT: ... @overload - def take( # type: ignore[misc] + def take( self, indices: _ArrayLikeInt_co, axis: SupportsIndex | None = ..., @@ -2571,12 +2462,12 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DType_co]): @overload # (() | (int) | (int, int) | ....) # up to 8-d def reshape( self, - shape: _AnyShapeType, + shape: _AnyShapeT, /, *, order: _OrderACF = "C", copy: builtins.bool | None = None, - ) -> ndarray[_AnyShapeType, _DType_co]: ... + ) -> ndarray[_AnyShapeT, _DType_co]: ... @overload # (index) def reshape( self, @@ -2737,15 +2628,6 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DType_co]): # Unary ops - # TODO: Uncomment once https://github.com/python/mypy/issues/14070 is fixed - # @overload - # def __abs__(self: ndarray[_ShapeType, dtypes.Complex64DType], /) -> ndarray[_ShapeType, dtypes.Float32DType]: ... - # @overload - # def __abs__(self: ndarray[_ShapeType, dtypes.Complex128DType], /) -> ndarray[_ShapeType, dtypes.Float64DType]: ... - # @overload - # def __abs__(self: ndarray[_ShapeType, dtypes.CLongDoubleDType], /) -> ndarray[_ShapeType, dtypes.LongDoubleDType]: ... - # @overload - # def __abs__(self: ndarray[_ShapeType, dtype[complex128]], /) -> ndarray[_ShapeType, dtype[float64]]: ... @overload def __abs__( self: ndarray[_ShapeT, dtype[complexfloating[_AnyNBitInexact]]], / @@ -3634,13 +3516,13 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DType_co]): def dtype(self) -> _DType_co: ... # NOTE: while `np.generic` is not technically an instance of `ABCMeta`, -# the `@abstractmethod` decorator is herein used to (forcefully) deny +# the `@abc.abstractmethod` decorator is herein used to (forcefully) deny # the creation of `np.generic` instances. # The `# type: ignore` comments are necessary to silence mypy errors regarding # the missing `ABCMeta` metaclass. # See https://github.com/numpy/numpy-stubs/pull/80 for more details. class generic(_ArrayOrScalarCommon, Generic[_ItemT_co]): - @abstractmethod + @abc.abstractmethod def __init__(self, *args: Any, **kwargs: Any) -> None: ... def __hash__(self) -> int: ... @overload @@ -3884,7 +3766,7 @@ class generic(_ArrayOrScalarCommon, Generic[_ItemT_co]): def dtype(self) -> _dtype[Self]: ... class number(generic[_NumberItemT_co], Generic[_NBit, _NumberItemT_co]): - @abstractmethod + @abc.abstractmethod def __init__(self, value: _NumberItemT_co, /) -> None: ... def __class_getitem__(cls, item: Any, /) -> GenericAlias: ... def __neg__(self) -> Self: ... @@ -4040,7 +3922,7 @@ class object_(_RealMixin, generic): def __release_buffer__(self, buffer: memoryview, /) -> None: ... class integer(_IntegralMixin, _RoundMixin, number[_NBit, int]): - @abstractmethod + @abc.abstractmethod def __init__(self, value: _ConvertibleToInt = ..., /) -> None: ... # NOTE: `bit_count` and `__index__` are technically defined in the concrete subtypes @@ -4143,12 +4025,12 @@ ubyte: TypeAlias = unsignedinteger[_NBitByte] ushort: TypeAlias = unsignedinteger[_NBitShort] uintc: TypeAlias = unsignedinteger[_NBitIntC] uintp: TypeAlias = unsignedinteger[_NBitIntP] -uint: TypeAlias = uintp +uint64: TypeAlias = uintp ulong: TypeAlias = unsignedinteger[_NBitLong] ulonglong: TypeAlias = unsignedinteger[_NBitLongLong] class inexact(number[_NBit, _InexactItemT_co], Generic[_NBit, _InexactItemT_co]): - @abstractmethod + @abc.abstractmethod def __init__(self, value: _InexactItemT_co | None = ..., /) -> None: ... class floating(_RealMixin, _RoundMixin, inexact[_NBit1, float]): @@ -4675,7 +4557,7 @@ class void(flexible[bytes | tuple[Any, ...]]): def setfield(self, val: ArrayLike, dtype: DTypeLike, offset: int = ...) -> None: ... class character(flexible[_CharacterItemT_co], Generic[_CharacterItemT_co]): - @abstractmethod + @abc.abstractmethod def __init__(self, value: _CharacterItemT_co = ..., /) -> None: ... # NOTE: Most `np.bytes_` / `np.str_` methods return their builtin `bytes` / `str` counterpart @@ -5175,12 +5057,7 @@ class poly1d: def __call__(self, val: poly1d) -> poly1d: ... @overload def __call__(self, val: ArrayLike) -> NDArray[Any]: ... - def __init__( - self, - c_or_r: ArrayLike, - r: builtins.bool = ..., - variable: str | None = ..., - ) -> None: ... + def __init__(self, c_or_r: ArrayLike, r: builtins.bool = ..., variable: str | None = ...) -> None: ... def __len__(self) -> int: ... def __neg__(self) -> poly1d: ... def __pos__(self) -> poly1d: ... @@ -5237,9 +5114,9 @@ class matrix(ndarray[_2DShapeT_co, _DType_co]): def __getitem__(self: NDArray[void], key: list[str], /) -> matrix[_2DShapeT_co, dtype[void]]: ... def __mul__(self, other: ArrayLike, /) -> matrix[_2D, Any]: ... def __rmul__(self, other: ArrayLike, /) -> matrix[_2D, Any]: ... - def __imul__(self, other: ArrayLike, /) -> matrix[_2DShapeT_co, _DType_co]: ... + def __imul__(self, other: ArrayLike, /) -> Self: ... def __pow__(self, other: ArrayLike, /) -> matrix[_2D, Any]: ... - def __ipow__(self, other: ArrayLike, /) -> matrix[_2DShapeT_co, _DType_co]: ... + def __ipow__(self, other: ArrayLike, /) -> Self: ... @overload def sum(self, axis: None = ..., dtype: DTypeLike = ..., out: None = ...) -> Any: ... @overload diff --git a/src/numpy-stubs/_array_api_info.pyi b/src/numpy-stubs/_array_api_info.pyi index a04b6e6b..2135908a 100644 --- a/src/numpy-stubs/_array_api_info.pyi +++ b/src/numpy-stubs/_array_api_info.pyi @@ -1,14 +1,5 @@ -from typing import ( - ClassVar, - Literal, - Never, - TypeAlias, - TypeVar, - TypedDict, - final, - overload, - type_check_only, -) +from typing import ClassVar, Literal, TypeAlias, TypeVar, TypedDict, final, overload, type_check_only +from typing_extensions import Never import numpy as np diff --git a/src/numpy-stubs/_core/_internal.pyi b/src/numpy-stubs/_core/_internal.pyi index 8ac10f85..a5355600 100644 --- a/src/numpy-stubs/_core/_internal.pyi +++ b/src/numpy-stubs/_core/_internal.pyi @@ -1,23 +1,24 @@ import ctypes as ct -from typing import Any, Generic, TypeVar, overload +from typing import Any, Generic, overload +from typing_extensions import TypeVar +import numpy.typing as npt from numpy.ctypeslib import c_intp -from numpy.typing import NDArray _CastT = TypeVar("_CastT", bound=ct._CanCastTo) # Copied from `ctypes.cast` _CT = TypeVar("_CT", bound=ct._CData) -_PT = TypeVar("_PT", bound=int) +_PT_co = TypeVar("_PT_co", bound=int | None, default=None, covariant=True) # TODO: Let the likes of `shape_as` and `strides_as` return `None` # for 0D arrays once we've got shape-support -class _ctypes(Generic[_PT]): +class _ctypes(Generic[_PT_co]): @overload - def __new__(cls, array: NDArray[Any], ptr: None = ...) -> _ctypes[None]: ... + def __new__(cls, array: npt.NDArray[Any], ptr: None = ...) -> _ctypes[None]: ... @overload - def __new__(cls, array: NDArray[Any], ptr: _PT) -> _ctypes[_PT]: ... + def __new__(cls, array: npt.NDArray[Any], ptr: _PT_co) -> _ctypes[_PT_co]: ... @property - def data(self) -> _PT: ... + def data(self) -> _PT_co: ... @property def shape(self) -> ct.Array[c_intp]: ... @property diff --git a/src/numpy-stubs/_core/_ufunc_config.pyi b/src/numpy-stubs/_core/_ufunc_config.pyi index 86df9827..4bb6f9d9 100644 --- a/src/numpy-stubs/_core/_ufunc_config.pyi +++ b/src/numpy-stubs/_core/_ufunc_config.pyi @@ -2,7 +2,9 @@ from _typeshed import SupportsWrite from collections.abc import Callable from typing import Any, Literal, TypeAlias, TypedDict, type_check_only -from numpy import errstate as errstate +from numpy import errstate as errstate # noqa: ICN003 + +__all__ = ["errstate", "getbufsize", "geterr", "geterrcall", "setbufsize", "seterr", "seterrcall"] _ErrKind: TypeAlias = Literal["ignore", "warn", "raise", "call", "print", "log"] _ErrFunc: TypeAlias = Callable[[str, int], Any] @@ -27,5 +29,3 @@ def setbufsize(size: int) -> int: ... def getbufsize() -> int: ... def seterrcall(func: _ErrCall | None) -> _ErrCall | None: ... def geterrcall() -> _ErrCall | None: ... - -# See `numpy/__init__.pyi` for the `errstate` class and `no_nep5_warnings` diff --git a/src/numpy-stubs/_core/arrayprint.pyi b/src/numpy-stubs/_core/arrayprint.pyi index f2d4bd8c..b9449ad0 100644 --- a/src/numpy-stubs/_core/arrayprint.pyi +++ b/src/numpy-stubs/_core/arrayprint.pyi @@ -1,42 +1,32 @@ from collections.abc import Callable - -# Using a private class is by no means ideal, but it is simply a consequence -# of a `contextlib.context` returning an instance of aforementioned class from contextlib import _GeneratorContextManager from typing import Any, Literal, SupportsIndex, TypeAlias, TypedDict, type_check_only import numpy as np -from numpy import ( - clongdouble, - complexfloating, - datetime64, - floating, - integer, - longdouble, - timedelta64, - void, -) from numpy._typing import NDArray, _CharLike_co, _FloatLike_co _FloatMode: TypeAlias = Literal["fixed", "unique", "maxprec", "maxprec_equal"] +_Sign: TypeAlias = Literal["-", "+", " "] +_Legacy: TypeAlias = Literal[False, "1.13", "1.21"] +_Trim: TypeAlias = Literal["k", ".", "0", "-"] @type_check_only class _FormatDict(TypedDict, total=False): bool: Callable[[np.bool], str] - int: Callable[[integer[Any]], str] - timedelta: Callable[[timedelta64], str] - datetime: Callable[[datetime64], str] - float: Callable[[floating[Any]], str] - longfloat: Callable[[longdouble], str] - complexfloat: Callable[[complexfloating[Any, Any]], str] - longcomplexfloat: Callable[[clongdouble], str] - void: Callable[[void], str] + int: Callable[[np.integer], str] + timedelta: Callable[[np.timedelta64], str] + datetime: Callable[[np.datetime64], str] + float: Callable[[np.floating], str] + longfloat: Callable[[np.longdouble], str] + complexfloat: Callable[[np.complexfloating], str] + longcomplexfloat: Callable[[np.clongdouble], str] + void: Callable[[np.void], str] numpystr: Callable[[_CharLike_co], str] object: Callable[[object], str] all: Callable[[object], str] - int_kind: Callable[[integer[Any]], str] - float_kind: Callable[[floating[Any]], str] - complex_kind: Callable[[complexfloating[Any, Any]], str] + int_kind: Callable[[np.integer], str] + float_kind: Callable[[np.floating], str] + complex_kind: Callable[[np.complexfloating], str] str_kind: Callable[[_CharLike_co], str] @type_check_only @@ -49,9 +39,9 @@ class _FormatOptions(TypedDict): nanstr: str infstr: str formatter: _FormatDict | None - sign: Literal["-", "+", " "] + sign: _Sign floatmode: _FloatMode - legacy: Literal[False, "1.13", "1.21"] + legacy: _Legacy def set_printoptions( precision: SupportsIndex | None = ..., @@ -62,10 +52,10 @@ def set_printoptions( nanstr: str | None = ..., infstr: str | None = ..., formatter: _FormatDict | None = ..., - sign: Literal["-", "+", " "] | None = ..., + sign: _Sign | None = ..., floatmode: _FloatMode | None = ..., *, - legacy: Literal[False, "1.13", "1.21"] | None = ..., + legacy: _Legacy | None = ..., override_repr: Callable[[NDArray[Any]], str] | None = ..., ) -> None: ... def get_printoptions() -> _FormatOptions: ... @@ -83,16 +73,16 @@ def array2string( formatter: _FormatDict | None = ..., threshold: int | None = ..., edgeitems: int | None = ..., - sign: Literal["-", "+", " "] | None = ..., + sign: _Sign | None = ..., floatmode: _FloatMode | None = ..., suffix: str = ..., - legacy: Literal[False, "1.13", "1.21"] | None = ..., + legacy: _Legacy | None = ..., ) -> str: ... def format_float_scientific( x: _FloatLike_co, precision: int | None = ..., unique: bool = ..., - trim: Literal["k", ".", "0", "-"] = ..., + trim: _Trim = ..., sign: bool = ..., pad_left: int | None = ..., exp_digits: int | None = ..., @@ -103,7 +93,7 @@ def format_float_positional( precision: int | None = ..., unique: bool = ..., fractional: bool = ..., - trim: Literal["k", ".", "0", "-"] = ..., + trim: _Trim = ..., sign: bool = ..., pad_left: int | None = ..., pad_right: int | None = ..., @@ -130,8 +120,8 @@ def printoptions( nanstr: str | None = ..., infstr: str | None = ..., formatter: _FormatDict | None = ..., - sign: Literal["-", "+", " "] | None = ..., + sign: _Sign | None = ..., floatmode: _FloatMode | None = ..., *, - legacy: Literal[False, "1.13", "1.21"] | None = ..., + legacy: _Legacy | None = ..., ) -> _GeneratorContextManager[_FormatOptions]: ... diff --git a/src/numpy-stubs/_core/defchararray.pyi b/src/numpy-stubs/_core/defchararray.pyi index 697c8136..f8df48ce 100644 --- a/src/numpy-stubs/_core/defchararray.pyi +++ b/src/numpy-stubs/_core/defchararray.pyi @@ -1,15 +1,6 @@ -from typing import ( - Any, - Literal as L, - SupportsIndex, - SupportsInt, - TypeAlias, - TypeVar, - overload, -) +from typing import Any, Literal as L, SupportsIndex, SupportsInt, TypeAlias, TypeVar, overload import numpy as np -from numpy import _OrderKACF, _SupportsArray, _SupportsBuffer, bytes_, dtype, int_, ndarray, object_, str_ from numpy._core.multiarray import compare_chararrays from numpy._typing import ( NDArray, @@ -21,6 +12,7 @@ from numpy._typing import ( _ArrayLikeString_co as T_co, _Shape, _ShapeLike, + _SupportsArray, ) __all__ = [ @@ -80,395 +72,233 @@ __all__ = [ ] _ShapeT_co = TypeVar("_ShapeT_co", bound=tuple[int, ...], covariant=True) +_CharDType_co = TypeVar("_CharDType_co", bound=np.dtype[np.character], covariant=True) _SCT = TypeVar("_SCT", bound=np.character) -_CharDType_co = TypeVar("_CharDType_co", bound=dtype[np.character], covariant=True) -_CharArray: TypeAlias = chararray[tuple[int, ...], dtype[_SCT]] + +_CharArray: TypeAlias = chararray[tuple[int, ...], np.dtype[_SCT]] _StringDTypeArray: TypeAlias = np.ndarray[_Shape, np.dtypes.StringDType] _StringDTypeSupportsArray: TypeAlias = _SupportsArray[np.dtypes.StringDType] _StringDTypeOrUnicodeArray: TypeAlias = np.ndarray[_Shape, np.dtype[np.str_]] | np.ndarray[_Shape, np.dtypes.StringDType] -class chararray(ndarray[_ShapeT_co, _CharDType_co]): +class chararray(np.ndarray[_ShapeT_co, _CharDType_co]): @overload def __new__( cls, shape: _ShapeLike, itemsize: SupportsIndex | SupportsInt = ..., unicode: L[False] = ..., - buffer: _SupportsBuffer = ..., + buffer: np._SupportsBuffer = ..., offset: SupportsIndex = ..., strides: _ShapeLike = ..., - order: _OrderKACF = ..., - ) -> chararray[_Shape, dtype[bytes_]]: ... + order: np._OrderKACF = ..., + ) -> chararray[_Shape, np.dtype[np.bytes_]]: ... @overload def __new__( cls, shape: _ShapeLike, itemsize: SupportsIndex | SupportsInt = ..., unicode: L[True] = ..., - buffer: _SupportsBuffer = ..., + buffer: np._SupportsBuffer = ..., offset: SupportsIndex = ..., strides: _ShapeLike = ..., - order: _OrderKACF = ..., - ) -> chararray[_Shape, dtype[str_]]: ... + order: np._OrderKACF = ..., + ) -> chararray[_Shape, np.dtype[np.str_]]: ... def __array_finalize__(self, obj: object) -> None: ... - def __mul__(self, other: i_co) -> chararray[_Shape, _CharDType_co]: ... - def __rmul__(self, other: i_co) -> chararray[_Shape, _CharDType_co]: ... - def __mod__(self, i: Any) -> chararray[_Shape, _CharDType_co]: ... - @overload - def __eq__( - self: _CharArray[str_], - other: U_co, - ) -> NDArray[np.bool]: ... - @overload - def __eq__( - self: _CharArray[bytes_], - other: S_co, - ) -> NDArray[np.bool]: ... - @overload - def __ne__( - self: _CharArray[str_], - other: U_co, - ) -> NDArray[np.bool]: ... - @overload - def __ne__( - self: _CharArray[bytes_], - other: S_co, - ) -> NDArray[np.bool]: ... - @overload - def __ge__( - self: _CharArray[str_], - other: U_co, - ) -> NDArray[np.bool]: ... - @overload - def __ge__( - self: _CharArray[bytes_], - other: S_co, - ) -> NDArray[np.bool]: ... - @overload - def __le__( - self: _CharArray[str_], - other: U_co, - ) -> NDArray[np.bool]: ... - @overload - def __le__( - self: _CharArray[bytes_], - other: S_co, - ) -> NDArray[np.bool]: ... - @overload - def __gt__( - self: _CharArray[str_], - other: U_co, - ) -> NDArray[np.bool]: ... - @overload - def __gt__( - self: _CharArray[bytes_], - other: S_co, - ) -> NDArray[np.bool]: ... - @overload - def __lt__( - self: _CharArray[str_], - other: U_co, - ) -> NDArray[np.bool]: ... - @overload - def __lt__( - self: _CharArray[bytes_], - other: S_co, - ) -> NDArray[np.bool]: ... - @overload - def __add__( - self: _CharArray[str_], - other: U_co, - ) -> _CharArray[str_]: ... - @overload - def __add__( - self: _CharArray[bytes_], - other: S_co, - ) -> _CharArray[bytes_]: ... - @overload - def __radd__( - self: _CharArray[str_], - other: U_co, - ) -> _CharArray[str_]: ... - @overload - def __radd__( - self: _CharArray[bytes_], - other: S_co, - ) -> _CharArray[bytes_]: ... - @overload - def center( - self: _CharArray[str_], - width: i_co, - fillchar: U_co = ..., - ) -> _CharArray[str_]: ... - @overload - def center( - self: _CharArray[bytes_], - width: i_co, - fillchar: S_co = ..., - ) -> _CharArray[bytes_]: ... - @overload - def count( - self: _CharArray[str_], - sub: U_co, - start: i_co = ..., - end: i_co | None = ..., - ) -> NDArray[int_]: ... - @overload - def count( - self: _CharArray[bytes_], - sub: S_co, - start: i_co = ..., - end: i_co | None = ..., - ) -> NDArray[int_]: ... - def decode( - self: _CharArray[bytes_], - encoding: str | None = ..., - errors: str | None = ..., - ) -> _CharArray[str_]: ... - def encode( - self: _CharArray[str_], - encoding: str | None = ..., - errors: str | None = ..., - ) -> _CharArray[bytes_]: ... - @overload - def endswith( - self: _CharArray[str_], - suffix: U_co, - start: i_co = ..., - end: i_co | None = ..., - ) -> NDArray[np.bool]: ... - @overload - def endswith( - self: _CharArray[bytes_], - suffix: S_co, - start: i_co = ..., - end: i_co | None = ..., - ) -> NDArray[np.bool]: ... - def expandtabs( - self, - tabsize: i_co = ..., - ) -> chararray[_Shape, _CharDType_co]: ... - @overload - def find( - self: _CharArray[str_], - sub: U_co, - start: i_co = ..., - end: i_co | None = ..., - ) -> NDArray[int_]: ... - @overload - def find( - self: _CharArray[bytes_], - sub: S_co, - start: i_co = ..., - end: i_co | None = ..., - ) -> NDArray[int_]: ... - @overload - def index( - self: _CharArray[str_], - sub: U_co, - start: i_co = ..., - end: i_co | None = ..., - ) -> NDArray[int_]: ... - @overload - def index( - self: _CharArray[bytes_], - sub: S_co, - start: i_co = ..., - end: i_co | None = ..., - ) -> NDArray[int_]: ... - @overload - def join( - self: _CharArray[str_], - seq: U_co, - ) -> _CharArray[str_]: ... - @overload - def join( - self: _CharArray[bytes_], - seq: S_co, - ) -> _CharArray[bytes_]: ... - @overload - def ljust( - self: _CharArray[str_], - width: i_co, - fillchar: U_co = ..., - ) -> _CharArray[str_]: ... - @overload - def ljust( - self: _CharArray[bytes_], - width: i_co, - fillchar: S_co = ..., - ) -> _CharArray[bytes_]: ... - @overload - def lstrip( - self: _CharArray[str_], - chars: U_co | None = ..., - ) -> _CharArray[str_]: ... - @overload - def lstrip( - self: _CharArray[bytes_], - chars: S_co | None = ..., - ) -> _CharArray[bytes_]: ... - @overload - def partition( - self: _CharArray[str_], - sep: U_co, - ) -> _CharArray[str_]: ... - @overload - def partition( - self: _CharArray[bytes_], - sep: S_co, - ) -> _CharArray[bytes_]: ... - @overload - def replace( - self: _CharArray[str_], - old: U_co, - new: U_co, - count: i_co | None = ..., - ) -> _CharArray[str_]: ... - @overload - def replace( - self: _CharArray[bytes_], - old: S_co, - new: S_co, - count: i_co | None = ..., - ) -> _CharArray[bytes_]: ... - @overload - def rfind( - self: _CharArray[str_], - sub: U_co, - start: i_co = ..., - end: i_co | None = ..., - ) -> NDArray[int_]: ... - @overload - def rfind( - self: _CharArray[bytes_], - sub: S_co, - start: i_co = ..., - end: i_co | None = ..., - ) -> NDArray[int_]: ... - @overload - def rindex( - self: _CharArray[str_], - sub: U_co, - start: i_co = ..., - end: i_co | None = ..., - ) -> NDArray[int_]: ... - @overload - def rindex( - self: _CharArray[bytes_], - sub: S_co, - start: i_co = ..., - end: i_co | None = ..., - ) -> NDArray[int_]: ... - @overload - def rjust( - self: _CharArray[str_], - width: i_co, - fillchar: U_co = ..., - ) -> _CharArray[str_]: ... - @overload - def rjust( - self: _CharArray[bytes_], - width: i_co, - fillchar: S_co = ..., - ) -> _CharArray[bytes_]: ... - @overload - def rpartition( - self: _CharArray[str_], - sep: U_co, - ) -> _CharArray[str_]: ... - @overload - def rpartition( - self: _CharArray[bytes_], - sep: S_co, - ) -> _CharArray[bytes_]: ... - @overload - def rsplit( - self: _CharArray[str_], - sep: U_co | None = ..., - maxsplit: i_co | None = ..., - ) -> NDArray[object_]: ... - @overload - def rsplit( - self: _CharArray[bytes_], - sep: S_co | None = ..., - maxsplit: i_co | None = ..., - ) -> NDArray[object_]: ... - @overload - def rstrip( - self: _CharArray[str_], - chars: U_co | None = ..., - ) -> _CharArray[str_]: ... - @overload - def rstrip( - self: _CharArray[bytes_], - chars: S_co | None = ..., - ) -> _CharArray[bytes_]: ... - @overload - def split( - self: _CharArray[str_], - sep: U_co | None = ..., - maxsplit: i_co | None = ..., - ) -> NDArray[object_]: ... - @overload - def split( - self: _CharArray[bytes_], - sep: S_co | None = ..., - maxsplit: i_co | None = ..., - ) -> NDArray[object_]: ... - def splitlines(self, keepends: b_co | None = ...) -> NDArray[object_]: ... - @overload - def startswith( - self: _CharArray[str_], - prefix: U_co, - start: i_co = ..., - end: i_co | None = ..., - ) -> NDArray[np.bool]: ... - @overload - def startswith( - self: _CharArray[bytes_], - prefix: S_co, - start: i_co = ..., - end: i_co | None = ..., - ) -> NDArray[np.bool]: ... - @overload - def strip( - self: _CharArray[str_], - chars: U_co | None = ..., - ) -> _CharArray[str_]: ... - @overload - def strip( - self: _CharArray[bytes_], - chars: S_co | None = ..., - ) -> _CharArray[bytes_]: ... - @overload - def translate( - self: _CharArray[str_], - table: U_co, - deletechars: U_co | None = ..., - ) -> _CharArray[str_]: ... - @overload - def translate( - self: _CharArray[bytes_], - table: S_co, - deletechars: S_co | None = ..., - ) -> _CharArray[bytes_]: ... + + # + def __mul__(self, other: i_co, /) -> chararray[_Shape, _CharDType_co]: ... + def __rmul__(self, other: i_co, /) -> chararray[_Shape, _CharDType_co]: ... + + # + def __mod__(self, i: Any, /) -> chararray[_Shape, _CharDType_co]: ... + + # + @overload + def __eq__(self: _CharArray[np.str_], other: U_co, /) -> NDArray[np.bool]: ... + @overload + def __eq__(self: _CharArray[np.bytes_], other: S_co, /) -> NDArray[np.bool]: ... + @overload + def __ne__(self: _CharArray[np.str_], other: U_co, /) -> NDArray[np.bool]: ... + @overload + def __ne__(self: _CharArray[np.bytes_], other: S_co, /) -> NDArray[np.bool]: ... + + # + @overload + def __ge__(self: _CharArray[np.str_], other: U_co, /) -> NDArray[np.bool]: ... + @overload + def __ge__(self: _CharArray[np.bytes_], other: S_co, /) -> NDArray[np.bool]: ... + @overload + def __le__(self: _CharArray[np.str_], other: U_co, /) -> NDArray[np.bool]: ... + @overload + def __le__(self: _CharArray[np.bytes_], other: S_co, /) -> NDArray[np.bool]: ... + @overload + def __gt__(self: _CharArray[np.str_], other: U_co, /) -> NDArray[np.bool]: ... + @overload + def __gt__(self: _CharArray[np.bytes_], other: S_co, /) -> NDArray[np.bool]: ... + @overload + def __lt__(self: _CharArray[np.str_], other: U_co, /) -> NDArray[np.bool]: ... + @overload + def __lt__(self: _CharArray[np.bytes_], other: S_co, /) -> NDArray[np.bool]: ... + + # + @overload + def __add__(self: _CharArray[np.str_], other: U_co, /) -> _CharArray[np.str_]: ... + @overload + def __add__(self: _CharArray[np.bytes_], other: S_co, /) -> _CharArray[np.bytes_]: ... + @overload + def __radd__(self: _CharArray[np.str_], other: U_co, /) -> _CharArray[np.str_]: ... + @overload + def __radd__(self: _CharArray[np.bytes_], other: S_co, /) -> _CharArray[np.bytes_]: ... + + # + @overload + def center(self: _CharArray[np.str_], width: i_co, fillchar: U_co = ...) -> _CharArray[np.str_]: ... + @overload + def center(self: _CharArray[np.bytes_], width: i_co, fillchar: S_co = ...) -> _CharArray[np.bytes_]: ... + + # + @overload + def count(self: _CharArray[np.str_], sub: U_co, start: i_co = ..., end: i_co | None = ...) -> NDArray[np.int_]: ... + @overload + def count(self: _CharArray[np.bytes_], sub: S_co, start: i_co = ..., end: i_co | None = ...) -> NDArray[np.int_]: ... + + # + def decode(self: _CharArray[np.bytes_], encoding: str | None = ..., errors: str | None = ...) -> _CharArray[np.str_]: ... + def encode(self: _CharArray[np.str_], encoding: str | None = ..., errors: str | None = ...) -> _CharArray[np.bytes_]: ... + + # + @overload + def endswith(self: _CharArray[np.str_], suffix: U_co, start: i_co = ..., end: i_co | None = ...) -> NDArray[np.bool]: ... + @overload + def endswith(self: _CharArray[np.bytes_], suffix: S_co, start: i_co = ..., end: i_co | None = ...) -> NDArray[np.bool]: ... + + # + def expandtabs(self, tabsize: i_co = ...) -> chararray[_Shape, _CharDType_co]: ... + + # + @overload + def find(self: _CharArray[np.str_], sub: U_co, start: i_co = ..., end: i_co | None = ...) -> NDArray[np.int_]: ... + @overload + def find(self: _CharArray[np.bytes_], sub: S_co, start: i_co = ..., end: i_co | None = ...) -> NDArray[np.int_]: ... + + # + @overload + def index(self: _CharArray[np.str_], sub: U_co, start: i_co = ..., end: i_co | None = ...) -> NDArray[np.int_]: ... + @overload + def index(self: _CharArray[np.bytes_], sub: S_co, start: i_co = ..., end: i_co | None = ...) -> NDArray[np.int_]: ... + + # + @overload + def join(self: _CharArray[np.str_], seq: U_co) -> _CharArray[np.str_]: ... + @overload + def join(self: _CharArray[np.bytes_], seq: S_co) -> _CharArray[np.bytes_]: ... + + # + @overload + def ljust(self: _CharArray[np.str_], width: i_co, fillchar: U_co = ...) -> _CharArray[np.str_]: ... + @overload + def ljust(self: _CharArray[np.bytes_], width: i_co, fillchar: S_co = ...) -> _CharArray[np.bytes_]: ... + + # + @overload + def lstrip(self: _CharArray[np.str_], chars: U_co | None = ...) -> _CharArray[np.str_]: ... + @overload + def lstrip(self: _CharArray[np.bytes_], chars: S_co | None = ...) -> _CharArray[np.bytes_]: ... + + # + @overload + def partition(self: _CharArray[np.str_], sep: U_co) -> _CharArray[np.str_]: ... + @overload + def partition(self: _CharArray[np.bytes_], sep: S_co) -> _CharArray[np.bytes_]: ... + + # + @overload + def replace(self: _CharArray[np.str_], old: U_co, new: U_co, count: i_co | None = ...) -> _CharArray[np.str_]: ... + @overload + def replace(self: _CharArray[np.bytes_], old: S_co, new: S_co, count: i_co | None = ...) -> _CharArray[np.bytes_]: ... + + # + @overload + def rfind(self: _CharArray[np.str_], sub: U_co, start: i_co = ..., end: i_co | None = ...) -> NDArray[np.int_]: ... + @overload + def rfind(self: _CharArray[np.bytes_], sub: S_co, start: i_co = ..., end: i_co | None = ...) -> NDArray[np.int_]: ... + + # + @overload + def rindex(self: _CharArray[np.str_], sub: U_co, start: i_co = ..., end: i_co | None = ...) -> NDArray[np.int_]: ... + @overload + def rindex(self: _CharArray[np.bytes_], sub: S_co, start: i_co = ..., end: i_co | None = ...) -> NDArray[np.int_]: ... + + # + @overload + def rjust(self: _CharArray[np.str_], width: i_co, fillchar: U_co = ...) -> _CharArray[np.str_]: ... + @overload + def rjust(self: _CharArray[np.bytes_], width: i_co, fillchar: S_co = ...) -> _CharArray[np.bytes_]: ... + + # + @overload + def rpartition(self: _CharArray[np.str_], sep: U_co) -> _CharArray[np.str_]: ... + @overload + def rpartition(self: _CharArray[np.bytes_], sep: S_co) -> _CharArray[np.bytes_]: ... + + # + @overload + def rsplit(self: _CharArray[np.str_], sep: U_co | None = ..., maxsplit: i_co | None = ...) -> NDArray[np.object_]: ... + @overload + def rsplit(self: _CharArray[np.bytes_], sep: S_co | None = ..., maxsplit: i_co | None = ...) -> NDArray[np.object_]: ... + + # + @overload + def rstrip(self: _CharArray[np.str_], chars: U_co | None = ...) -> _CharArray[np.str_]: ... + @overload + def rstrip(self: _CharArray[np.bytes_], chars: S_co | None = ...) -> _CharArray[np.bytes_]: ... + + # + @overload + def split(self: _CharArray[np.str_], sep: U_co | None = ..., maxsplit: i_co | None = ...) -> NDArray[np.object_]: ... + @overload + def split(self: _CharArray[np.bytes_], sep: S_co | None = ..., maxsplit: i_co | None = ...) -> NDArray[np.object_]: ... + + # + def splitlines(self, keepends: b_co | None = ...) -> NDArray[np.object_]: ... + + # + @overload + def startswith(self: _CharArray[np.str_], prefix: U_co, start: i_co = ..., end: i_co | None = ...) -> NDArray[np.bool]: ... + @overload + def startswith(self: _CharArray[np.bytes_], prefix: S_co, start: i_co = ..., end: i_co | None = ...) -> NDArray[np.bool]: ... + + # + @overload + def strip(self: _CharArray[np.str_], chars: U_co | None = ...) -> _CharArray[np.str_]: ... + @overload + def strip(self: _CharArray[np.bytes_], chars: S_co | None = ...) -> _CharArray[np.bytes_]: ... + + # + @overload + def translate(self: _CharArray[np.str_], table: U_co, deletechars: U_co | None = ...) -> _CharArray[np.str_]: ... + @overload + def translate(self: _CharArray[np.bytes_], table: S_co, deletechars: S_co | None = ...) -> _CharArray[np.bytes_]: ... + + # def zfill(self, width: i_co) -> chararray[_Shape, _CharDType_co]: ... def capitalize(self) -> chararray[_ShapeT_co, _CharDType_co]: ... def title(self) -> chararray[_ShapeT_co, _CharDType_co]: ... def swapcase(self) -> chararray[_ShapeT_co, _CharDType_co]: ... def lower(self) -> chararray[_ShapeT_co, _CharDType_co]: ... def upper(self) -> chararray[_ShapeT_co, _CharDType_co]: ... - def isalnum(self) -> ndarray[_ShapeT_co, dtype[np.bool]]: ... - def isalpha(self) -> ndarray[_ShapeT_co, dtype[np.bool]]: ... - def isdigit(self) -> ndarray[_ShapeT_co, dtype[np.bool]]: ... - def islower(self) -> ndarray[_ShapeT_co, dtype[np.bool]]: ... - def isspace(self) -> ndarray[_ShapeT_co, dtype[np.bool]]: ... - def istitle(self) -> ndarray[_ShapeT_co, dtype[np.bool]]: ... - def isupper(self) -> ndarray[_ShapeT_co, dtype[np.bool]]: ... - def isnumeric(self) -> ndarray[_ShapeT_co, dtype[np.bool]]: ... - def isdecimal(self) -> ndarray[_ShapeT_co, dtype[np.bool]]: ... + + # + def isalnum(self) -> np.ndarray[_ShapeT_co, np.dtype[np.bool]]: ... + def isalpha(self) -> np.ndarray[_ShapeT_co, np.dtype[np.bool]]: ... + def isdigit(self) -> np.ndarray[_ShapeT_co, np.dtype[np.bool]]: ... + def islower(self) -> np.ndarray[_ShapeT_co, np.dtype[np.bool]]: ... + def isspace(self) -> np.ndarray[_ShapeT_co, np.dtype[np.bool]]: ... + def istitle(self) -> np.ndarray[_ShapeT_co, np.dtype[np.bool]]: ... + def isupper(self) -> np.ndarray[_ShapeT_co, np.dtype[np.bool]]: ... + def isnumeric(self) -> np.ndarray[_ShapeT_co, np.dtype[np.bool]]: ... + def isdecimal(self) -> np.ndarray[_ShapeT_co, np.dtype[np.bool]]: ... # Comparison @overload @@ -477,36 +307,48 @@ def equal(x1: U_co, x2: U_co) -> NDArray[np.bool]: ... def equal(x1: S_co, x2: S_co) -> NDArray[np.bool]: ... @overload def equal(x1: T_co, x2: T_co) -> NDArray[np.bool]: ... + +# @overload def not_equal(x1: U_co, x2: U_co) -> NDArray[np.bool]: ... @overload def not_equal(x1: S_co, x2: S_co) -> NDArray[np.bool]: ... @overload def not_equal(x1: T_co, x2: T_co) -> NDArray[np.bool]: ... + +# @overload def greater_equal(x1: U_co, x2: U_co) -> NDArray[np.bool]: ... @overload def greater_equal(x1: S_co, x2: S_co) -> NDArray[np.bool]: ... @overload def greater_equal(x1: T_co, x2: T_co) -> NDArray[np.bool]: ... + +# @overload def less_equal(x1: U_co, x2: U_co) -> NDArray[np.bool]: ... @overload def less_equal(x1: S_co, x2: S_co) -> NDArray[np.bool]: ... @overload def less_equal(x1: T_co, x2: T_co) -> NDArray[np.bool]: ... + +# @overload def greater(x1: U_co, x2: U_co) -> NDArray[np.bool]: ... @overload def greater(x1: S_co, x2: S_co) -> NDArray[np.bool]: ... @overload def greater(x1: T_co, x2: T_co) -> NDArray[np.bool]: ... + +# @overload def less(x1: U_co, x2: U_co) -> NDArray[np.bool]: ... @overload def less(x1: S_co, x2: S_co) -> NDArray[np.bool]: ... @overload def less(x1: T_co, x2: T_co) -> NDArray[np.bool]: ... + +# @overload def add(x1: U_co, x2: U_co) -> NDArray[np.str_]: ... @overload @@ -515,6 +357,8 @@ def add(x1: S_co, x2: S_co) -> NDArray[np.bytes_]: ... def add(x1: _StringDTypeSupportsArray, x2: _StringDTypeSupportsArray) -> _StringDTypeArray: ... @overload def add(x1: T_co, x2: T_co) -> _StringDTypeOrUnicodeArray: ... + +# @overload def multiply(a: U_co, i: i_co) -> NDArray[np.str_]: ... @overload @@ -523,6 +367,8 @@ def multiply(a: S_co, i: i_co) -> NDArray[np.bytes_]: ... def multiply(a: _StringDTypeSupportsArray, i: i_co) -> _StringDTypeArray: ... @overload def multiply(a: T_co, i: i_co) -> _StringDTypeOrUnicodeArray: ... + +# @overload def mod(a: U_co, value: Any) -> NDArray[np.str_]: ... @overload @@ -531,257 +377,215 @@ def mod(a: S_co, value: Any) -> NDArray[np.bytes_]: ... def mod(a: _StringDTypeSupportsArray, value: Any) -> _StringDTypeArray: ... @overload def mod(a: T_co, value: Any) -> _StringDTypeOrUnicodeArray: ... + +# @overload -def capitalize(a: U_co) -> NDArray[str_]: ... +def capitalize(a: U_co) -> NDArray[np.str_]: ... @overload -def capitalize(a: S_co) -> NDArray[bytes_]: ... +def capitalize(a: S_co) -> NDArray[np.bytes_]: ... @overload def capitalize(a: _StringDTypeSupportsArray) -> _StringDTypeArray: ... @overload def capitalize(a: T_co) -> _StringDTypeOrUnicodeArray: ... + +# @overload -def center(a: U_co, width: i_co, fillchar: U_co = ...) -> NDArray[str_]: ... +def center(a: U_co, width: i_co, fillchar: U_co = ...) -> NDArray[np.str_]: ... @overload -def center(a: S_co, width: i_co, fillchar: S_co = ...) -> NDArray[bytes_]: ... +def center(a: S_co, width: i_co, fillchar: S_co = ...) -> NDArray[np.bytes_]: ... @overload def center(a: _StringDTypeSupportsArray, width: i_co, fillchar: _StringDTypeSupportsArray = ...) -> _StringDTypeArray: ... @overload def center(a: T_co, width: i_co, fillchar: T_co = ...) -> _StringDTypeOrUnicodeArray: ... -def decode( - a: S_co, - encoding: str | None = ..., - errors: str | None = ..., -) -> NDArray[str_]: ... -def encode( - a: U_co | T_co, - encoding: str | None = ..., - errors: str | None = ..., -) -> NDArray[bytes_]: ... + +# +def decode(a: S_co, encoding: str | None = ..., errors: str | None = ...) -> NDArray[np.str_]: ... +def encode(a: U_co | T_co, encoding: str | None = ..., errors: str | None = ...) -> NDArray[np.bytes_]: ... + +# @overload -def expandtabs(a: U_co, tabsize: i_co = ...) -> NDArray[str_]: ... +def expandtabs(a: U_co, tabsize: i_co = ...) -> NDArray[np.str_]: ... @overload -def expandtabs(a: S_co, tabsize: i_co = ...) -> NDArray[bytes_]: ... +def expandtabs(a: S_co, tabsize: i_co = ...) -> NDArray[np.bytes_]: ... @overload def expandtabs(a: _StringDTypeSupportsArray, tabsize: i_co = ...) -> _StringDTypeArray: ... @overload def expandtabs(a: T_co, tabsize: i_co = ...) -> _StringDTypeOrUnicodeArray: ... + +# @overload -def join(sep: U_co, seq: U_co) -> NDArray[str_]: ... +def join(sep: U_co, seq: U_co) -> NDArray[np.str_]: ... @overload -def join(sep: S_co, seq: S_co) -> NDArray[bytes_]: ... +def join(sep: S_co, seq: S_co) -> NDArray[np.bytes_]: ... @overload def join(sep: _StringDTypeSupportsArray, seq: _StringDTypeSupportsArray) -> _StringDTypeArray: ... @overload def join(sep: T_co, seq: T_co) -> _StringDTypeOrUnicodeArray: ... + +# @overload -def ljust(a: U_co, width: i_co, fillchar: U_co = ...) -> NDArray[str_]: ... +def ljust(a: U_co, width: i_co, fillchar: U_co = ...) -> NDArray[np.str_]: ... @overload -def ljust(a: S_co, width: i_co, fillchar: S_co = ...) -> NDArray[bytes_]: ... +def ljust(a: S_co, width: i_co, fillchar: S_co = ...) -> NDArray[np.bytes_]: ... @overload def ljust(a: _StringDTypeSupportsArray, width: i_co, fillchar: _StringDTypeSupportsArray = ...) -> _StringDTypeArray: ... @overload def ljust(a: T_co, width: i_co, fillchar: T_co = ...) -> _StringDTypeOrUnicodeArray: ... + +# @overload -def lower(a: U_co) -> NDArray[str_]: ... +def lower(a: U_co) -> NDArray[np.str_]: ... @overload -def lower(a: S_co) -> NDArray[bytes_]: ... +def lower(a: S_co) -> NDArray[np.bytes_]: ... @overload def lower(a: _StringDTypeSupportsArray) -> _StringDTypeArray: ... @overload def lower(a: T_co) -> _StringDTypeOrUnicodeArray: ... + +# @overload -def lstrip(a: U_co, chars: U_co | None = ...) -> NDArray[str_]: ... +def lstrip(a: U_co, chars: U_co | None = ...) -> NDArray[np.str_]: ... @overload -def lstrip(a: S_co, chars: S_co | None = ...) -> NDArray[bytes_]: ... +def lstrip(a: S_co, chars: S_co | None = ...) -> NDArray[np.bytes_]: ... @overload def lstrip(a: _StringDTypeSupportsArray, chars: _StringDTypeSupportsArray | None = ...) -> _StringDTypeArray: ... @overload def lstrip(a: T_co, chars: T_co | None = ...) -> _StringDTypeOrUnicodeArray: ... + +# @overload -def partition(a: U_co, sep: U_co) -> NDArray[str_]: ... +def partition(a: U_co, sep: U_co) -> NDArray[np.str_]: ... @overload -def partition(a: S_co, sep: S_co) -> NDArray[bytes_]: ... +def partition(a: S_co, sep: S_co) -> NDArray[np.bytes_]: ... @overload def partition(a: _StringDTypeSupportsArray, sep: _StringDTypeSupportsArray) -> _StringDTypeArray: ... @overload def partition(a: T_co, sep: T_co) -> _StringDTypeOrUnicodeArray: ... + +# @overload -def replace( - a: U_co, - old: U_co, - new: U_co, - count: i_co | None = ..., -) -> NDArray[str_]: ... +def replace(a: U_co, old: U_co, new: U_co, count: i_co | None = ...) -> NDArray[np.str_]: ... @overload -def replace( - a: S_co, - old: S_co, - new: S_co, - count: i_co | None = ..., -) -> NDArray[bytes_]: ... +def replace(a: S_co, old: S_co, new: S_co, count: i_co | None = ...) -> NDArray[np.bytes_]: ... @overload def replace( - a: _StringDTypeSupportsArray, - old: _StringDTypeSupportsArray, - new: _StringDTypeSupportsArray, - count: i_co = ..., + a: _StringDTypeSupportsArray, old: _StringDTypeSupportsArray, new: _StringDTypeSupportsArray, count: i_co = ... ) -> _StringDTypeArray: ... @overload -def replace( - a: T_co, - old: T_co, - new: T_co, - count: i_co = ..., -) -> _StringDTypeOrUnicodeArray: ... -@overload -def rjust( - a: U_co, - width: i_co, - fillchar: U_co = ..., -) -> NDArray[str_]: ... -@overload -def rjust( - a: S_co, - width: i_co, - fillchar: S_co = ..., -) -> NDArray[bytes_]: ... -@overload -def rjust( - a: _StringDTypeSupportsArray, - width: i_co, - fillchar: _StringDTypeSupportsArray = ..., -) -> _StringDTypeArray: ... +def replace(a: T_co, old: T_co, new: T_co, count: i_co = ...) -> _StringDTypeOrUnicodeArray: ... + +# +@overload +def rjust(a: U_co, width: i_co, fillchar: U_co = ...) -> NDArray[np.str_]: ... @overload -def rjust( - a: T_co, - width: i_co, - fillchar: T_co = ..., -) -> _StringDTypeOrUnicodeArray: ... +def rjust(a: S_co, width: i_co, fillchar: S_co = ...) -> NDArray[np.bytes_]: ... @overload -def rpartition(a: U_co, sep: U_co) -> NDArray[str_]: ... +def rjust(a: _StringDTypeSupportsArray, width: i_co, fillchar: _StringDTypeSupportsArray = ...) -> _StringDTypeArray: ... @overload -def rpartition(a: S_co, sep: S_co) -> NDArray[bytes_]: ... +def rjust(a: T_co, width: i_co, fillchar: T_co = ...) -> _StringDTypeOrUnicodeArray: ... + +# +@overload +def rpartition(a: U_co, sep: U_co) -> NDArray[np.str_]: ... +@overload +def rpartition(a: S_co, sep: S_co) -> NDArray[np.bytes_]: ... @overload def rpartition(a: _StringDTypeSupportsArray, sep: _StringDTypeSupportsArray) -> _StringDTypeArray: ... @overload def rpartition(a: T_co, sep: T_co) -> _StringDTypeOrUnicodeArray: ... + +# @overload -def rsplit( - a: U_co, - sep: U_co | None = ..., - maxsplit: i_co | None = ..., -) -> NDArray[object_]: ... +def rsplit(a: U_co, sep: U_co | None = ..., maxsplit: i_co | None = ...) -> NDArray[np.object_]: ... @overload -def rsplit( - a: S_co, - sep: S_co | None = ..., - maxsplit: i_co | None = ..., -) -> NDArray[object_]: ... +def rsplit(a: S_co, sep: S_co | None = ..., maxsplit: i_co | None = ...) -> NDArray[np.object_]: ... @overload def rsplit( - a: _StringDTypeSupportsArray, - sep: _StringDTypeSupportsArray | None = ..., - maxsplit: i_co | None = ..., -) -> NDArray[object_]: ... + a: _StringDTypeSupportsArray, sep: _StringDTypeSupportsArray | None = ..., maxsplit: i_co | None = ... +) -> NDArray[np.object_]: ... @overload -def rsplit( - a: T_co, - sep: T_co | None = ..., - maxsplit: i_co | None = ..., -) -> NDArray[object_]: ... +def rsplit(a: T_co, sep: T_co | None = ..., maxsplit: i_co | None = ...) -> NDArray[np.object_]: ... + +# @overload -def rstrip(a: U_co, chars: U_co | None = ...) -> NDArray[str_]: ... +def rstrip(a: U_co, chars: U_co | None = ...) -> NDArray[np.str_]: ... @overload -def rstrip(a: S_co, chars: S_co | None = ...) -> NDArray[bytes_]: ... +def rstrip(a: S_co, chars: S_co | None = ...) -> NDArray[np.bytes_]: ... @overload def rstrip(a: _StringDTypeSupportsArray, chars: _StringDTypeSupportsArray | None = ...) -> _StringDTypeArray: ... @overload def rstrip(a: T_co, chars: T_co | None = ...) -> _StringDTypeOrUnicodeArray: ... + +# @overload -def split( - a: U_co, - sep: U_co | None = ..., - maxsplit: i_co | None = ..., -) -> NDArray[object_]: ... +def split(a: U_co, sep: U_co | None = ..., maxsplit: i_co | None = ...) -> NDArray[np.object_]: ... @overload -def split( - a: S_co, - sep: S_co | None = ..., - maxsplit: i_co | None = ..., -) -> NDArray[object_]: ... +def split(a: S_co, sep: S_co | None = ..., maxsplit: i_co | None = ...) -> NDArray[np.object_]: ... @overload def split( - a: _StringDTypeSupportsArray, - sep: _StringDTypeSupportsArray | None = ..., - maxsplit: i_co | None = ..., -) -> NDArray[object_]: ... + a: _StringDTypeSupportsArray, sep: _StringDTypeSupportsArray | None = ..., maxsplit: i_co | None = ... +) -> NDArray[np.object_]: ... @overload -def split( - a: T_co, - sep: T_co | None = ..., - maxsplit: i_co | None = ..., -) -> NDArray[object_]: ... +def split(a: T_co, sep: T_co | None = ..., maxsplit: i_co | None = ...) -> NDArray[np.object_]: ... + +# def splitlines(a: UST_co, keepends: b_co | None = ...) -> NDArray[np.object_]: ... + +# @overload -def strip(a: U_co, chars: U_co | None = ...) -> NDArray[str_]: ... +def strip(a: U_co, chars: U_co | None = ...) -> NDArray[np.str_]: ... @overload -def strip(a: S_co, chars: S_co | None = ...) -> NDArray[bytes_]: ... +def strip(a: S_co, chars: S_co | None = ...) -> NDArray[np.bytes_]: ... @overload def strip(a: _StringDTypeSupportsArray, chars: _StringDTypeSupportsArray | None = ...) -> _StringDTypeArray: ... @overload def strip(a: T_co, chars: T_co | None = ...) -> _StringDTypeOrUnicodeArray: ... + +# @overload -def swapcase(a: U_co) -> NDArray[str_]: ... +def swapcase(a: U_co) -> NDArray[np.str_]: ... @overload -def swapcase(a: S_co) -> NDArray[bytes_]: ... +def swapcase(a: S_co) -> NDArray[np.bytes_]: ... @overload def swapcase(a: _StringDTypeSupportsArray) -> _StringDTypeArray: ... @overload def swapcase(a: T_co) -> _StringDTypeOrUnicodeArray: ... + +# @overload -def title(a: U_co) -> NDArray[str_]: ... +def title(a: U_co) -> NDArray[np.str_]: ... @overload -def title(a: S_co) -> NDArray[bytes_]: ... +def title(a: S_co) -> NDArray[np.bytes_]: ... @overload def title(a: _StringDTypeSupportsArray) -> _StringDTypeArray: ... @overload def title(a: T_co) -> _StringDTypeOrUnicodeArray: ... + +# @overload -def translate( - a: U_co, - table: str, - deletechars: str | None = ..., -) -> NDArray[str_]: ... -@overload -def translate( - a: S_co, - table: str, - deletechars: str | None = ..., -) -> NDArray[bytes_]: ... -@overload -def translate( - a: _StringDTypeSupportsArray, - table: str, - deletechars: str | None = ..., -) -> _StringDTypeArray: ... +def translate(a: U_co, table: str, deletechars: str | None = ...) -> NDArray[np.str_]: ... +@overload +def translate(a: S_co, table: str, deletechars: str | None = ...) -> NDArray[np.bytes_]: ... +@overload +def translate(a: _StringDTypeSupportsArray, table: str, deletechars: str | None = ...) -> _StringDTypeArray: ... @overload -def translate( - a: T_co, - table: str, - deletechars: str | None = ..., -) -> _StringDTypeOrUnicodeArray: ... +def translate(a: T_co, table: str, deletechars: str | None = ...) -> _StringDTypeOrUnicodeArray: ... + +# @overload -def upper(a: U_co) -> NDArray[str_]: ... +def upper(a: U_co) -> NDArray[np.str_]: ... @overload -def upper(a: S_co) -> NDArray[bytes_]: ... +def upper(a: S_co) -> NDArray[np.bytes_]: ... @overload def upper(a: _StringDTypeSupportsArray) -> _StringDTypeArray: ... @overload def upper(a: T_co) -> _StringDTypeOrUnicodeArray: ... + +# @overload -def zfill(a: U_co, width: i_co) -> NDArray[str_]: ... +def zfill(a: U_co, width: i_co) -> NDArray[np.str_]: ... @overload -def zfill(a: S_co, width: i_co) -> NDArray[bytes_]: ... +def zfill(a: S_co, width: i_co) -> NDArray[np.bytes_]: ... @overload def zfill(a: _StringDTypeSupportsArray, width: i_co) -> _StringDTypeArray: ... @overload @@ -789,89 +593,37 @@ def zfill(a: T_co, width: i_co) -> _StringDTypeOrUnicodeArray: ... # String information @overload -def count( - a: U_co, - sub: U_co, - start: i_co = ..., - end: i_co | None = ..., -) -> NDArray[int_]: ... -@overload -def count( - a: S_co, - sub: S_co, - start: i_co = ..., - end: i_co | None = ..., -) -> NDArray[int_]: ... -@overload -def count( - a: T_co, - sub: T_co, - start: i_co = ..., - end: i_co | None = ..., -) -> NDArray[np.int_]: ... -@overload -def endswith( - a: U_co, - suffix: U_co, - start: i_co = ..., - end: i_co | None = ..., -) -> NDArray[np.bool]: ... -@overload -def endswith( - a: S_co, - suffix: S_co, - start: i_co = ..., - end: i_co | None = ..., -) -> NDArray[np.bool]: ... -@overload -def endswith( - a: T_co, - suffix: T_co, - start: i_co = ..., - end: i_co | None = ..., -) -> NDArray[np.bool]: ... -@overload -def find( - a: U_co, - sub: U_co, - start: i_co = ..., - end: i_co | None = ..., -) -> NDArray[int_]: ... -@overload -def find( - a: S_co, - sub: S_co, - start: i_co = ..., - end: i_co | None = ..., -) -> NDArray[int_]: ... -@overload -def find( - a: T_co, - sub: T_co, - start: i_co = ..., - end: i_co | None = ..., -) -> NDArray[np.int_]: ... -@overload -def index( - a: U_co, - sub: U_co, - start: i_co = ..., - end: i_co | None = ..., -) -> NDArray[int_]: ... -@overload -def index( - a: S_co, - sub: S_co, - start: i_co = ..., - end: i_co | None = ..., -) -> NDArray[int_]: ... -@overload -def index( - a: T_co, - sub: T_co, - start: i_co = ..., - end: i_co | None = ..., -) -> NDArray[np.int_]: ... +def count(a: U_co, sub: U_co, start: i_co = ..., end: i_co | None = ...) -> NDArray[np.int_]: ... +@overload +def count(a: S_co, sub: S_co, start: i_co = ..., end: i_co | None = ...) -> NDArray[np.int_]: ... +@overload +def count(a: T_co, sub: T_co, start: i_co = ..., end: i_co | None = ...) -> NDArray[np.int_]: ... + +# +@overload +def endswith(a: U_co, suffix: U_co, start: i_co = ..., end: i_co | None = ...) -> NDArray[np.bool]: ... +@overload +def endswith(a: S_co, suffix: S_co, start: i_co = ..., end: i_co | None = ...) -> NDArray[np.bool]: ... +@overload +def endswith(a: T_co, suffix: T_co, start: i_co = ..., end: i_co | None = ...) -> NDArray[np.bool]: ... + +# +@overload +def find(a: U_co, sub: U_co, start: i_co = ..., end: i_co | None = ...) -> NDArray[np.int_]: ... +@overload +def find(a: S_co, sub: S_co, start: i_co = ..., end: i_co | None = ...) -> NDArray[np.int_]: ... +@overload +def find(a: T_co, sub: T_co, start: i_co = ..., end: i_co | None = ...) -> NDArray[np.int_]: ... + +# +@overload +def index(a: U_co, sub: U_co, start: i_co = ..., end: i_co | None = ...) -> NDArray[np.int_]: ... +@overload +def index(a: S_co, sub: S_co, start: i_co = ..., end: i_co | None = ...) -> NDArray[np.int_]: ... +@overload +def index(a: T_co, sub: T_co, start: i_co = ..., end: i_co | None = ...) -> NDArray[np.int_]: ... + +# def isalpha(a: UST_co) -> NDArray[np.bool]: ... def isalnum(a: UST_co) -> NDArray[np.bool]: ... def isdecimal(a: U_co | T_co) -> NDArray[np.bool]: ... @@ -881,131 +633,96 @@ def isnumeric(a: U_co | T_co) -> NDArray[np.bool]: ... def isspace(a: UST_co) -> NDArray[np.bool]: ... def istitle(a: UST_co) -> NDArray[np.bool]: ... def isupper(a: UST_co) -> NDArray[np.bool]: ... + +# +@overload +def rfind(a: U_co, sub: U_co, start: i_co = ..., end: i_co | None = ...) -> NDArray[np.int_]: ... +@overload +def rfind(a: S_co, sub: S_co, start: i_co = ..., end: i_co | None = ...) -> NDArray[np.int_]: ... @overload -def rfind( - a: U_co, - sub: U_co, - start: i_co = ..., - end: i_co | None = ..., -) -> NDArray[int_]: ... -@overload -def rfind( - a: S_co, - sub: S_co, - start: i_co = ..., - end: i_co | None = ..., -) -> NDArray[int_]: ... -@overload -def rfind( - a: T_co, - sub: T_co, - start: i_co = ..., - end: i_co | None = ..., -) -> NDArray[np.int_]: ... -@overload -def rindex( - a: U_co, - sub: U_co, - start: i_co = ..., - end: i_co | None = ..., -) -> NDArray[int_]: ... -@overload -def rindex( - a: S_co, - sub: S_co, - start: i_co = ..., - end: i_co | None = ..., -) -> NDArray[int_]: ... -@overload -def rindex( - a: T_co, - sub: T_co, - start: i_co = ..., - end: i_co | None = ..., -) -> NDArray[np.int_]: ... -@overload -def startswith( - a: U_co, - prefix: U_co, - start: i_co = ..., - end: i_co | None = ..., -) -> NDArray[np.bool]: ... -@overload -def startswith( - a: S_co, - prefix: S_co, - start: i_co = ..., - end: i_co | None = ..., -) -> NDArray[np.bool]: ... -@overload -def startswith( - a: T_co, - suffix: T_co, - start: i_co = ..., - end: i_co | None = ..., -) -> NDArray[np.bool]: ... -def str_len(A: UST_co) -> NDArray[int_]: ... +def rfind(a: T_co, sub: T_co, start: i_co = ..., end: i_co | None = ...) -> NDArray[np.int_]: ... + +# +@overload +def rindex(a: U_co, sub: U_co, start: i_co = ..., end: i_co | None = ...) -> NDArray[np.int_]: ... +@overload +def rindex(a: S_co, sub: S_co, start: i_co = ..., end: i_co | None = ...) -> NDArray[np.int_]: ... +@overload +def rindex(a: T_co, sub: T_co, start: i_co = ..., end: i_co | None = ...) -> NDArray[np.int_]: ... + +# +@overload +def startswith(a: U_co, prefix: U_co, start: i_co = ..., end: i_co | None = ...) -> NDArray[np.bool]: ... +@overload +def startswith(a: S_co, prefix: S_co, start: i_co = ..., end: i_co | None = ...) -> NDArray[np.bool]: ... +@overload +def startswith(a: T_co, suffix: T_co, start: i_co = ..., end: i_co | None = ...) -> NDArray[np.bool]: ... + +# +def str_len(A: UST_co) -> NDArray[np.int_]: ... # Overload 1 and 2: str- or bytes-based array-likes -# overload 3: arbitrary object with unicode=False (-> bytes_) -# overload 4: arbitrary object with unicode=True (-> str_) +# overload 3: arbitrary object with unicode=False (-> np.bytes_) +# overload 4: arbitrary object with unicode=True (-> np.str_) @overload def array( obj: U_co, itemsize: int | None = ..., copy: bool = ..., unicode: L[False] = ..., - order: _OrderKACF = ..., -) -> _CharArray[str_]: ... + order: np._OrderKACF = ..., +) -> _CharArray[np.str_]: ... @overload def array( obj: S_co, itemsize: int | None = ..., copy: bool = ..., unicode: L[False] = ..., - order: _OrderKACF = ..., -) -> _CharArray[bytes_]: ... + order: np._OrderKACF = ..., +) -> _CharArray[np.bytes_]: ... @overload def array( obj: object, itemsize: int | None = ..., copy: bool = ..., unicode: L[False] = ..., - order: _OrderKACF = ..., -) -> _CharArray[bytes_]: ... + order: np._OrderKACF = ..., +) -> _CharArray[np.bytes_]: ... @overload def array( obj: object, itemsize: int | None = ..., copy: bool = ..., unicode: L[True] = ..., - order: _OrderKACF = ..., -) -> _CharArray[str_]: ... + order: np._OrderKACF = ..., +) -> _CharArray[np.str_]: ... + +# @overload def asarray( obj: U_co, itemsize: int | None = ..., unicode: L[False] = ..., - order: _OrderKACF = ..., -) -> _CharArray[str_]: ... + order: np._OrderKACF = ..., +) -> _CharArray[np.str_]: ... @overload def asarray( obj: S_co, itemsize: int | None = ..., unicode: L[False] = ..., - order: _OrderKACF = ..., -) -> _CharArray[bytes_]: ... + order: np._OrderKACF = ..., +) -> _CharArray[np.bytes_]: ... @overload def asarray( obj: object, itemsize: int | None = ..., unicode: L[False] = ..., - order: _OrderKACF = ..., -) -> _CharArray[bytes_]: ... + order: np._OrderKACF = ..., +) -> _CharArray[np.bytes_]: ... @overload def asarray( obj: object, itemsize: int | None = ..., unicode: L[True] = ..., - order: _OrderKACF = ..., -) -> _CharArray[str_]: ... + order: np._OrderKACF = ..., +) -> _CharArray[np.str_]: ... diff --git a/src/numpy-stubs/_core/einsumfunc.pyi b/src/numpy-stubs/_core/einsumfunc.pyi index 344399ea..812e2533 100644 --- a/src/numpy-stubs/_core/einsumfunc.pyi +++ b/src/numpy-stubs/_core/einsumfunc.pyi @@ -2,7 +2,6 @@ from collections.abc import Sequence from typing import Any, Literal, TypeAlias, TypeVar, overload import numpy as np -from numpy import _OrderKACF, number from numpy._typing import ( NDArray, _ArrayLikeBool_co, @@ -22,10 +21,7 @@ from numpy._typing import ( __all__ = ["einsum", "einsum_path"] -_ArrayType = TypeVar( - "_ArrayType", - bound=NDArray[np.bool | number[Any]], -) +_ArrayT = TypeVar("_ArrayT", bound=NDArray[np.bool | np.number[Any]]) _OptimizeKind: TypeAlias = bool | Literal["greedy", "optimal"] | Sequence[Any] | None _CastingSafe: TypeAlias = Literal["no", "equiv", "safe", "same_kind"] @@ -44,7 +40,7 @@ def einsum( *operands: _ArrayLikeBool_co, out: None = ..., dtype: _DTypeLikeBool | None = ..., - order: _OrderKACF = ..., + order: np._OrderKACF = ..., casting: _CastingSafe = ..., optimize: _OptimizeKind = ..., ) -> Any: ... @@ -55,7 +51,7 @@ def einsum( *operands: _ArrayLikeUInt_co, out: None = ..., dtype: _DTypeLikeUInt | None = ..., - order: _OrderKACF = ..., + order: np._OrderKACF = ..., casting: _CastingSafe = ..., optimize: _OptimizeKind = ..., ) -> Any: ... @@ -66,7 +62,7 @@ def einsum( *operands: _ArrayLikeInt_co, out: None = ..., dtype: _DTypeLikeInt | None = ..., - order: _OrderKACF = ..., + order: np._OrderKACF = ..., casting: _CastingSafe = ..., optimize: _OptimizeKind = ..., ) -> Any: ... @@ -77,7 +73,7 @@ def einsum( *operands: _ArrayLikeFloat_co, out: None = ..., dtype: _DTypeLikeFloat | None = ..., - order: _OrderKACF = ..., + order: np._OrderKACF = ..., casting: _CastingSafe = ..., optimize: _OptimizeKind = ..., ) -> Any: ... @@ -88,7 +84,7 @@ def einsum( *operands: _ArrayLikeComplex_co, out: None = ..., dtype: _DTypeLikeComplex | None = ..., - order: _OrderKACF = ..., + order: np._OrderKACF = ..., casting: _CastingSafe = ..., optimize: _OptimizeKind = ..., ) -> Any: ... @@ -100,7 +96,7 @@ def einsum( casting: _CastingUnsafe, dtype: _DTypeLikeComplex_co | None = ..., out: None = ..., - order: _OrderKACF = ..., + order: np._OrderKACF = ..., optimize: _OptimizeKind = ..., ) -> Any: ... @overload @@ -108,23 +104,23 @@ def einsum( subscripts: str | _ArrayLikeInt_co, /, *operands: _ArrayLikeComplex_co, - out: _ArrayType, + out: _ArrayT, dtype: _DTypeLikeComplex_co | None = ..., - order: _OrderKACF = ..., + order: np._OrderKACF = ..., casting: _CastingSafe = ..., optimize: _OptimizeKind = ..., -) -> _ArrayType: ... +) -> _ArrayT: ... @overload def einsum( subscripts: str | _ArrayLikeInt_co, /, *operands: Any, - out: _ArrayType, + out: _ArrayT, casting: _CastingUnsafe, dtype: _DTypeLikeComplex_co | None = ..., - order: _OrderKACF = ..., + order: np._OrderKACF = ..., optimize: _OptimizeKind = ..., -) -> _ArrayType: ... +) -> _ArrayT: ... @overload def einsum( subscripts: str | _ArrayLikeInt_co, @@ -132,7 +128,7 @@ def einsum( *operands: _ArrayLikeObject_co, out: None = ..., dtype: _DTypeLikeObject | None = ..., - order: _OrderKACF = ..., + order: np._OrderKACF = ..., casting: _CastingSafe = ..., optimize: _OptimizeKind = ..., ) -> Any: ... @@ -144,7 +140,7 @@ def einsum( casting: _CastingUnsafe, dtype: _DTypeLikeObject | None = ..., out: None = ..., - order: _OrderKACF = ..., + order: np._OrderKACF = ..., optimize: _OptimizeKind = ..., ) -> Any: ... @overload @@ -152,23 +148,23 @@ def einsum( subscripts: str | _ArrayLikeInt_co, /, *operands: _ArrayLikeObject_co, - out: _ArrayType, + out: _ArrayT, dtype: _DTypeLikeObject | None = ..., - order: _OrderKACF = ..., + order: np._OrderKACF = ..., casting: _CastingSafe = ..., optimize: _OptimizeKind = ..., -) -> _ArrayType: ... +) -> _ArrayT: ... @overload def einsum( subscripts: str | _ArrayLikeInt_co, /, *operands: Any, - out: _ArrayType, + out: _ArrayT, casting: _CastingUnsafe, dtype: _DTypeLikeObject | None = ..., - order: _OrderKACF = ..., + order: np._OrderKACF = ..., optimize: _OptimizeKind = ..., -) -> _ArrayType: ... +) -> _ArrayT: ... # NOTE: `einsum_call` is a hidden kwarg unavailable for public use. # It is therefore excluded from the signatures below. diff --git a/src/numpy-stubs/_core/fromnumeric.pyi b/src/numpy-stubs/_core/fromnumeric.pyi index 0dd79088..089169e6 100644 --- a/src/numpy-stubs/_core/fromnumeric.pyi +++ b/src/numpy-stubs/_core/fromnumeric.pyi @@ -1,40 +1,8 @@ from collections.abc import Sequence -from typing import ( - Any, - Literal, - Never, - NoReturn, - Protocol, - SupportsIndex, - TypeAlias, - TypeVar, - overload, - type_check_only, -) -from typing_extensions import deprecated +from typing import Any, Literal, NoReturn, Protocol, SupportsIndex, TypeAlias, TypeVar, overload, type_check_only +from typing_extensions import Never, deprecated import numpy as np -from numpy import ( - _AnyShapeType, - _CastingKind, - _ModeKind, - _OrderACF, - _OrderKACF, - _PartitionKind, - _SortKind, - _SortSide, - complexfloating, - float16, - floating, - generic, - int64, - int_, - intp, - number, - object_, - timedelta64, - uint64, -) from numpy._typing import ( ArrayLike, DTypeLike, @@ -104,24 +72,24 @@ __all__ = [ "var", ] -_SCT = TypeVar("_SCT", bound=generic) -_SCT_uifcO = TypeVar("_SCT_uifcO", bound=number[Any] | object_) -_ArrayType = TypeVar("_ArrayType", bound=np.ndarray[Any, Any]) -_SizeType = TypeVar("_SizeType", bound=int) -_ShapeType = TypeVar("_ShapeType", bound=tuple[int, ...]) -_ShapeType_co = TypeVar("_ShapeType_co", bound=tuple[int, ...], covariant=True) +_T = TypeVar("_T") +_SCT = TypeVar("_SCT", bound=np.generic) +_SCT_uifcO = TypeVar("_SCT_uifcO", bound=np.number | np.object_) +_ArrayT = TypeVar("_ArrayT", bound=np.ndarray[Any, Any]) +_SizeT = TypeVar("_SizeT", bound=int) +_ShapeT = TypeVar("_ShapeT", bound=tuple[int, ...]) +_ShapeT_co = TypeVar("_ShapeT_co", bound=tuple[int, ...], covariant=True) @type_check_only -class _SupportsShape(Protocol[_ShapeType_co]): +class _SupportsShape(Protocol[_ShapeT_co]): # NOTE: it matters that `self` is positional only @property - def shape(self, /) -> _ShapeType_co: ... + def shape(self, /) -> _ShapeT_co: ... # a "sequence" that isn't a string, bytes, bytearray, or memoryview -_T = TypeVar("_T") _PyArray: TypeAlias = list[_T] | tuple[_T, ...] # `int` also covers `bool` -_PyScalar: TypeAlias = int | float | complex | bytes | str +_PyScalar: TypeAlias = complex | bytes | str @overload def take( @@ -129,7 +97,7 @@ def take( indices: _IntLike_co, axis: None = ..., out: None = ..., - mode: _ModeKind = ..., + mode: np._ModeKind = ..., ) -> _SCT: ... @overload def take( @@ -137,7 +105,7 @@ def take( indices: _IntLike_co, axis: SupportsIndex | None = ..., out: None = ..., - mode: _ModeKind = ..., + mode: np._ModeKind = ..., ) -> Any: ... @overload def take( @@ -145,7 +113,7 @@ def take( indices: _ArrayLikeInt_co, axis: SupportsIndex | None = ..., out: None = ..., - mode: _ModeKind = ..., + mode: np._ModeKind = ..., ) -> NDArray[_SCT]: ... @overload def take( @@ -153,40 +121,42 @@ def take( indices: _ArrayLikeInt_co, axis: SupportsIndex | None = ..., out: None = ..., - mode: _ModeKind = ..., + mode: np._ModeKind = ..., ) -> NDArray[Any]: ... @overload def take( a: ArrayLike, indices: _ArrayLikeInt_co, axis: SupportsIndex | None = ..., - out: _ArrayType = ..., - mode: _ModeKind = ..., -) -> _ArrayType: ... + out: _ArrayT = ..., + mode: np._ModeKind = ..., +) -> _ArrayT: ... + +# @overload def reshape( # shape: index a: _ArrayLike[_SCT], /, shape: SupportsIndex, - order: _OrderACF = "C", + order: np._OrderACF = "C", *, copy: bool | None = None, ) -> np.ndarray[tuple[int], np.dtype[_SCT]]: ... @overload -def reshape( # shape: (int, ...) @ _AnyShapeType +def reshape( # shape: (int, ...) @ np._AnyShapeT a: _ArrayLike[_SCT], /, - shape: _AnyShapeType, - order: _OrderACF = "C", + shape: np._AnyShapeT, + order: np._OrderACF = "C", *, copy: bool | None = None, -) -> np.ndarray[_AnyShapeType, np.dtype[_SCT]]: ... +) -> np.ndarray[np._AnyShapeT, np.dtype[_SCT]]: ... @overload # shape: Sequence[index] def reshape( a: _ArrayLike[_SCT], /, shape: Sequence[SupportsIndex], - order: _OrderACF = "C", + order: np._OrderACF = "C", *, copy: bool | None = None, ) -> NDArray[_SCT]: ... @@ -195,113 +165,86 @@ def reshape( a: ArrayLike, /, shape: SupportsIndex, - order: _OrderACF = "C", + order: np._OrderACF = "C", *, copy: bool | None = None, ) -> np.ndarray[tuple[int], np.dtype[Any]]: ... @overload -def reshape( # shape: (int, ...) @ _AnyShapeType +def reshape( # shape: (int, ...) @ np._AnyShapeT a: ArrayLike, /, - shape: _AnyShapeType, - order: _OrderACF = "C", + shape: np._AnyShapeT, + order: np._OrderACF = "C", *, copy: bool | None = None, -) -> np.ndarray[_AnyShapeType, np.dtype[Any]]: ... +) -> np.ndarray[np._AnyShapeT, np.dtype[Any]]: ... @overload # shape: Sequence[index] def reshape( a: ArrayLike, /, shape: Sequence[SupportsIndex], - order: _OrderACF = "C", + order: np._OrderACF = "C", *, copy: bool | None = None, ) -> NDArray[Any]: ... @overload @deprecated( - "`newshape` keyword argument is deprecated, use `shape=...` or pass shape positionally instead. (deprecated in NumPy 2.1)", + "`newshape` keyword argument is deprecated, use `shape=...` or pass shape positionally instead. (deprecated in NumPy 2.1)" ) def reshape( a: ArrayLike, /, shape: None = None, - order: _OrderACF = "C", + order: np._OrderACF = "C", *, newshape: _ShapeLike, copy: bool | None = None, ) -> NDArray[Any]: ... + +# @overload -def choose( - a: _IntLike_co, - choices: ArrayLike, - out: None = ..., - mode: _ModeKind = ..., -) -> Any: ... +def choose(a: _IntLike_co, choices: ArrayLike, out: None = ..., mode: np._ModeKind = ...) -> Any: ... @overload -def choose( - a: _ArrayLikeInt_co, - choices: _ArrayLike[_SCT], - out: None = ..., - mode: _ModeKind = ..., -) -> NDArray[_SCT]: ... +def choose(a: _ArrayLikeInt_co, choices: _ArrayLike[_SCT], out: None = ..., mode: np._ModeKind = ...) -> NDArray[_SCT]: ... @overload -def choose( - a: _ArrayLikeInt_co, - choices: ArrayLike, - out: None = ..., - mode: _ModeKind = ..., -) -> NDArray[Any]: ... +def choose(a: _ArrayLikeInt_co, choices: ArrayLike, out: None = ..., mode: np._ModeKind = ...) -> NDArray[Any]: ... @overload -def choose( - a: _ArrayLikeInt_co, - choices: ArrayLike, - out: _ArrayType = ..., - mode: _ModeKind = ..., -) -> _ArrayType: ... +def choose(a: _ArrayLikeInt_co, choices: ArrayLike, out: _ArrayT = ..., mode: np._ModeKind = ...) -> _ArrayT: ... + +# @overload -def repeat( - a: _ArrayLike[_SCT], - repeats: _ArrayLikeInt_co, - axis: SupportsIndex | None = ..., -) -> NDArray[_SCT]: ... +def repeat(a: _ArrayLike[_SCT], repeats: _ArrayLikeInt_co, axis: SupportsIndex | None = ...) -> NDArray[_SCT]: ... @overload -def repeat( - a: ArrayLike, - repeats: _ArrayLikeInt_co, - axis: SupportsIndex | None = ..., -) -> NDArray[Any]: ... -def put( - a: NDArray[Any], - ind: _ArrayLikeInt_co, - v: ArrayLike, - mode: _ModeKind = ..., -) -> None: ... +def repeat(a: ArrayLike, repeats: _ArrayLikeInt_co, axis: SupportsIndex | None = ...) -> NDArray[Any]: ... + +# +def put(a: NDArray[Any], ind: _ArrayLikeInt_co, v: ArrayLike, mode: np._ModeKind = ...) -> None: ... + +# @overload -def swapaxes( - a: _ArrayLike[_SCT], - axis1: SupportsIndex, - axis2: SupportsIndex, -) -> NDArray[_SCT]: ... +def swapaxes(a: _ArrayLike[_SCT], axis1: SupportsIndex, axis2: SupportsIndex) -> NDArray[_SCT]: ... @overload -def swapaxes( - a: ArrayLike, - axis1: SupportsIndex, - axis2: SupportsIndex, -) -> NDArray[Any]: ... +def swapaxes(a: ArrayLike, axis1: SupportsIndex, axis2: SupportsIndex) -> NDArray[Any]: ... + +# @overload def transpose(a: _ArrayLike[_SCT], axes: _ShapeLike | None = ...) -> NDArray[_SCT]: ... @overload def transpose(a: ArrayLike, axes: _ShapeLike | None = ...) -> NDArray[Any]: ... + +# @overload def matrix_transpose(x: _ArrayLike[_SCT]) -> NDArray[_SCT]: ... @overload def matrix_transpose(x: ArrayLike) -> NDArray[Any]: ... + +# @overload def partition( a: _ArrayLike[_SCT], kth: _ArrayLikeInt_co, axis: SupportsIndex | None = ..., - kind: _PartitionKind = ..., + kind: np._PartitionKind = ..., order: str | Sequence[str] | None = ..., ) -> NDArray[_SCT]: ... @overload @@ -309,21 +252,23 @@ def partition( a: ArrayLike, kth: _ArrayLikeInt_co, axis: SupportsIndex | None = ..., - kind: _PartitionKind = ..., + kind: np._PartitionKind = ..., order: str | Sequence[str] | None = ..., ) -> NDArray[Any]: ... def argpartition( a: ArrayLike, kth: _ArrayLikeInt_co, axis: SupportsIndex | None = ..., - kind: _PartitionKind = ..., + kind: np._PartitionKind = ..., order: str | Sequence[str] | None = ..., -) -> NDArray[intp]: ... +) -> NDArray[np.int_]: ... + +# @overload def sort( a: _ArrayLike[_SCT], axis: SupportsIndex | None = ..., - kind: _SortKind | None = ..., + kind: np._SortKind | None = ..., order: str | Sequence[str] | None = ..., *, stable: bool | None = ..., @@ -332,19 +277,23 @@ def sort( def sort( a: ArrayLike, axis: SupportsIndex | None = ..., - kind: _SortKind | None = ..., + kind: np._SortKind | None = ..., order: str | Sequence[str] | None = ..., *, stable: bool | None = ..., ) -> NDArray[Any]: ... + +# def argsort( a: ArrayLike, axis: SupportsIndex | None = ..., - kind: _SortKind | None = ..., + kind: np._SortKind | None = ..., order: str | Sequence[str] | None = ..., *, stable: bool | None = ..., -) -> NDArray[intp]: ... +) -> NDArray[np.int_]: ... + +# @overload def argmax( a: ArrayLike, @@ -352,7 +301,7 @@ def argmax( out: None = ..., *, keepdims: Literal[False] = ..., -) -> intp: ... +) -> np.int_: ... @overload def argmax( a: ArrayLike, @@ -365,10 +314,12 @@ def argmax( def argmax( a: ArrayLike, axis: SupportsIndex | None = ..., - out: _ArrayType = ..., + out: _ArrayT = ..., *, keepdims: bool = ..., -) -> _ArrayType: ... +) -> _ArrayT: ... + +# @overload def argmin( a: ArrayLike, @@ -376,7 +327,7 @@ def argmin( out: None = ..., *, keepdims: Literal[False] = ..., -) -> intp: ... +) -> np.int_: ... @overload def argmin( a: ArrayLike, @@ -389,57 +340,54 @@ def argmin( def argmin( a: ArrayLike, axis: SupportsIndex | None = ..., - out: _ArrayType = ..., + out: _ArrayT = ..., *, keepdims: bool = ..., -) -> _ArrayType: ... +) -> _ArrayT: ... + +# @overload def searchsorted( a: ArrayLike, v: _ScalarLike_co, - side: _SortSide = ..., + side: np._SortSide = ..., sorter: _ArrayLikeInt_co | None = ..., # 1D int array -) -> intp: ... +) -> np.int_: ... @overload def searchsorted( a: ArrayLike, v: ArrayLike, - side: _SortSide = ..., + side: np._SortSide = ..., sorter: _ArrayLikeInt_co | None = ..., # 1D int array -) -> NDArray[intp]: ... +) -> NDArray[np.int_]: ... # unlike `reshape`, `resize` only accepts positive integers, so literal ints can be used @overload -def resize(a: _ArrayLike[_SCT], new_shape: _SizeType) -> np.ndarray[tuple[_SizeType], np.dtype[_SCT]]: ... +def resize(a: _ArrayLike[_SCT], new_shape: _SizeT) -> np.ndarray[tuple[_SizeT], np.dtype[_SCT]]: ... @overload def resize(a: _ArrayLike[_SCT], new_shape: SupportsIndex) -> np.ndarray[tuple[int], np.dtype[_SCT]]: ... @overload -def resize(a: _ArrayLike[_SCT], new_shape: _ShapeType) -> np.ndarray[_ShapeType, np.dtype[_SCT]]: ... +def resize(a: _ArrayLike[_SCT], new_shape: _ShapeT) -> np.ndarray[_ShapeT, np.dtype[_SCT]]: ... @overload def resize(a: _ArrayLike[_SCT], new_shape: Sequence[SupportsIndex]) -> NDArray[_SCT]: ... @overload -def resize(a: ArrayLike, new_shape: _SizeType) -> np.ndarray[tuple[_SizeType], np.dtype[Any]]: ... +def resize(a: ArrayLike, new_shape: _SizeT) -> np.ndarray[tuple[_SizeT], np.dtype[Any]]: ... @overload def resize(a: ArrayLike, new_shape: SupportsIndex) -> np.ndarray[tuple[int], np.dtype[Any]]: ... @overload -def resize(a: ArrayLike, new_shape: _ShapeType) -> np.ndarray[_ShapeType, np.dtype[Any]]: ... +def resize(a: ArrayLike, new_shape: _ShapeT) -> np.ndarray[_ShapeT, np.dtype[Any]]: ... @overload def resize(a: ArrayLike, new_shape: Sequence[SupportsIndex]) -> NDArray[Any]: ... + +# @overload -def squeeze( - a: _SCT, - axis: _ShapeLike | None = ..., -) -> _SCT: ... +def squeeze(a: _SCT, axis: _ShapeLike | None = ...) -> _SCT: ... @overload -def squeeze( - a: _ArrayLike[_SCT], - axis: _ShapeLike | None = ..., -) -> NDArray[_SCT]: ... +def squeeze(a: _ArrayLike[_SCT], axis: _ShapeLike | None = ...) -> NDArray[_SCT]: ... @overload -def squeeze( - a: ArrayLike, - axis: _ShapeLike | None = ..., -) -> NDArray[Any]: ... +def squeeze(a: ArrayLike, axis: _ShapeLike | None = ...) -> NDArray[Any]: ... + +# @overload def diagonal( a: _ArrayLike[_SCT], @@ -454,6 +402,8 @@ def diagonal( axis1: SupportsIndex = ..., axis2: SupportsIndex = ..., # >= 2D array ) -> NDArray[Any]: ... + +# @overload def trace( a: ArrayLike, # >= 2D array @@ -470,76 +420,77 @@ def trace( axis1: SupportsIndex = ..., axis2: SupportsIndex = ..., dtype: DTypeLike = ..., - out: _ArrayType = ..., -) -> _ArrayType: ... + out: _ArrayT = ..., +) -> _ArrayT: ... _Array1D: TypeAlias = np.ndarray[tuple[int], np.dtype[_SCT]] @overload -def ravel(a: _ArrayLike[_SCT], order: _OrderKACF = "C") -> _Array1D[_SCT]: ... +def ravel(a: _ArrayLike[_SCT], order: np._OrderKACF = "C") -> _Array1D[_SCT]: ... @overload -def ravel(a: bytes | _NestedSequence[bytes], order: _OrderKACF = "C") -> _Array1D[np.bytes_]: ... +def ravel(a: bytes | _NestedSequence[bytes], order: np._OrderKACF = "C") -> _Array1D[np.bytes_]: ... @overload -def ravel(a: str | _NestedSequence[str], order: _OrderKACF = "C") -> _Array1D[np.str_]: ... +def ravel(a: str | _NestedSequence[str], order: np._OrderKACF = "C") -> _Array1D[np.str_]: ... @overload -def ravel(a: bool | _NestedSequence[bool], order: _OrderKACF = "C") -> _Array1D[np.bool]: ... +def ravel(a: bool | _NestedSequence[bool], order: np._OrderKACF = "C") -> _Array1D[np.bool]: ... @overload -def ravel(a: int | _NestedSequence[int], order: _OrderKACF = "C") -> _Array1D[np.int_ | np.bool]: ... +def ravel(a: int | _NestedSequence[int], order: np._OrderKACF = "C") -> _Array1D[np.int_ | np.bool]: ... @overload -def ravel(a: float | _NestedSequence[float], order: _OrderKACF = "C") -> _Array1D[np.float64 | np.int_ | np.bool]: ... +def ravel(a: float | _NestedSequence[float], order: np._OrderKACF = "C") -> _Array1D[np.float64 | np.int_ | np.bool]: ... @overload def ravel( a: complex | _NestedSequence[complex], - order: _OrderKACF = "C", + order: np._OrderKACF = "C", ) -> _Array1D[np.complex128 | np.float64 | np.int_ | np.bool]: ... @overload -def ravel(a: ArrayLike, order: _OrderKACF = "C") -> np.ndarray[tuple[int], np.dtype[Any]]: ... +def ravel(a: ArrayLike, order: np._OrderKACF = "C") -> np.ndarray[tuple[int], np.dtype[Any]]: ... + +# @overload def nonzero(a: np.generic | np.ndarray[tuple[()], Any]) -> NoReturn: ... @overload -def nonzero(a: _ArrayLike[Any]) -> tuple[NDArray[intp], ...]: ... +def nonzero(a: _ArrayLike[Any]) -> tuple[NDArray[np.int_], ...]: ... -# this prevents `Any` from being returned with Pyright +# @overload def shape(a: _SupportsShape[Never]) -> tuple[int, ...]: ... @overload -def shape(a: _SupportsShape[_ShapeType]) -> _ShapeType: ... +def shape(a: _SupportsShape[_ShapeT]) -> _ShapeT: ... @overload def shape(a: _PyScalar) -> tuple[()]: ... - -# `collections.abc.Sequence` can't be used hesre, since `bytes` and `str` are -# subtypes of it, which would make the return types incompatible. @overload def shape(a: _PyArray[_PyScalar]) -> tuple[int]: ... @overload def shape(a: _PyArray[_PyArray[_PyScalar]]) -> tuple[int, int]: ... - -# this overload will be skipped by typecheckers that don't support PEP 688 @overload def shape(a: memoryview | bytearray) -> tuple[int]: ... @overload def shape(a: ArrayLike) -> tuple[int, ...]: ... + +# @overload def compress( - condition: _ArrayLikeBool_co, # 1D bool array + condition: _ArrayLikeBool_co, a: _ArrayLike[_SCT], axis: SupportsIndex | None = ..., out: None = ..., ) -> NDArray[_SCT]: ... @overload def compress( - condition: _ArrayLikeBool_co, # 1D bool array + condition: _ArrayLikeBool_co, a: ArrayLike, axis: SupportsIndex | None = ..., out: None = ..., ) -> NDArray[Any]: ... @overload def compress( - condition: _ArrayLikeBool_co, # 1D bool array + condition: _ArrayLikeBool_co, a: ArrayLike, axis: SupportsIndex | None = ..., - out: _ArrayType = ..., -) -> _ArrayType: ... + out: _ArrayT = ..., +) -> _ArrayT: ... + +# @overload def clip( a: _SCT, @@ -551,10 +502,10 @@ def clip( max: ArrayLike | None = ..., dtype: None = ..., where: _ArrayLikeBool_co | None = ..., - order: _OrderKACF = ..., + order: np._OrderKACF = ..., subok: bool = ..., signature: str | tuple[str | None, ...] = ..., - casting: _CastingKind = ..., + casting: np._CastingKind = ..., ) -> _SCT: ... @overload def clip( @@ -567,10 +518,10 @@ def clip( max: ArrayLike | None = ..., dtype: None = ..., where: _ArrayLikeBool_co | None = ..., - order: _OrderKACF = ..., + order: np._OrderKACF = ..., subok: bool = ..., signature: str | tuple[str | None, ...] = ..., - casting: _CastingKind = ..., + casting: np._CastingKind = ..., ) -> Any: ... @overload def clip( @@ -583,10 +534,10 @@ def clip( max: ArrayLike | None = ..., dtype: None = ..., where: _ArrayLikeBool_co | None = ..., - order: _OrderKACF = ..., + order: np._OrderKACF = ..., subok: bool = ..., signature: str | tuple[str | None, ...] = ..., - casting: _CastingKind = ..., + casting: np._CastingKind = ..., ) -> NDArray[_SCT]: ... @overload def clip( @@ -599,43 +550,45 @@ def clip( max: ArrayLike | None = ..., dtype: None = ..., where: _ArrayLikeBool_co | None = ..., - order: _OrderKACF = ..., + order: np._OrderKACF = ..., subok: bool = ..., signature: str | tuple[str | None, ...] = ..., - casting: _CastingKind = ..., + casting: np._CastingKind = ..., ) -> NDArray[Any]: ... @overload def clip( a: ArrayLike, a_min: ArrayLike | None, a_max: ArrayLike | None, - out: _ArrayType = ..., + out: _ArrayT = ..., *, min: ArrayLike | None = ..., max: ArrayLike | None = ..., dtype: DTypeLike, where: _ArrayLikeBool_co | None = ..., - order: _OrderKACF = ..., + order: np._OrderKACF = ..., subok: bool = ..., signature: str | tuple[str | None, ...] = ..., - casting: _CastingKind = ..., + casting: np._CastingKind = ..., ) -> Any: ... @overload def clip( a: ArrayLike, a_min: ArrayLike | None, a_max: ArrayLike | None, - out: _ArrayType, + out: _ArrayT, *, min: ArrayLike | None = ..., max: ArrayLike | None = ..., dtype: DTypeLike = ..., where: _ArrayLikeBool_co | None = ..., - order: _OrderKACF = ..., + order: np._OrderKACF = ..., subok: bool = ..., signature: str | tuple[str | None, ...] = ..., - casting: _CastingKind = ..., -) -> _ArrayType: ... + casting: np._CastingKind = ..., +) -> _ArrayT: ... + +# @overload def sum( a: _ArrayLike[_SCT], @@ -713,11 +666,13 @@ def sum( a: ArrayLike, axis: _ShapeLike | None = ..., dtype: DTypeLike = ..., - out: _ArrayType = ..., + out: _ArrayT = ..., keepdims: bool = ..., initial: _NumberLike_co = ..., where: _ArrayLikeBool_co = ..., -) -> _ArrayType: ... +) -> _ArrayT: ... + +# @overload def all( a: ArrayLike, @@ -740,20 +695,22 @@ def all( def all( a: ArrayLike, axis: int | tuple[int, ...] | None, - out: _ArrayType, + out: _ArrayT, keepdims: SupportsIndex = False, *, where: _ArrayLikeBool_co = True, -) -> _ArrayType: ... +) -> _ArrayT: ... @overload def all( a: ArrayLike, axis: int | tuple[int, ...] | None = None, *, - out: _ArrayType, + out: _ArrayT, keepdims: SupportsIndex = False, where: _ArrayLikeBool_co = True, -) -> _ArrayType: ... +) -> _ArrayT: ... + +# @overload def any( a: ArrayLike, @@ -776,55 +733,34 @@ def any( def any( a: ArrayLike, axis: int | tuple[int, ...] | None, - out: _ArrayType, + out: _ArrayT, keepdims: SupportsIndex = False, *, where: _ArrayLikeBool_co = True, -) -> _ArrayType: ... +) -> _ArrayT: ... @overload def any( a: ArrayLike, axis: int | tuple[int, ...] | None = None, *, - out: _ArrayType, + out: _ArrayT, keepdims: SupportsIndex = False, where: _ArrayLikeBool_co = True, -) -> _ArrayType: ... +) -> _ArrayT: ... + +# @overload -def cumsum( - a: _ArrayLike[_SCT], - axis: SupportsIndex | None = ..., - dtype: None = ..., - out: None = ..., -) -> NDArray[_SCT]: ... +def cumsum(a: _ArrayLike[_SCT], axis: SupportsIndex | None = ..., dtype: None = ..., out: None = ...) -> NDArray[_SCT]: ... @overload -def cumsum( - a: ArrayLike, - axis: SupportsIndex | None = ..., - dtype: None = ..., - out: None = ..., -) -> NDArray[Any]: ... +def cumsum(a: ArrayLike, axis: SupportsIndex | None = ..., dtype: None = ..., out: None = ...) -> NDArray[Any]: ... @overload -def cumsum( - a: ArrayLike, - axis: SupportsIndex | None = ..., - dtype: _DTypeLike[_SCT] = ..., - out: None = ..., -) -> NDArray[_SCT]: ... +def cumsum(a: ArrayLike, axis: SupportsIndex | None = ..., dtype: _DTypeLike[_SCT] = ..., out: None = ...) -> NDArray[_SCT]: ... @overload -def cumsum( - a: ArrayLike, - axis: SupportsIndex | None = ..., - dtype: DTypeLike = ..., - out: None = ..., -) -> NDArray[Any]: ... +def cumsum(a: ArrayLike, axis: SupportsIndex | None = ..., dtype: DTypeLike = ..., out: None = ...) -> NDArray[Any]: ... @overload -def cumsum( - a: ArrayLike, - axis: SupportsIndex | None = ..., - dtype: DTypeLike = ..., - out: _ArrayType = ..., -) -> _ArrayType: ... +def cumsum(a: ArrayLike, axis: SupportsIndex | None = ..., dtype: DTypeLike = ..., out: _ArrayT = ...) -> _ArrayT: ... + +# @overload def cumulative_sum( x: _ArrayLike[_SCT], @@ -872,30 +808,19 @@ def cumulative_sum( *, axis: SupportsIndex | None = ..., dtype: DTypeLike = ..., - out: _ArrayType = ..., + out: _ArrayT = ..., include_initial: bool = ..., -) -> _ArrayType: ... +) -> _ArrayT: ... + +# @overload -def ptp( - a: _ArrayLike[_SCT], - axis: None = ..., - out: None = ..., - keepdims: Literal[False] = ..., -) -> _SCT: ... +def ptp(a: _ArrayLike[_SCT], axis: None = ..., out: None = ..., keepdims: Literal[False] = ...) -> _SCT: ... @overload -def ptp( - a: ArrayLike, - axis: _ShapeLike | None = ..., - out: None = ..., - keepdims: bool = ..., -) -> Any: ... +def ptp(a: ArrayLike, axis: _ShapeLike | None = ..., out: None = ..., keepdims: bool = ...) -> Any: ... @overload -def ptp( - a: ArrayLike, - axis: _ShapeLike | None = ..., - out: _ArrayType = ..., - keepdims: bool = ..., -) -> _ArrayType: ... +def ptp(a: ArrayLike, axis: _ShapeLike | None = ..., out: _ArrayT = ..., keepdims: bool = ...) -> _ArrayT: ... + +# @overload def amax( a: _ArrayLike[_SCT], @@ -918,11 +843,13 @@ def amax( def amax( a: ArrayLike, axis: _ShapeLike | None = ..., - out: _ArrayType = ..., + out: _ArrayT = ..., keepdims: bool = ..., initial: _NumberLike_co = ..., where: _ArrayLikeBool_co = ..., -) -> _ArrayType: ... +) -> _ArrayT: ... + +# @overload def amin( a: _ArrayLike[_SCT], @@ -945,11 +872,11 @@ def amin( def amin( a: ArrayLike, axis: _ShapeLike | None = ..., - out: _ArrayType = ..., + out: _ArrayT = ..., keepdims: bool = ..., initial: _NumberLike_co = ..., where: _ArrayLikeBool_co = ..., -) -> _ArrayType: ... +) -> _ArrayT: ... # TODO: `np.prod()``: For object arrays `initial` does not necessarily # have to be a numerical scalar. @@ -967,7 +894,7 @@ def prod( keepdims: Literal[False] = ..., initial: _NumberLike_co = ..., where: _ArrayLikeBool_co = ..., -) -> int_: ... +) -> np.int_: ... @overload def prod( a: _ArrayLikeUInt_co, @@ -977,7 +904,7 @@ def prod( keepdims: Literal[False] = ..., initial: _NumberLike_co = ..., where: _ArrayLikeBool_co = ..., -) -> uint64: ... +) -> np.uint64: ... @overload def prod( a: _ArrayLikeInt_co, @@ -987,7 +914,7 @@ def prod( keepdims: Literal[False] = ..., initial: _NumberLike_co = ..., where: _ArrayLikeBool_co = ..., -) -> int64: ... +) -> np.int64: ... @overload def prod( a: _ArrayLikeFloat_co, @@ -997,7 +924,7 @@ def prod( keepdims: Literal[False] = ..., initial: _NumberLike_co = ..., where: _ArrayLikeBool_co = ..., -) -> floating[Any]: ... +) -> np.floating: ... @overload def prod( a: _ArrayLikeComplex_co, @@ -1007,7 +934,7 @@ def prod( keepdims: Literal[False] = ..., initial: _NumberLike_co = ..., where: _ArrayLikeBool_co = ..., -) -> complexfloating[Any, Any]: ... +) -> np.complexfloating: ... @overload def prod( a: _ArrayLikeComplex_co | _ArrayLikeObject_co, @@ -1043,53 +970,55 @@ def prod( a: _ArrayLikeComplex_co | _ArrayLikeObject_co, axis: _ShapeLike | None = ..., dtype: DTypeLike | None = ..., - out: _ArrayType = ..., + out: _ArrayT = ..., keepdims: bool = ..., initial: _NumberLike_co = ..., where: _ArrayLikeBool_co = ..., -) -> _ArrayType: ... +) -> _ArrayT: ... + +# @overload def cumprod( a: _ArrayLikeBool_co, axis: SupportsIndex | None = ..., dtype: None = ..., out: None = ..., -) -> NDArray[int_]: ... +) -> NDArray[np.int_]: ... @overload def cumprod( a: _ArrayLikeUInt_co, axis: SupportsIndex | None = ..., dtype: None = ..., out: None = ..., -) -> NDArray[uint64]: ... +) -> NDArray[np.uint64]: ... @overload def cumprod( a: _ArrayLikeInt_co, axis: SupportsIndex | None = ..., dtype: None = ..., out: None = ..., -) -> NDArray[int64]: ... +) -> NDArray[np.int64]: ... @overload def cumprod( a: _ArrayLikeFloat_co, axis: SupportsIndex | None = ..., dtype: None = ..., out: None = ..., -) -> NDArray[floating[Any]]: ... +) -> NDArray[np.floating]: ... @overload def cumprod( a: _ArrayLikeComplex_co, axis: SupportsIndex | None = ..., dtype: None = ..., out: None = ..., -) -> NDArray[complexfloating[Any, Any]]: ... +) -> NDArray[np.complexfloating]: ... @overload def cumprod( a: _ArrayLikeObject_co, axis: SupportsIndex | None = ..., dtype: None = ..., out: None = ..., -) -> NDArray[object_]: ... +) -> NDArray[np.object_]: ... @overload def cumprod( a: _ArrayLikeComplex_co | _ArrayLikeObject_co, @@ -1109,8 +1038,10 @@ def cumprod( a: _ArrayLikeComplex_co | _ArrayLikeObject_co, axis: SupportsIndex | None = ..., dtype: DTypeLike = ..., - out: _ArrayType = ..., -) -> _ArrayType: ... + out: _ArrayT = ..., +) -> _ArrayT: ... + +# @overload def cumulative_prod( x: _ArrayLikeBool_co, @@ -1120,7 +1051,7 @@ def cumulative_prod( dtype: None = ..., out: None = ..., include_initial: bool = ..., -) -> NDArray[int_]: ... +) -> NDArray[np.int_]: ... @overload def cumulative_prod( x: _ArrayLikeUInt_co, @@ -1130,7 +1061,7 @@ def cumulative_prod( dtype: None = ..., out: None = ..., include_initial: bool = ..., -) -> NDArray[uint64]: ... +) -> NDArray[np.uint64]: ... @overload def cumulative_prod( x: _ArrayLikeInt_co, @@ -1140,7 +1071,7 @@ def cumulative_prod( dtype: None = ..., out: None = ..., include_initial: bool = ..., -) -> NDArray[int64]: ... +) -> NDArray[np.int64]: ... @overload def cumulative_prod( x: _ArrayLikeFloat_co, @@ -1150,7 +1081,7 @@ def cumulative_prod( dtype: None = ..., out: None = ..., include_initial: bool = ..., -) -> NDArray[floating[Any]]: ... +) -> NDArray[np.floating]: ... @overload def cumulative_prod( x: _ArrayLikeComplex_co, @@ -1160,7 +1091,7 @@ def cumulative_prod( dtype: None = ..., out: None = ..., include_initial: bool = ..., -) -> NDArray[complexfloating[Any, Any]]: ... +) -> NDArray[np.complexfloating]: ... @overload def cumulative_prod( x: _ArrayLikeObject_co, @@ -1170,7 +1101,7 @@ def cumulative_prod( dtype: None = ..., out: None = ..., include_initial: bool = ..., -) -> NDArray[object_]: ... +) -> NDArray[np.object_]: ... @overload def cumulative_prod( x: _ArrayLikeComplex_co | _ArrayLikeObject_co, @@ -1198,53 +1129,31 @@ def cumulative_prod( *, axis: SupportsIndex | None = ..., dtype: DTypeLike = ..., - out: _ArrayType = ..., + out: _ArrayT = ..., include_initial: bool = ..., -) -> _ArrayType: ... +) -> _ArrayT: ... + +# def ndim(a: ArrayLike) -> int: ... def size(a: ArrayLike, axis: int | None = ...) -> int: ... + +# @overload -def around( - a: _BoolLike_co, - decimals: SupportsIndex = ..., - out: None = ..., -) -> float16: ... +def around(a: _BoolLike_co, decimals: SupportsIndex = ..., out: None = ...) -> np.float16: ... @overload -def around( - a: _SCT_uifcO, - decimals: SupportsIndex = ..., - out: None = ..., -) -> _SCT_uifcO: ... +def around(a: _SCT_uifcO, decimals: SupportsIndex = ..., out: None = ...) -> _SCT_uifcO: ... @overload -def around( - a: _ComplexLike_co | object_, - decimals: SupportsIndex = ..., - out: None = ..., -) -> Any: ... +def around(a: _ComplexLike_co | np.object_, decimals: SupportsIndex = ..., out: None = ...) -> Any: ... @overload -def around( - a: _ArrayLikeBool_co, - decimals: SupportsIndex = ..., - out: None = ..., -) -> NDArray[float16]: ... +def around(a: _ArrayLikeBool_co, decimals: SupportsIndex = ..., out: None = ...) -> NDArray[np.float16]: ... @overload -def around( - a: _ArrayLike[_SCT_uifcO], - decimals: SupportsIndex = ..., - out: None = ..., -) -> NDArray[_SCT_uifcO]: ... +def around(a: _ArrayLike[_SCT_uifcO], decimals: SupportsIndex = ..., out: None = ...) -> NDArray[_SCT_uifcO]: ... @overload -def around( - a: _ArrayLikeComplex_co | _ArrayLikeObject_co, - decimals: SupportsIndex = ..., - out: None = ..., -) -> NDArray[Any]: ... +def around(a: _ArrayLikeComplex_co | _ArrayLikeObject_co, decimals: SupportsIndex = ..., out: None = ...) -> NDArray[Any]: ... @overload -def around( - a: _ArrayLikeComplex_co | _ArrayLikeObject_co, - decimals: SupportsIndex = ..., - out: _ArrayType = ..., -) -> _ArrayType: ... +def around(a: _ArrayLikeComplex_co | _ArrayLikeObject_co, decimals: SupportsIndex = ..., out: _ArrayT = ...) -> _ArrayT: ... + +# @overload def mean( a: _ArrayLikeFloat_co, @@ -1254,7 +1163,7 @@ def mean( keepdims: Literal[False] = ..., *, where: _ArrayLikeBool_co = ..., -) -> floating[Any]: ... +) -> np.floating: ... @overload def mean( a: _ArrayLikeComplex_co, @@ -1264,7 +1173,7 @@ def mean( keepdims: Literal[False] = ..., *, where: _ArrayLikeBool_co = ..., -) -> complexfloating[Any, Any]: ... +) -> np.complexfloating: ... @overload def mean( a: _ArrayLikeTD64_co, @@ -1274,7 +1183,7 @@ def mean( keepdims: Literal[False] = ..., *, where: _ArrayLikeBool_co = ..., -) -> timedelta64: ... +) -> np.timedelta64: ... @overload def mean( a: _ArrayLikeComplex_co | _ArrayLikeObject_co, @@ -1330,11 +1239,13 @@ def mean( a: _ArrayLikeComplex_co | _ArrayLikeObject_co, axis: _ShapeLike | None = ..., dtype: DTypeLike = ..., - out: _ArrayType = ..., + out: _ArrayT = ..., keepdims: bool = ..., *, where: _ArrayLikeBool_co = ..., -) -> _ArrayType: ... +) -> _ArrayT: ... + +# @overload def std( a: _ArrayLikeComplex_co, @@ -1347,7 +1258,7 @@ def std( where: _ArrayLikeBool_co = ..., mean: _ArrayLikeComplex_co = ..., correction: float = ..., -) -> floating[Any]: ... +) -> np.floating: ... @overload def std( a: _ArrayLikeComplex_co | _ArrayLikeObject_co, @@ -1392,14 +1303,16 @@ def std( a: _ArrayLikeComplex_co | _ArrayLikeObject_co, axis: _ShapeLike | None = ..., dtype: DTypeLike = ..., - out: _ArrayType = ..., + out: _ArrayT = ..., ddof: float = ..., keepdims: bool = ..., *, where: _ArrayLikeBool_co = ..., mean: _ArrayLikeComplex_co | _ArrayLikeObject_co = ..., correction: float = ..., -) -> _ArrayType: ... +) -> _ArrayT: ... + +# @overload def var( a: _ArrayLikeComplex_co, @@ -1412,7 +1325,7 @@ def var( where: _ArrayLikeBool_co = ..., mean: _ArrayLikeComplex_co = ..., correction: float = ..., -) -> floating[Any]: ... +) -> np.floating: ... @overload def var( a: _ArrayLikeComplex_co | _ArrayLikeObject_co, @@ -1457,14 +1370,14 @@ def var( a: _ArrayLikeComplex_co | _ArrayLikeObject_co, axis: _ShapeLike | None = ..., dtype: DTypeLike = ..., - out: _ArrayType = ..., + out: _ArrayT = ..., ddof: float = ..., keepdims: bool = ..., *, where: _ArrayLikeBool_co = ..., mean: _ArrayLikeComplex_co | _ArrayLikeObject_co = ..., correction: float = ..., -) -> _ArrayType: ... +) -> _ArrayT: ... max = amax min = amin diff --git a/src/numpy-stubs/_core/function_base.pyi b/src/numpy-stubs/_core/function_base.pyi index d3c0906c..3fd9755f 100644 --- a/src/numpy-stubs/_core/function_base.pyi +++ b/src/numpy-stubs/_core/function_base.pyi @@ -1,23 +1,11 @@ -from typing import ( - Any, - Literal as L, - SupportsIndex, - TypeVar, - overload, -) +from typing import Any, Literal as L, SupportsIndex, TypeVar, overload -from numpy import complexfloating, floating, generic -from numpy._typing import ( - DTypeLike, - NDArray, - _ArrayLikeComplex_co, - _ArrayLikeFloat_co, - _DTypeLike, -) +import numpy as np +from numpy._typing import DTypeLike, NDArray, _ArrayLikeComplex_co, _ArrayLikeFloat_co, _DTypeLike __all__ = ["geomspace", "linspace", "logspace"] -_SCT = TypeVar("_SCT", bound=generic) +_SCT = TypeVar("_SCT", bound=np.generic) @overload def linspace( @@ -30,7 +18,7 @@ def linspace( axis: SupportsIndex = ..., *, device: L["cpu"] | None = ..., -) -> NDArray[floating[Any]]: ... +) -> NDArray[np.floating]: ... @overload def linspace( start: _ArrayLikeComplex_co, @@ -42,7 +30,7 @@ def linspace( axis: SupportsIndex = ..., *, device: L["cpu"] | None = ..., -) -> NDArray[complexfloating[Any, Any]]: ... +) -> NDArray[np.complexfloating]: ... @overload def linspace( start: _ArrayLikeComplex_co, @@ -78,7 +66,7 @@ def linspace( axis: SupportsIndex = ..., *, device: L["cpu"] | None = ..., -) -> tuple[NDArray[floating[Any]], floating[Any]]: ... +) -> tuple[NDArray[np.floating], np.floating]: ... @overload def linspace( start: _ArrayLikeComplex_co, @@ -90,7 +78,7 @@ def linspace( axis: SupportsIndex = ..., *, device: L["cpu"] | None = ..., -) -> tuple[NDArray[complexfloating[Any, Any]], complexfloating[Any, Any]]: ... +) -> tuple[NDArray[np.complexfloating], np.complexfloating]: ... @overload def linspace( start: _ArrayLikeComplex_co, @@ -115,6 +103,8 @@ def linspace( *, device: L["cpu"] | None = ..., ) -> tuple[NDArray[Any], Any]: ... + +# @overload def logspace( start: _ArrayLikeFloat_co, @@ -124,7 +114,7 @@ def logspace( base: _ArrayLikeFloat_co = ..., dtype: None = ..., axis: SupportsIndex = ..., -) -> NDArray[floating[Any]]: ... +) -> NDArray[np.floating]: ... @overload def logspace( start: _ArrayLikeComplex_co, @@ -134,7 +124,7 @@ def logspace( base: _ArrayLikeComplex_co = ..., dtype: None = ..., axis: SupportsIndex = ..., -) -> NDArray[complexfloating[Any, Any]]: ... +) -> NDArray[np.complexfloating]: ... @overload def logspace( start: _ArrayLikeComplex_co, @@ -155,6 +145,8 @@ def logspace( dtype: DTypeLike = ..., axis: SupportsIndex = ..., ) -> NDArray[Any]: ... + +# @overload def geomspace( start: _ArrayLikeFloat_co, @@ -163,7 +155,7 @@ def geomspace( endpoint: bool = ..., dtype: None = ..., axis: SupportsIndex = ..., -) -> NDArray[floating[Any]]: ... +) -> NDArray[np.floating]: ... @overload def geomspace( start: _ArrayLikeComplex_co, @@ -172,7 +164,7 @@ def geomspace( endpoint: bool = ..., dtype: None = ..., axis: SupportsIndex = ..., -) -> NDArray[complexfloating[Any, Any]]: ... +) -> NDArray[np.complexfloating]: ... @overload def geomspace( start: _ArrayLikeComplex_co, @@ -191,9 +183,6 @@ def geomspace( dtype: DTypeLike = ..., axis: SupportsIndex = ..., ) -> NDArray[Any]: ... -def add_newdoc( - place: str, - obj: str, - doc: str | tuple[str, str] | list[tuple[str, str]], - warn_on_python: bool = ..., -) -> None: ... + +# +def add_newdoc(place: str, obj: str, doc: str | tuple[str, str] | list[tuple[str, str]], warn_on_python: bool = ...) -> None: ... diff --git a/src/numpy-stubs/_core/getlimits.pyi b/src/numpy-stubs/_core/getlimits.pyi index 9d79b178..09892b9b 100644 --- a/src/numpy-stubs/_core/getlimits.pyi +++ b/src/numpy-stubs/_core/getlimits.pyi @@ -1,3 +1,3 @@ -from numpy import finfo, iinfo +from numpy import finfo, iinfo # noqa: ICN003 __all__ = ["finfo", "iinfo"] diff --git a/src/numpy-stubs/_core/memmap.pyi b/src/numpy-stubs/_core/memmap.pyi index 0b313284..45638a28 100644 --- a/src/numpy-stubs/_core/memmap.pyi +++ b/src/numpy-stubs/_core/memmap.pyi @@ -1,3 +1,3 @@ -from numpy import memmap +from numpy import memmap # noqa: ICN003 __all__ = ["memmap"] diff --git a/src/numpy-stubs/_core/multiarray.pyi b/src/numpy-stubs/_core/multiarray.pyi index f95cd21c..7a2f01ca 100644 --- a/src/numpy-stubs/_core/multiarray.pyi +++ b/src/numpy-stubs/_core/multiarray.pyi @@ -1,4 +1,3 @@ -# TODO: Sort out any and all missing functions in this namespace import datetime as dt from _typeshed import StrOrBytesPath, SupportsLenAndGetItem from collections.abc import Callable, Iterable, Sequence @@ -19,50 +18,25 @@ from typing import ( from typing_extensions import CapsuleType, Unpack import numpy as np -from numpy import ( # type: ignore[attr-defined] - _CastingKind, - _CopyMode, - _ModeKind, - _NDIterFlagsKind, - _NDIterFlagsOp, - _OrderCF, - _OrderKACF, - _SupportsBuffer, - _SupportsFileMethods, +from numpy import ( # noqa: ICN003 broadcast, - # Re-exports busdaycalendar, - complexfloating, correlate, count_nonzero, - datetime64, dtype, einsum as c_einsum, flatiter, - float64, - floating, from_dlpack, - generic, - int_, interp, - intp, matmul, ndarray, nditer, - signedinteger, - str_, - timedelta64, - # The rest ufunc, - uint8, - unsignedinteger, vecdot, ) from numpy._typing import ( ArrayLike, - # DTypes DTypeLike, - # Arrays NDArray, _ArrayLike, _ArrayLikeBool_co, @@ -80,19 +54,12 @@ from numpy._typing import ( _IntLike_co, _NestedSequence, _ScalarLike_co, - # Shapes _ShapeLike, _SupportsArrayFunc, _SupportsDType, _TD64Like_co, ) -from numpy._typing._ufunc import ( - _2PTuple, - _PyFunc_Nin1P_Nout2P, - _PyFunc_Nin1_Nout1, - _PyFunc_Nin2_Nout1, - _PyFunc_Nin3P_Nout1, -) +from numpy._typing._ufunc import _2PTuple, _PyFunc_Nin1P_Nout2P, _PyFunc_Nin1_Nout1, _PyFunc_Nin2_Nout1, _PyFunc_Nin3P_Nout1 from numpy.lib._array_utils_impl import normalize_axis_index __all__ = [ @@ -187,55 +154,31 @@ __all__ = [ "zeros", ] -_T_co = TypeVar("_T_co", covariant=True) -_T_contra = TypeVar("_T_contra", contravariant=True) -_SCT = TypeVar("_SCT", bound=generic) -_DType = TypeVar("_DType", bound=np.dtype[Any]) -_ArrayType = TypeVar("_ArrayType", bound=ndarray[Any, Any]) -_ArrayType_co = TypeVar( - "_ArrayType_co", - bound=ndarray[Any, Any], - covariant=True, -) -_ReturnType = TypeVar("_ReturnType") -_IDType = TypeVar("_IDType") -_Nin = TypeVar("_Nin", bound=int) -_Nout = TypeVar("_Nout", bound=int) +_ReturnT = TypeVar("_ReturnT") +_IdentityT = TypeVar("_IdentityT") + +_SCT = TypeVar("_SCT", bound=np.generic) +_DTypeT = TypeVar("_DTypeT", bound=np.dtype[Any]) +_ArrayT = TypeVar("_ArrayT", bound=ndarray[Any, Any]) +_ArrayT_co = TypeVar("_ArrayT_co", bound=ndarray[Any, Any], covariant=True) -_SizeType = TypeVar("_SizeType", bound=int) -_ShapeType = TypeVar("_ShapeType", bound=tuple[int, ...]) -_1DArray: TypeAlias = ndarray[tuple[_SizeType], dtype[_SCT]] -_Array: TypeAlias = ndarray[_ShapeType, dtype[_SCT]] +_NInT = TypeVar("_NInT", bound=int) +_NOutT = TypeVar("_NOutT", bound=int) +_SizeT = TypeVar("_SizeT", bound=int) +_ShapeT = TypeVar("_ShapeT", bound=tuple[int, ...]) + +_Array1D: TypeAlias = ndarray[tuple[_SizeT], dtype[_SCT]] +_Array: TypeAlias = ndarray[_ShapeT, dtype[_SCT]] # Valid time units -_UnitKind: TypeAlias = L[ - "Y", - "M", - "D", - "h", - "m", - "s", - "ms", - "us", - "μs", - "ns", - "ps", - "fs", - "as", -] -_RollKind: TypeAlias = L[ # `raise` is deliberately excluded - "nat", - "forward", - "following", - "backward", - "preceding", - "modifiedfollowing", - "modifiedpreceding", -] +_UnitKind: TypeAlias = L["Y", "M", "D", "h", "m", "s", "ms", "us", "μs", "ns", "ps", "fs", "as"] + +# `raise` is deliberately excluded +_RollKind: TypeAlias = L["nat", "forward", "following", "backward", "preceding", "modifiedfollowing", "modifiedpreceding"] @type_check_only -class _SupportsArray(Protocol[_ArrayType_co]): - def __array__(self, /) -> _ArrayType_co: ... +class _SupportsArray(Protocol[_ArrayT_co]): + def __array__(self, /) -> _ArrayT_co: ... @type_check_only class _KwargsEmpty(TypedDict, total=False): @@ -249,76 +192,76 @@ class _ConstructorEmpty(Protocol): def __call__( self, /, - shape: _SizeType, + shape: _SizeT, dtype: None = ..., - order: _OrderCF = ..., + order: np._OrderCF = ..., **kwargs: Unpack[_KwargsEmpty], - ) -> _Array[tuple[_SizeType], float64]: ... + ) -> _Array[tuple[_SizeT], np.float64]: ... @overload def __call__( self, /, - shape: _SizeType, - dtype: _DType | _SupportsDType[_DType], - order: _OrderCF = ..., + shape: _SizeT, + dtype: _DTypeT | _SupportsDType[_DTypeT], + order: np._OrderCF = ..., **kwargs: Unpack[_KwargsEmpty], - ) -> ndarray[tuple[_SizeType], _DType]: ... + ) -> ndarray[tuple[_SizeT], _DTypeT]: ... @overload def __call__( self, /, - shape: _SizeType, + shape: _SizeT, dtype: type[_SCT], - order: _OrderCF = ..., + order: np._OrderCF = ..., **kwargs: Unpack[_KwargsEmpty], - ) -> _Array[tuple[_SizeType], _SCT]: ... + ) -> _Array[tuple[_SizeT], _SCT]: ... @overload def __call__( self, /, - shape: _SizeType, + shape: _SizeT, dtype: DTypeLike, - order: _OrderCF = ..., + order: np._OrderCF = ..., **kwargs: Unpack[_KwargsEmpty], - ) -> _Array[tuple[_SizeType], Any]: ... + ) -> _Array[tuple[_SizeT], Any]: ... # known shape @overload def __call__( self, /, - shape: _ShapeType, + shape: _ShapeT, dtype: None = ..., - order: _OrderCF = ..., + order: np._OrderCF = ..., **kwargs: Unpack[_KwargsEmpty], - ) -> _Array[_ShapeType, float64]: ... + ) -> _Array[_ShapeT, np.float64]: ... @overload def __call__( self, /, - shape: _ShapeType, - dtype: _DType | _SupportsDType[_DType], - order: _OrderCF = ..., + shape: _ShapeT, + dtype: _DTypeT | _SupportsDType[_DTypeT], + order: np._OrderCF = ..., **kwargs: Unpack[_KwargsEmpty], - ) -> ndarray[_ShapeType, _DType]: ... + ) -> ndarray[_ShapeT, _DTypeT]: ... @overload def __call__( self, /, - shape: _ShapeType, + shape: _ShapeT, dtype: type[_SCT], - order: _OrderCF = ..., + order: np._OrderCF = ..., **kwargs: Unpack[_KwargsEmpty], - ) -> _Array[_ShapeType, _SCT]: ... + ) -> _Array[_ShapeT, _SCT]: ... @overload def __call__( self, /, - shape: _ShapeType, + shape: _ShapeT, dtype: DTypeLike, - order: _OrderCF = ..., + order: np._OrderCF = ..., **kwargs: Unpack[_KwargsEmpty], - ) -> _Array[_ShapeType, Any]: ... + ) -> _Array[_ShapeT, Any]: ... # unknown shape @overload @@ -327,25 +270,25 @@ class _ConstructorEmpty(Protocol): /, shape: _ShapeLike, dtype: None = ..., - order: _OrderCF = ..., + order: np._OrderCF = ..., **kwargs: Unpack[_KwargsEmpty], - ) -> NDArray[float64]: ... + ) -> NDArray[np.float64]: ... @overload def __call__( self, /, shape: _ShapeLike, - dtype: _DType | _SupportsDType[_DType], - order: _OrderCF = ..., + dtype: _DTypeT | _SupportsDType[_DTypeT], + order: np._OrderCF = ..., **kwargs: Unpack[_KwargsEmpty], - ) -> ndarray[Any, _DType]: ... + ) -> ndarray[Any, _DTypeT]: ... @overload def __call__( self, /, shape: _ShapeLike, dtype: type[_SCT], - order: _OrderCF = ..., + order: np._OrderCF = ..., **kwargs: Unpack[_KwargsEmpty], ) -> NDArray[_SCT]: ... @overload @@ -354,7 +297,7 @@ class _ConstructorEmpty(Protocol): /, shape: _ShapeLike, dtype: DTypeLike, - order: _OrderCF = ..., + order: np._OrderCF = ..., **kwargs: Unpack[_KwargsEmpty], ) -> NDArray[Any]: ... @@ -384,7 +327,7 @@ set_datetimeparse_function: Final[Callable[..., object]] def get_handler_name(a: NDArray[Any] = ..., /) -> str | None: ... def get_handler_version(a: NDArray[Any] = ..., /) -> int | None: ... def format_longfloat(x: np.longdouble, precision: int) -> str: ... -def scalar(dtype: _DType, object: bytes | object = ...) -> ndarray[tuple[()], _DType]: ... +def scalar(dtype: _DTypeT, object: bytes | object = ...) -> ndarray[tuple[()], _DTypeT]: ... def set_typeDict(dict_: dict[str, np.dtype[Any]], /) -> None: ... typeinfo: Final[dict[str, np.dtype[np.generic]]] @@ -404,19 +347,19 @@ empty: Final[_ConstructorEmpty] @overload def empty_like( - prototype: _ArrayType, + prototype: _ArrayT, dtype: None = ..., - order: _OrderKACF = ..., + order: np._OrderKACF = ..., subok: bool = ..., shape: _ShapeLike | None = ..., *, device: L["cpu"] | None = ..., -) -> _ArrayType: ... +) -> _ArrayT: ... @overload def empty_like( prototype: _ArrayLike[_SCT], dtype: None = ..., - order: _OrderKACF = ..., + order: np._OrderKACF = ..., subok: bool = ..., shape: _ShapeLike | None = ..., *, @@ -426,7 +369,7 @@ def empty_like( def empty_like( prototype: object, dtype: None = ..., - order: _OrderKACF = ..., + order: np._OrderKACF = ..., subok: bool = ..., shape: _ShapeLike | None = ..., *, @@ -436,7 +379,7 @@ def empty_like( def empty_like( prototype: Any, dtype: _DTypeLike[_SCT], - order: _OrderKACF = ..., + order: np._OrderKACF = ..., subok: bool = ..., shape: _ShapeLike | None = ..., *, @@ -446,41 +389,43 @@ def empty_like( def empty_like( prototype: Any, dtype: DTypeLike, - order: _OrderKACF = ..., + order: np._OrderKACF = ..., subok: bool = ..., shape: _ShapeLike | None = ..., *, device: L["cpu"] | None = ..., ) -> NDArray[Any]: ... + +# @overload def array( - object: _ArrayType, + object: _ArrayT, dtype: None = ..., *, - copy: bool | _CopyMode | None = ..., - order: _OrderKACF = ..., + copy: bool | np._CopyMode | None = ..., + order: np._OrderKACF = ..., subok: L[True], ndmin: int = ..., like: _SupportsArrayFunc | None = ..., -) -> _ArrayType: ... +) -> _ArrayT: ... @overload def array( - object: _SupportsArray[_ArrayType], + object: _SupportsArray[_ArrayT], dtype: None = ..., *, - copy: bool | _CopyMode | None = ..., - order: _OrderKACF = ..., + copy: bool | np._CopyMode | None = ..., + order: np._OrderKACF = ..., subok: L[True], ndmin: L[0] = ..., like: _SupportsArrayFunc | None = ..., -) -> _ArrayType: ... +) -> _ArrayT: ... @overload def array( object: _ArrayLike[_SCT], dtype: None = ..., *, - copy: bool | _CopyMode | None = ..., - order: _OrderKACF = ..., + copy: bool | np._CopyMode | None = ..., + order: np._OrderKACF = ..., subok: bool = ..., ndmin: int = ..., like: _SupportsArrayFunc | None = ..., @@ -490,8 +435,8 @@ def array( object: object, dtype: None = ..., *, - copy: bool | _CopyMode | None = ..., - order: _OrderKACF = ..., + copy: bool | np._CopyMode | None = ..., + order: np._OrderKACF = ..., subok: bool = ..., ndmin: int = ..., like: _SupportsArrayFunc | None = ..., @@ -501,8 +446,8 @@ def array( object: Any, dtype: _DTypeLike[_SCT], *, - copy: bool | _CopyMode | None = ..., - order: _OrderKACF = ..., + copy: bool | np._CopyMode | None = ..., + order: np._OrderKACF = ..., subok: bool = ..., ndmin: int = ..., like: _SupportsArrayFunc | None = ..., @@ -512,38 +457,42 @@ def array( object: Any, dtype: DTypeLike, *, - copy: bool | _CopyMode | None = ..., - order: _OrderKACF = ..., + copy: bool | np._CopyMode | None = ..., + order: np._OrderKACF = ..., subok: bool = ..., ndmin: int = ..., like: _SupportsArrayFunc | None = ..., ) -> NDArray[Any]: ... + +# @overload -def unravel_index( # type: ignore[misc] +def unravel_index( indices: _IntLike_co, shape: _ShapeLike, - order: _OrderCF = ..., -) -> tuple[intp, ...]: ... + order: np._OrderCF = ..., +) -> tuple[np.int_, ...]: ... @overload def unravel_index( indices: _ArrayLikeInt_co, shape: _ShapeLike, - order: _OrderCF = ..., -) -> tuple[NDArray[intp], ...]: ... + order: np._OrderCF = ..., +) -> tuple[NDArray[np.int_], ...]: ... + +# @overload -def ravel_multi_index( # type: ignore[misc] +def ravel_multi_index( multi_index: Sequence[_IntLike_co], dims: Sequence[SupportsIndex], - mode: _ModeKind | tuple[_ModeKind, ...] = ..., - order: _OrderCF = ..., -) -> intp: ... + mode: np._ModeKind | tuple[np._ModeKind, ...] = ..., + order: np._OrderCF = ..., +) -> np.int_: ... @overload def ravel_multi_index( multi_index: Sequence[_ArrayLikeInt_co], dims: Sequence[SupportsIndex], - mode: _ModeKind | tuple[_ModeKind, ...] = ..., - order: _OrderCF = ..., -) -> NDArray[intp]: ... + mode: np._ModeKind | tuple[np._ModeKind, ...] = ..., + order: np._OrderCF = ..., +) -> NDArray[np.int_]: ... # NOTE: Allow any sequence of array-like objects @overload @@ -554,7 +503,7 @@ def concatenate( # type: ignore[misc] out: None = ..., *, dtype: None = ..., - casting: _CastingKind | None = ..., + casting: np._CastingKind | None = ..., ) -> NDArray[_SCT]: ... @overload def concatenate( # type: ignore[misc] @@ -564,7 +513,7 @@ def concatenate( # type: ignore[misc] out: None = ..., *, dtype: None = ..., - casting: _CastingKind | None = ..., + casting: np._CastingKind | None = ..., ) -> NDArray[Any]: ... @overload def concatenate( # type: ignore[misc] @@ -574,7 +523,7 @@ def concatenate( # type: ignore[misc] out: None = ..., *, dtype: _DTypeLike[_SCT], - casting: _CastingKind | None = ..., + casting: np._CastingKind | None = ..., ) -> NDArray[_SCT]: ... @overload def concatenate( # type: ignore[misc] @@ -584,119 +533,99 @@ def concatenate( # type: ignore[misc] out: None = ..., *, dtype: DTypeLike, - casting: _CastingKind | None = ..., + casting: np._CastingKind | None = ..., ) -> NDArray[Any]: ... @overload def concatenate( arrays: SupportsLenAndGetItem[ArrayLike], /, axis: SupportsIndex | None = ..., - out: _ArrayType = ..., + out: _ArrayT = ..., *, dtype: DTypeLike = ..., - casting: _CastingKind | None = ..., -) -> _ArrayType: ... -def inner( - a: ArrayLike, - b: ArrayLike, - /, -) -> Any: ... + casting: np._CastingKind | None = ..., +) -> _ArrayT: ... + +# +def inner(a: ArrayLike, b: ArrayLike, /) -> Any: ... + +# @overload -def where( - condition: ArrayLike, - /, -) -> tuple[NDArray[intp], ...]: ... +def where(condition: ArrayLike, /) -> tuple[NDArray[np.int_], ...]: ... @overload -def where( - condition: ArrayLike, - x: ArrayLike, - y: ArrayLike, - /, -) -> NDArray[Any]: ... -def lexsort( - keys: ArrayLike, - axis: SupportsIndex | None = ..., -) -> Any: ... -def can_cast( - from_: ArrayLike | DTypeLike, - to: DTypeLike, - casting: _CastingKind | None = ..., -) -> bool: ... -def min_scalar_type( - a: ArrayLike, - /, -) -> dtype[Any]: ... -def result_type( - *arrays_and_dtypes: ArrayLike | DTypeLike, -) -> dtype[Any]: ... +def where(condition: ArrayLike, x: ArrayLike, y: ArrayLike, /) -> NDArray[Any]: ... + +# +def lexsort(keys: ArrayLike, axis: SupportsIndex | None = ...) -> Any: ... +def can_cast(from_: ArrayLike | DTypeLike, to: DTypeLike, casting: np._CastingKind | None = ...) -> bool: ... +def min_scalar_type(a: ArrayLike, /) -> dtype[Any]: ... +def result_type(*arrays_and_dtypes: ArrayLike | DTypeLike) -> dtype[Any]: ... + +# @overload def dot(a: ArrayLike, b: ArrayLike, out: None = ...) -> Any: ... @overload -def dot(a: ArrayLike, b: ArrayLike, out: _ArrayType) -> _ArrayType: ... +def dot(a: ArrayLike, b: ArrayLike, out: _ArrayT) -> _ArrayT: ... + +# @overload def vdot(a: _ArrayLikeBool_co, b: _ArrayLikeBool_co, /) -> np.bool: ... # type: ignore[misc] @overload -def vdot(a: _ArrayLikeUInt_co, b: _ArrayLikeUInt_co, /) -> unsignedinteger[Any]: ... # type: ignore[misc] +def vdot(a: _ArrayLikeUInt_co, b: _ArrayLikeUInt_co, /) -> np.unsignedinteger: ... # type: ignore[misc] @overload -def vdot(a: _ArrayLikeInt_co, b: _ArrayLikeInt_co, /) -> signedinteger[Any]: ... # type: ignore[misc] +def vdot(a: _ArrayLikeInt_co, b: _ArrayLikeInt_co, /) -> np.signedinteger: ... # type: ignore[misc] @overload -def vdot(a: _ArrayLikeFloat_co, b: _ArrayLikeFloat_co, /) -> floating[Any]: ... # type: ignore[misc] +def vdot(a: _ArrayLikeFloat_co, b: _ArrayLikeFloat_co, /) -> np.floating: ... # type: ignore[misc] @overload -def vdot(a: _ArrayLikeComplex_co, b: _ArrayLikeComplex_co, /) -> complexfloating[Any, Any]: ... # type: ignore[misc] +def vdot(a: _ArrayLikeComplex_co, b: _ArrayLikeComplex_co, /) -> np.complexfloating: ... # type: ignore[misc] @overload -def vdot(a: _ArrayLikeTD64_co, b: _ArrayLikeTD64_co, /) -> timedelta64: ... +def vdot(a: _ArrayLikeTD64_co, b: _ArrayLikeTD64_co, /) -> np.timedelta64: ... @overload def vdot(a: _ArrayLikeObject_co, b: Any, /) -> Any: ... @overload def vdot(a: Any, b: _ArrayLikeObject_co, /) -> Any: ... -def bincount( - x: ArrayLike, - /, - weights: ArrayLike | None = ..., - minlength: SupportsIndex = ..., -) -> NDArray[intp]: ... + +# +def bincount(x: ArrayLike, /, weights: ArrayLike | None = ..., minlength: SupportsIndex = ...) -> NDArray[np.int_]: ... + +# def copyto( dst: NDArray[Any], src: ArrayLike, - casting: _CastingKind | None = ..., + casting: np._CastingKind | None = ..., where: _ArrayLikeBool_co | None = ..., ) -> None: ... -def putmask( - a: NDArray[Any], - /, - mask: _ArrayLikeBool_co, - values: ArrayLike, -) -> None: ... + +# +def putmask(a: NDArray[Any], /, mask: _ArrayLikeBool_co, values: ArrayLike) -> None: ... + +# def packbits( a: _ArrayLikeInt_co, /, axis: SupportsIndex | None = ..., bitorder: L["big", "little"] = ..., -) -> NDArray[uint8]: ... +) -> NDArray[np.uint8]: ... + +# def unpackbits( - a: _ArrayLike[uint8], + a: _ArrayLike[np.uint8], /, axis: SupportsIndex | None = ..., count: SupportsIndex | None = ..., bitorder: L["big", "little"] = ..., -) -> NDArray[uint8]: ... -def shares_memory( - a: object, - b: object, - /, - max_work: int | None = ..., -) -> bool: ... -def may_share_memory( - a: object, - b: object, - /, - max_work: int | None = ..., -) -> bool: ... +) -> NDArray[np.uint8]: ... + +# +def shares_memory(a: object, b: object, /, max_work: int | None = ...) -> bool: ... +def may_share_memory(a: object, b: object, /, max_work: int | None = ...) -> bool: ... + +# @overload def asarray( a: _ArrayLike[_SCT], dtype: None = ..., - order: _OrderKACF = ..., + order: np._OrderKACF = ..., *, device: L["cpu"] | None = ..., copy: bool | None = ..., @@ -706,7 +635,7 @@ def asarray( def asarray( a: object, dtype: None = ..., - order: _OrderKACF = ..., + order: np._OrderKACF = ..., *, device: L["cpu"] | None = ..., copy: bool | None = ..., @@ -716,7 +645,7 @@ def asarray( def asarray( a: Any, dtype: _DTypeLike[_SCT], - order: _OrderKACF = ..., + order: np._OrderKACF = ..., *, device: L["cpu"] | None = ..., copy: bool | None = ..., @@ -726,27 +655,29 @@ def asarray( def asarray( a: Any, dtype: DTypeLike, - order: _OrderKACF = ..., + order: np._OrderKACF = ..., *, device: L["cpu"] | None = ..., copy: bool | None = ..., like: _SupportsArrayFunc | None = ..., ) -> NDArray[Any]: ... + +# @overload def asanyarray( - a: _ArrayType, # Preserve subclass-information + a: _ArrayT, # Preserve subclass-information dtype: None = ..., - order: _OrderKACF = ..., + order: np._OrderKACF = ..., *, device: L["cpu"] | None = ..., copy: bool | None = ..., like: _SupportsArrayFunc | None = ..., -) -> _ArrayType: ... +) -> _ArrayT: ... @overload def asanyarray( a: _ArrayLike[_SCT], dtype: None = ..., - order: _OrderKACF = ..., + order: np._OrderKACF = ..., *, device: L["cpu"] | None = ..., copy: bool | None = ..., @@ -756,7 +687,7 @@ def asanyarray( def asanyarray( a: object, dtype: None = ..., - order: _OrderKACF = ..., + order: np._OrderKACF = ..., *, device: L["cpu"] | None = ..., copy: bool | None = ..., @@ -766,7 +697,7 @@ def asanyarray( def asanyarray( a: Any, dtype: _DTypeLike[_SCT], - order: _OrderKACF = ..., + order: np._OrderKACF = ..., *, device: L["cpu"] | None = ..., copy: bool | None = ..., @@ -776,69 +707,35 @@ def asanyarray( def asanyarray( a: Any, dtype: DTypeLike, - order: _OrderKACF = ..., + order: np._OrderKACF = ..., *, device: L["cpu"] | None = ..., copy: bool | None = ..., like: _SupportsArrayFunc | None = ..., ) -> NDArray[Any]: ... + +# @overload -def ascontiguousarray( - a: _ArrayLike[_SCT], - dtype: None = ..., - *, - like: _SupportsArrayFunc | None = ..., -) -> NDArray[_SCT]: ... +def ascontiguousarray(a: _ArrayLike[_SCT], dtype: None = ..., *, like: _SupportsArrayFunc | None = ...) -> NDArray[_SCT]: ... @overload -def ascontiguousarray( - a: object, - dtype: None = ..., - *, - like: _SupportsArrayFunc | None = ..., -) -> NDArray[Any]: ... +def ascontiguousarray(a: object, dtype: None = ..., *, like: _SupportsArrayFunc | None = ...) -> NDArray[Any]: ... @overload -def ascontiguousarray( - a: Any, - dtype: _DTypeLike[_SCT], - *, - like: _SupportsArrayFunc | None = ..., -) -> NDArray[_SCT]: ... +def ascontiguousarray(a: Any, dtype: _DTypeLike[_SCT], *, like: _SupportsArrayFunc | None = ...) -> NDArray[_SCT]: ... @overload -def ascontiguousarray( - a: Any, - dtype: DTypeLike, - *, - like: _SupportsArrayFunc | None = ..., -) -> NDArray[Any]: ... +def ascontiguousarray(a: Any, dtype: DTypeLike, *, like: _SupportsArrayFunc | None = ...) -> NDArray[Any]: ... + +# @overload -def asfortranarray( - a: _ArrayLike[_SCT], - dtype: None = ..., - *, - like: _SupportsArrayFunc | None = ..., -) -> NDArray[_SCT]: ... +def asfortranarray(a: _ArrayLike[_SCT], dtype: None = ..., *, like: _SupportsArrayFunc | None = ...) -> NDArray[_SCT]: ... @overload -def asfortranarray( - a: object, - dtype: None = ..., - *, - like: _SupportsArrayFunc | None = ..., -) -> NDArray[Any]: ... +def asfortranarray(a: object, dtype: None = ..., *, like: _SupportsArrayFunc | None = ...) -> NDArray[Any]: ... @overload -def asfortranarray( - a: Any, - dtype: _DTypeLike[_SCT], - *, - like: _SupportsArrayFunc | None = ..., -) -> NDArray[_SCT]: ... +def asfortranarray(a: Any, dtype: _DTypeLike[_SCT], *, like: _SupportsArrayFunc | None = ...) -> NDArray[_SCT]: ... @overload -def asfortranarray( - a: Any, - dtype: DTypeLike, - *, - like: _SupportsArrayFunc | None = ..., -) -> NDArray[Any]: ... -def promote_types(__type1: DTypeLike, __type2: DTypeLike) -> dtype[Any]: ... +def asfortranarray(a: Any, dtype: DTypeLike, *, like: _SupportsArrayFunc | None = ...) -> NDArray[Any]: ... + +# +def promote_types(type1: DTypeLike, type2: DTypeLike, /) -> dtype[Any]: ... # `sep` is a de facto mandatory argument, as its default value is deprecated @overload @@ -849,7 +746,7 @@ def fromstring( *, sep: str, like: _SupportsArrayFunc | None = ..., -) -> NDArray[float64]: ... +) -> NDArray[np.float64]: ... @overload def fromstring( string: str | bytes, @@ -868,78 +765,80 @@ def fromstring( sep: str, like: _SupportsArrayFunc | None = ..., ) -> NDArray[Any]: ... + +# @overload -def frompyfunc( # type: ignore[overload-overlap] - func: Callable[[Any], _ReturnType], +def frompyfunc( + func: Callable[[Any], _ReturnT], /, nin: L[1], nout: L[1], *, identity: None = ..., -) -> _PyFunc_Nin1_Nout1[_ReturnType, None]: ... +) -> _PyFunc_Nin1_Nout1[_ReturnT, None]: ... @overload -def frompyfunc( # type: ignore[overload-overlap] - func: Callable[[Any], _ReturnType], +def frompyfunc( + func: Callable[[Any], _ReturnT], /, nin: L[1], nout: L[1], *, - identity: _IDType, -) -> _PyFunc_Nin1_Nout1[_ReturnType, _IDType]: ... + identity: _IdentityT, +) -> _PyFunc_Nin1_Nout1[_ReturnT, _IdentityT]: ... @overload -def frompyfunc( # type: ignore[overload-overlap] - func: Callable[[Any, Any], _ReturnType], +def frompyfunc( + func: Callable[[Any, Any], _ReturnT], /, nin: L[2], nout: L[1], *, identity: None = ..., -) -> _PyFunc_Nin2_Nout1[_ReturnType, None]: ... +) -> _PyFunc_Nin2_Nout1[_ReturnT, None]: ... @overload -def frompyfunc( # type: ignore[overload-overlap] - func: Callable[[Any, Any], _ReturnType], +def frompyfunc( + func: Callable[[Any, Any], _ReturnT], /, nin: L[2], nout: L[1], *, - identity: _IDType, -) -> _PyFunc_Nin2_Nout1[_ReturnType, _IDType]: ... + identity: _IdentityT, +) -> _PyFunc_Nin2_Nout1[_ReturnT, _IdentityT]: ... @overload -def frompyfunc( # type: ignore[overload-overlap] - func: Callable[..., _ReturnType], +def frompyfunc( + func: Callable[..., _ReturnT], /, - nin: _Nin, + nin: _NInT, nout: L[1], *, identity: None = ..., -) -> _PyFunc_Nin3P_Nout1[_ReturnType, None, _Nin]: ... +) -> _PyFunc_Nin3P_Nout1[_ReturnT, None, _NInT]: ... @overload -def frompyfunc( # type: ignore[overload-overlap] - func: Callable[..., _ReturnType], +def frompyfunc( + func: Callable[..., _ReturnT], /, - nin: _Nin, + nin: _NInT, nout: L[1], *, - identity: _IDType, -) -> _PyFunc_Nin3P_Nout1[_ReturnType, _IDType, _Nin]: ... + identity: _IdentityT, +) -> _PyFunc_Nin3P_Nout1[_ReturnT, _IdentityT, _NInT]: ... @overload def frompyfunc( - func: Callable[..., _2PTuple[_ReturnType]], + func: Callable[..., _2PTuple[_ReturnT]], /, - nin: _Nin, - nout: _Nout, + nin: _NInT, + nout: _NOutT, *, identity: None = ..., -) -> _PyFunc_Nin1P_Nout2P[_ReturnType, None, _Nin, _Nout]: ... +) -> _PyFunc_Nin1P_Nout2P[_ReturnT, None, _NInT, _NOutT]: ... @overload def frompyfunc( - func: Callable[..., _2PTuple[_ReturnType]], + func: Callable[..., _2PTuple[_ReturnT]], /, - nin: _Nin, - nout: _Nout, + nin: _NInT, + nout: _NOutT, *, - identity: _IDType, -) -> _PyFunc_Nin1P_Nout2P[_ReturnType, _IDType, _Nin, _Nout]: ... + identity: _IdentityT, +) -> _PyFunc_Nin1P_Nout2P[_ReturnT, _IdentityT, _NInT, _NOutT]: ... @overload def frompyfunc( func: Callable[..., Any], @@ -949,19 +848,21 @@ def frompyfunc( *, identity: object | None = ..., ) -> ufunc: ... + +# @overload def fromfile( - file: StrOrBytesPath | _SupportsFileMethods, + file: StrOrBytesPath | np._SupportsFileMethods, dtype: None = ..., count: SupportsIndex = ..., sep: str = ..., offset: SupportsIndex = ..., *, like: _SupportsArrayFunc | None = ..., -) -> NDArray[float64]: ... +) -> NDArray[np.float64]: ... @overload def fromfile( - file: StrOrBytesPath | _SupportsFileMethods, + file: StrOrBytesPath | np._SupportsFileMethods, dtype: _DTypeLike[_SCT], count: SupportsIndex = ..., sep: str = ..., @@ -971,7 +872,7 @@ def fromfile( ) -> NDArray[_SCT]: ... @overload def fromfile( - file: StrOrBytesPath | _SupportsFileMethods, + file: StrOrBytesPath | np._SupportsFileMethods, dtype: DTypeLike, count: SupportsIndex = ..., sep: str = ..., @@ -979,6 +880,8 @@ def fromfile( *, like: _SupportsArrayFunc | None = ..., ) -> NDArray[Any]: ... + +# @overload def fromiter( iter: Iterable[Any], @@ -995,18 +898,20 @@ def fromiter( *, like: _SupportsArrayFunc | None = ..., ) -> NDArray[Any]: ... + +# @overload def frombuffer( - buffer: _SupportsBuffer, + buffer: np._SupportsBuffer, dtype: None = ..., count: SupportsIndex = ..., offset: SupportsIndex = ..., *, like: _SupportsArrayFunc | None = ..., -) -> NDArray[float64]: ... +) -> NDArray[np.float64]: ... @overload def frombuffer( - buffer: _SupportsBuffer, + buffer: np._SupportsBuffer, dtype: _DTypeLike[_SCT], count: SupportsIndex = ..., offset: SupportsIndex = ..., @@ -1015,13 +920,15 @@ def frombuffer( ) -> NDArray[_SCT]: ... @overload def frombuffer( - buffer: _SupportsBuffer, + buffer: np._SupportsBuffer, dtype: DTypeLike, count: SupportsIndex = ..., offset: SupportsIndex = ..., *, like: _SupportsArrayFunc | None = ..., ) -> NDArray[Any]: ... + +# @overload def arange( # type: ignore[misc] stop: _IntLike_co, @@ -1030,7 +937,7 @@ def arange( # type: ignore[misc] dtype: None = ..., device: L["cpu"] | None = ..., like: _SupportsArrayFunc | None = ..., -) -> _1DArray[int, signedinteger[Any]]: ... +) -> _Array1D[int, np.signedinteger]: ... @overload def arange( # type: ignore[misc] start: _IntLike_co, @@ -1040,7 +947,7 @@ def arange( # type: ignore[misc] *, device: L["cpu"] | None = ..., like: _SupportsArrayFunc | None = ..., -) -> _1DArray[int, signedinteger[Any]]: ... +) -> _Array1D[int, np.signedinteger]: ... @overload def arange( # type: ignore[misc] stop: _FloatLike_co, @@ -1049,7 +956,7 @@ def arange( # type: ignore[misc] dtype: None = ..., device: L["cpu"] | None = ..., like: _SupportsArrayFunc | None = ..., -) -> _1DArray[int, floating[Any]]: ... +) -> _Array1D[int, np.floating]: ... @overload def arange( # type: ignore[misc] start: _FloatLike_co, @@ -1059,7 +966,7 @@ def arange( # type: ignore[misc] *, device: L["cpu"] | None = ..., like: _SupportsArrayFunc | None = ..., -) -> _1DArray[int, floating[Any]]: ... +) -> _Array1D[int, np.floating]: ... @overload def arange( stop: _TD64Like_co, @@ -1068,7 +975,7 @@ def arange( dtype: None = ..., device: L["cpu"] | None = ..., like: _SupportsArrayFunc | None = ..., -) -> _1DArray[int, timedelta64]: ... +) -> _Array1D[int, np.timedelta64]: ... @overload def arange( start: _TD64Like_co, @@ -1078,17 +985,17 @@ def arange( *, device: L["cpu"] | None = ..., like: _SupportsArrayFunc | None = ..., -) -> _1DArray[int, timedelta64]: ... +) -> _Array1D[int, np.timedelta64]: ... @overload -def arange( # both start and stop must always be specified for datetime64 - start: datetime64, - stop: datetime64, - step: datetime64 = ..., +def arange( # both start and stop must always be specified for np.datetime64 + start: np.datetime64, + stop: np.datetime64, + step: np.datetime64 = ..., dtype: None = ..., *, device: L["cpu"] | None = ..., like: _SupportsArrayFunc | None = ..., -) -> _1DArray[int, datetime64]: ... +) -> _Array1D[int, np.datetime64]: ... @overload def arange( stop: Any, @@ -1097,7 +1004,7 @@ def arange( dtype: _DTypeLike[_SCT], device: L["cpu"] | None = ..., like: _SupportsArrayFunc | None = ..., -) -> _1DArray[int, _SCT]: ... +) -> _Array1D[int, _SCT]: ... @overload def arange( start: Any, @@ -1107,7 +1014,7 @@ def arange( *, device: L["cpu"] | None = ..., like: _SupportsArrayFunc | None = ..., -) -> _1DArray[int, _SCT]: ... +) -> _Array1D[int, _SCT]: ... @overload def arange( stop: Any, @@ -1116,7 +1023,7 @@ def arange( dtype: DTypeLike, device: L["cpu"] | None = ..., like: _SupportsArrayFunc | None = ..., -) -> _1DArray[int, Any]: ... +) -> _Array1D[int, Any]: ... @overload def arange( start: Any, @@ -1126,13 +1033,12 @@ def arange( *, device: L["cpu"] | None = ..., like: _SupportsArrayFunc | None = ..., -) -> _1DArray[int, Any]: ... -def datetime_data( - dtype: str | _DTypeLike[datetime64] | _DTypeLike[timedelta64], - /, -) -> tuple[str, int]: ... +) -> _Array1D[int, Any]: ... + +# +def datetime_data(dtype: str | _DTypeLike[np.datetime64] | _DTypeLike[np.timedelta64], /) -> tuple[str, int]: ... -# The datetime functions perform unsafe casts to `datetime64[D]`, +# The datetime functions perform unsafe casts to `np.datetime64[D]`, # so a lot of different argument types are allowed here @overload @@ -1143,7 +1049,7 @@ def busday_count( # type: ignore[misc] holidays: ArrayLike | dt.date | _NestedSequence[dt.date] | None = ..., busdaycal: busdaycalendar | None = ..., out: None = ..., -) -> int_: ... +) -> np.int_: ... @overload def busday_count( # type: ignore[misc] begindates: ArrayLike | dt.date | _NestedSequence[dt.date], @@ -1152,7 +1058,7 @@ def busday_count( # type: ignore[misc] holidays: ArrayLike | dt.date | _NestedSequence[dt.date] | None = ..., busdaycal: busdaycalendar | None = ..., out: None = ..., -) -> NDArray[int_]: ... +) -> NDArray[np.int_]: ... @overload def busday_count( begindates: ArrayLike | dt.date | _NestedSequence[dt.date], @@ -1160,40 +1066,40 @@ def busday_count( weekmask: ArrayLike = ..., holidays: ArrayLike | dt.date | _NestedSequence[dt.date] | None = ..., busdaycal: busdaycalendar | None = ..., - out: _ArrayType = ..., -) -> _ArrayType: ... + out: _ArrayT = ..., +) -> _ArrayT: ... # `roll="raise"` is (more or less?) equivalent to `casting="safe"` @overload def busday_offset( # type: ignore[misc] - dates: datetime64 | dt.date, + dates: np.datetime64 | dt.date, offsets: _TD64Like_co | dt.timedelta, roll: L["raise"] = ..., weekmask: ArrayLike = ..., holidays: ArrayLike | dt.date | _NestedSequence[dt.date] | None = ..., busdaycal: busdaycalendar | None = ..., out: None = ..., -) -> datetime64: ... +) -> np.datetime64: ... @overload def busday_offset( # type: ignore[misc] - dates: _ArrayLike[datetime64] | dt.date | _NestedSequence[dt.date], + dates: _ArrayLike[np.datetime64] | dt.date | _NestedSequence[dt.date], offsets: _ArrayLikeTD64_co | dt.timedelta | _NestedSequence[dt.timedelta], roll: L["raise"] = ..., weekmask: ArrayLike = ..., holidays: ArrayLike | dt.date | _NestedSequence[dt.date] | None = ..., busdaycal: busdaycalendar | None = ..., out: None = ..., -) -> NDArray[datetime64]: ... +) -> NDArray[np.datetime64]: ... @overload def busday_offset( # type: ignore[misc] - dates: _ArrayLike[datetime64] | dt.date | _NestedSequence[dt.date], + dates: _ArrayLike[np.datetime64] | dt.date | _NestedSequence[dt.date], offsets: _ArrayLikeTD64_co | dt.timedelta | _NestedSequence[dt.timedelta], roll: L["raise"] = ..., weekmask: ArrayLike = ..., holidays: ArrayLike | dt.date | _NestedSequence[dt.date] | None = ..., busdaycal: busdaycalendar | None = ..., - out: _ArrayType = ..., -) -> _ArrayType: ... + out: _ArrayT = ..., +) -> _ArrayT: ... @overload def busday_offset( # type: ignore[misc] dates: _ScalarLike_co | dt.date, @@ -1203,7 +1109,7 @@ def busday_offset( # type: ignore[misc] holidays: ArrayLike | dt.date | _NestedSequence[dt.date] | None = ..., busdaycal: busdaycalendar | None = ..., out: None = ..., -) -> datetime64: ... +) -> np.datetime64: ... @overload def busday_offset( # type: ignore[misc] dates: ArrayLike | dt.date | _NestedSequence[dt.date], @@ -1213,7 +1119,7 @@ def busday_offset( # type: ignore[misc] holidays: ArrayLike | dt.date | _NestedSequence[dt.date] | None = ..., busdaycal: busdaycalendar | None = ..., out: None = ..., -) -> NDArray[datetime64]: ... +) -> NDArray[np.datetime64]: ... @overload def busday_offset( dates: ArrayLike | dt.date | _NestedSequence[dt.date], @@ -1222,8 +1128,8 @@ def busday_offset( weekmask: ArrayLike = ..., holidays: ArrayLike | dt.date | _NestedSequence[dt.date] | None = ..., busdaycal: busdaycalendar | None = ..., - out: _ArrayType = ..., -) -> _ArrayType: ... + out: _ArrayT = ..., +) -> _ArrayT: ... @overload def is_busday( # type: ignore[misc] dates: _ScalarLike_co | dt.date, @@ -1246,22 +1152,22 @@ def is_busday( weekmask: ArrayLike = ..., holidays: ArrayLike | dt.date | _NestedSequence[dt.date] | None = ..., busdaycal: busdaycalendar | None = ..., - out: _ArrayType = ..., -) -> _ArrayType: ... + out: _ArrayT = ..., +) -> _ArrayT: ... @overload def datetime_as_string( # type: ignore[misc] - arr: datetime64 | dt.date, + arr: np.datetime64 | dt.date, unit: L["auto"] | _UnitKind | None = ..., timezone: L["naive", "UTC", "local"] | dt.tzinfo = ..., - casting: _CastingKind = ..., -) -> str_: ... + casting: np._CastingKind = ..., +) -> np.str_: ... @overload def datetime_as_string( arr: _ArrayLikeDT64_co | _NestedSequence[dt.date], unit: L["auto"] | _UnitKind | None = ..., timezone: L["naive", "UTC", "local"] | dt.tzinfo = ..., - casting: _CastingKind = ..., -) -> NDArray[str_]: ... + casting: np._CastingKind = ..., +) -> NDArray[np.str_]: ... @overload def compare_chararrays( a1: _ArrayLikeStr_co, @@ -1315,8 +1221,6 @@ _SetItemKeys: TypeAlias = L[ class flagsobj: __hash__: ClassVar[None] # type: ignore[assignment] aligned: bool - # NOTE: deprecated - # updateifcopy: bool writeable: bool writebackifcopy: bool @property @@ -1347,10 +1251,10 @@ class flagsobj: def nested_iters( op: ArrayLike | Sequence[ArrayLike], axes: Sequence[Sequence[SupportsIndex]], - flags: Sequence[_NDIterFlagsKind] | None = ..., - op_flags: Sequence[Sequence[_NDIterFlagsOp]] | None = ..., + flags: Sequence[np._NDIterFlagsKind] | None = ..., + op_flags: Sequence[Sequence[np._NDIterFlagsOp]] | None = ..., op_dtypes: DTypeLike | Sequence[DTypeLike] = ..., - order: _OrderKACF = ..., - casting: _CastingKind = ..., + order: np._OrderKACF = ..., + casting: np._CastingKind = ..., buffersize: SupportsIndex = ..., ) -> tuple[nditer, ...]: ... diff --git a/src/numpy-stubs/_core/numeric.pyi b/src/numpy-stubs/_core/numeric.pyi index c95d2a72..4b6b1ab3 100644 --- a/src/numpy-stubs/_core/numeric.pyi +++ b/src/numpy-stubs/_core/numeric.pyi @@ -7,43 +7,28 @@ from typing import ( SupportsAbs, SupportsIndex, TypeAlias, - TypeGuard, TypeVar, overload, ) -from typing_extensions import Unpack +from typing_extensions import TypeIs, Unpack import numpy as np -from numpy import ( +from numpy import ( # noqa: ICN003 False_, True_, - _OrderCF, - _OrderKACF, - # re-exports bitwise_not, broadcast, - complexfloating, dtype, flatiter, - float64, - floating, from_dlpack, - # other - generic, inf, - int_, - intp, little_endian, matmul, nan, ndarray, nditer, newaxis, - object_, - signedinteger, - timedelta64, ufunc, - unsignedinteger, vecdot, ) from numpy._typing import ( @@ -178,29 +163,29 @@ __all__ = [ ] _T = TypeVar("_T") -_SCT = TypeVar("_SCT", bound=generic) -_DType = TypeVar("_DType", bound=np.dtype[Any]) -_ArrayType = TypeVar("_ArrayType", bound=np.ndarray[Any, Any]) -_SizeType = TypeVar("_SizeType", bound=int) -_ShapeType = TypeVar("_ShapeType", bound=tuple[int, ...]) +_SCT = TypeVar("_SCT", bound=np.generic) +_DTypeT = TypeVar("_DTypeT", bound=np.dtype[Any]) +_ArrayT = TypeVar("_ArrayT", bound=np.ndarray[Any, Any]) +_SizeT = TypeVar("_SizeT", bound=int) +_ShapeT = TypeVar("_ShapeT", bound=tuple[int, ...]) _CorrelateMode: TypeAlias = L["valid", "same", "full"] @overload def zeros_like( - a: _ArrayType, + a: _ArrayT, dtype: None = ..., - order: _OrderKACF = ..., + order: np._OrderKACF = ..., subok: L[True] = ..., shape: None = ..., *, device: L["cpu"] | None = ..., -) -> _ArrayType: ... +) -> _ArrayT: ... @overload def zeros_like( a: _ArrayLike[_SCT], dtype: None = ..., - order: _OrderKACF = ..., + order: np._OrderKACF = ..., subok: bool = ..., shape: _ShapeLike | None = ..., *, @@ -210,7 +195,7 @@ def zeros_like( def zeros_like( a: object, dtype: None = ..., - order: _OrderKACF = ..., + order: np._OrderKACF = ..., subok: bool = ..., shape: _ShapeLike | None = ..., *, @@ -220,7 +205,7 @@ def zeros_like( def zeros_like( a: Any, dtype: _DTypeLike[_SCT], - order: _OrderKACF = ..., + order: np._OrderKACF = ..., subok: bool = ..., shape: _ShapeLike | None = ..., *, @@ -230,7 +215,7 @@ def zeros_like( def zeros_like( a: Any, dtype: DTypeLike, - order: _OrderKACF = ..., + order: np._OrderKACF = ..., subok: bool = ..., shape: _ShapeLike | None = ..., *, @@ -241,19 +226,19 @@ ones: Final[_ConstructorEmpty] @overload def ones_like( - a: _ArrayType, + a: _ArrayT, dtype: None = ..., - order: _OrderKACF = ..., + order: np._OrderKACF = ..., subok: L[True] = ..., shape: None = ..., *, device: L["cpu"] | None = ..., -) -> _ArrayType: ... +) -> _ArrayT: ... @overload def ones_like( a: _ArrayLike[_SCT], dtype: None = ..., - order: _OrderKACF = ..., + order: np._OrderKACF = ..., subok: bool = ..., shape: _ShapeLike | None = ..., *, @@ -263,7 +248,7 @@ def ones_like( def ones_like( a: object, dtype: None = ..., - order: _OrderKACF = ..., + order: np._OrderKACF = ..., subok: bool = ..., shape: _ShapeLike | None = ..., *, @@ -273,7 +258,7 @@ def ones_like( def ones_like( a: Any, dtype: _DTypeLike[_SCT], - order: _OrderKACF = ..., + order: np._OrderKACF = ..., subok: bool = ..., shape: _ShapeLike | None = ..., *, @@ -283,7 +268,7 @@ def ones_like( def ones_like( a: Any, dtype: DTypeLike, - order: _OrderKACF = ..., + order: np._OrderKACF = ..., subok: bool = ..., shape: _ShapeLike | None = ..., *, @@ -291,97 +276,92 @@ def ones_like( ) -> NDArray[Any]: ... # TODO: Add overloads for bool, int, float, complex, str, bytes, and memoryview -# 1-D shape @overload def full( - shape: _SizeType, + shape: _SizeT, fill_value: _SCT, dtype: None = ..., - order: _OrderCF = ..., + order: np._OrderCF = ..., **kwargs: Unpack[_KwargsEmpty], -) -> _Array[tuple[_SizeType], _SCT]: ... +) -> _Array[tuple[_SizeT], _SCT]: ... @overload def full( - shape: _SizeType, + shape: _SizeT, fill_value: Any, - dtype: _DType | _SupportsDType[_DType], - order: _OrderCF = ..., + dtype: _DTypeT | _SupportsDType[_DTypeT], + order: np._OrderCF = ..., **kwargs: Unpack[_KwargsEmpty], -) -> np.ndarray[tuple[_SizeType], _DType]: ... +) -> np.ndarray[tuple[_SizeT], _DTypeT]: ... @overload def full( - shape: _SizeType, + shape: _SizeT, fill_value: Any, dtype: type[_SCT], - order: _OrderCF = ..., + order: np._OrderCF = ..., **kwargs: Unpack[_KwargsEmpty], -) -> _Array[tuple[_SizeType], _SCT]: ... +) -> _Array[tuple[_SizeT], _SCT]: ... @overload def full( - shape: _SizeType, + shape: _SizeT, fill_value: Any, dtype: DTypeLike | None = ..., - order: _OrderCF = ..., + order: np._OrderCF = ..., **kwargs: Unpack[_KwargsEmpty], -) -> _Array[tuple[_SizeType], Any]: ... - -# known shape +) -> _Array[tuple[_SizeT], Any]: ... @overload def full( - shape: _ShapeType, + shape: _ShapeT, fill_value: _SCT, dtype: None = ..., - order: _OrderCF = ..., + order: np._OrderCF = ..., **kwargs: Unpack[_KwargsEmpty], -) -> _Array[_ShapeType, _SCT]: ... +) -> _Array[_ShapeT, _SCT]: ... @overload def full( - shape: _ShapeType, + shape: _ShapeT, fill_value: Any, - dtype: _DType | _SupportsDType[_DType], - order: _OrderCF = ..., + dtype: _DTypeT | _SupportsDType[_DTypeT], + order: np._OrderCF = ..., **kwargs: Unpack[_KwargsEmpty], -) -> np.ndarray[_ShapeType, _DType]: ... +) -> np.ndarray[_ShapeT, _DTypeT]: ... @overload def full( - shape: _ShapeType, + shape: _ShapeT, fill_value: Any, dtype: type[_SCT], - order: _OrderCF = ..., + order: np._OrderCF = ..., **kwargs: Unpack[_KwargsEmpty], -) -> _Array[_ShapeType, _SCT]: ... +) -> _Array[_ShapeT, _SCT]: ... @overload def full( - shape: _ShapeType, + shape: _ShapeT, fill_value: Any, dtype: DTypeLike | None = ..., - order: _OrderCF = ..., + order: np._OrderCF = ..., **kwargs: Unpack[_KwargsEmpty], -) -> _Array[_ShapeType, Any]: ... - -# unknown shape +) -> _Array[_ShapeT, Any]: ... @overload def full( shape: _ShapeLike, fill_value: _SCT, dtype: None = ..., - order: _OrderCF = ..., + order: np._OrderCF = ..., **kwargs: Unpack[_KwargsEmpty], ) -> NDArray[_SCT]: ... @overload def full( shape: _ShapeLike, fill_value: Any, - dtype: _DType | _SupportsDType[_DType], - order: _OrderCF = ..., + dtype: _DTypeT | _SupportsDType[_DTypeT], + order: np._OrderCF = ..., **kwargs: Unpack[_KwargsEmpty], -) -> np.ndarray[Any, _DType]: ... +) -> np.ndarray[Any, _DTypeT]: ... @overload def full( shape: _ShapeLike, fill_value: Any, dtype: type[_SCT], - order: _OrderCF = ..., + order: np._OrderCF = ..., **kwargs: Unpack[_KwargsEmpty], ) -> NDArray[_SCT]: ... @overload @@ -389,26 +369,28 @@ def full( shape: _ShapeLike, fill_value: Any, dtype: DTypeLike | None = ..., - order: _OrderCF = ..., + order: np._OrderCF = ..., **kwargs: Unpack[_KwargsEmpty], ) -> NDArray[Any]: ... + +# @overload def full_like( - a: _ArrayType, + a: _ArrayT, fill_value: Any, dtype: None = ..., - order: _OrderKACF = ..., + order: np._OrderKACF = ..., subok: L[True] = ..., shape: None = ..., *, device: L["cpu"] | None = ..., -) -> _ArrayType: ... +) -> _ArrayT: ... @overload def full_like( a: _ArrayLike[_SCT], fill_value: Any, dtype: None = ..., - order: _OrderKACF = ..., + order: np._OrderKACF = ..., subok: bool = ..., shape: _ShapeLike | None = ..., *, @@ -419,7 +401,7 @@ def full_like( a: object, fill_value: Any, dtype: None = ..., - order: _OrderKACF = ..., + order: np._OrderKACF = ..., subok: bool = ..., shape: _ShapeLike | None = ..., *, @@ -430,7 +412,7 @@ def full_like( a: Any, fill_value: Any, dtype: _DTypeLike[_SCT], - order: _OrderKACF = ..., + order: np._OrderKACF = ..., subok: bool = ..., shape: _ShapeLike | None = ..., *, @@ -441,179 +423,85 @@ def full_like( a: Any, fill_value: Any, dtype: DTypeLike, - order: _OrderKACF = ..., + order: np._OrderKACF = ..., subok: bool = ..., shape: _ShapeLike | None = ..., *, device: L["cpu"] | None = ..., ) -> NDArray[Any]: ... + +# @overload -def count_nonzero( - a: ArrayLike, - axis: None = ..., - *, - keepdims: L[False] = ..., -) -> int: ... +def count_nonzero(a: ArrayLike, axis: None = ..., *, keepdims: L[False] = ...) -> int: ... @overload -def count_nonzero( - a: ArrayLike, - axis: _ShapeLike = ..., - *, - keepdims: bool = ..., -) -> Any: ... # TODO: np.intp or ndarray[np.intp] -def isfortran(a: NDArray[Any] | generic) -> bool: ... -def argwhere(a: ArrayLike) -> NDArray[intp]: ... -def flatnonzero(a: ArrayLike) -> NDArray[intp]: ... +def count_nonzero(a: ArrayLike, axis: _ShapeLike = ..., *, keepdims: bool = ...) -> Any: ... + +# +def isfortran(a: NDArray[Any] | np.generic) -> bool: ... +def argwhere(a: ArrayLike) -> NDArray[np.int_]: ... +def flatnonzero(a: ArrayLike) -> NDArray[np.int_]: ... + +# @overload -def correlate( - a: _ArrayLikeUnknown, - v: _ArrayLikeUnknown, - mode: _CorrelateMode = ..., -) -> NDArray[Any]: ... +def correlate(a: _ArrayLikeUnknown, v: _ArrayLikeUnknown, mode: _CorrelateMode = ...) -> NDArray[Any]: ... @overload -def correlate( - a: _ArrayLikeBool_co, - v: _ArrayLikeBool_co, - mode: _CorrelateMode = ..., -) -> NDArray[np.bool]: ... +def correlate(a: _ArrayLikeBool_co, v: _ArrayLikeBool_co, mode: _CorrelateMode = ...) -> NDArray[np.bool]: ... @overload -def correlate( - a: _ArrayLikeUInt_co, - v: _ArrayLikeUInt_co, - mode: _CorrelateMode = ..., -) -> NDArray[unsignedinteger[Any]]: ... +def correlate(a: _ArrayLikeUInt_co, v: _ArrayLikeUInt_co, mode: _CorrelateMode = ...) -> NDArray[np.unsignedinteger]: ... @overload -def correlate( - a: _ArrayLikeInt_co, - v: _ArrayLikeInt_co, - mode: _CorrelateMode = ..., -) -> NDArray[signedinteger[Any]]: ... +def correlate(a: _ArrayLikeInt_co, v: _ArrayLikeInt_co, mode: _CorrelateMode = ...) -> NDArray[np.signedinteger]: ... @overload -def correlate( - a: _ArrayLikeFloat_co, - v: _ArrayLikeFloat_co, - mode: _CorrelateMode = ..., -) -> NDArray[floating[Any]]: ... +def correlate(a: _ArrayLikeFloat_co, v: _ArrayLikeFloat_co, mode: _CorrelateMode = ...) -> NDArray[np.floating]: ... @overload -def correlate( - a: _ArrayLikeComplex_co, - v: _ArrayLikeComplex_co, - mode: _CorrelateMode = ..., -) -> NDArray[complexfloating[Any, Any]]: ... +def correlate(a: _ArrayLikeComplex_co, v: _ArrayLikeComplex_co, mode: _CorrelateMode = ...) -> NDArray[np.complexfloating]: ... @overload -def correlate( - a: _ArrayLikeTD64_co, - v: _ArrayLikeTD64_co, - mode: _CorrelateMode = ..., -) -> NDArray[timedelta64]: ... +def correlate(a: _ArrayLikeTD64_co, v: _ArrayLikeTD64_co, mode: _CorrelateMode = ...) -> NDArray[np.timedelta64]: ... @overload -def correlate( - a: _ArrayLikeObject_co, - v: _ArrayLikeObject_co, - mode: _CorrelateMode = ..., -) -> NDArray[object_]: ... +def correlate(a: _ArrayLikeObject_co, v: _ArrayLikeObject_co, mode: _CorrelateMode = ...) -> NDArray[np.object_]: ... + +# @overload -def convolve( - a: _ArrayLikeUnknown, - v: _ArrayLikeUnknown, - mode: _CorrelateMode = ..., -) -> NDArray[Any]: ... +def convolve(a: _ArrayLikeUnknown, v: _ArrayLikeUnknown, mode: _CorrelateMode = ...) -> NDArray[Any]: ... @overload -def convolve( - a: _ArrayLikeBool_co, - v: _ArrayLikeBool_co, - mode: _CorrelateMode = ..., -) -> NDArray[np.bool]: ... +def convolve(a: _ArrayLikeBool_co, v: _ArrayLikeBool_co, mode: _CorrelateMode = ...) -> NDArray[np.bool]: ... @overload -def convolve( - a: _ArrayLikeUInt_co, - v: _ArrayLikeUInt_co, - mode: _CorrelateMode = ..., -) -> NDArray[unsignedinteger[Any]]: ... +def convolve(a: _ArrayLikeUInt_co, v: _ArrayLikeUInt_co, mode: _CorrelateMode = ...) -> NDArray[np.unsignedinteger]: ... @overload -def convolve( - a: _ArrayLikeInt_co, - v: _ArrayLikeInt_co, - mode: _CorrelateMode = ..., -) -> NDArray[signedinteger[Any]]: ... +def convolve(a: _ArrayLikeInt_co, v: _ArrayLikeInt_co, mode: _CorrelateMode = ...) -> NDArray[np.signedinteger]: ... @overload -def convolve( - a: _ArrayLikeFloat_co, - v: _ArrayLikeFloat_co, - mode: _CorrelateMode = ..., -) -> NDArray[floating[Any]]: ... +def convolve(a: _ArrayLikeFloat_co, v: _ArrayLikeFloat_co, mode: _CorrelateMode = ...) -> NDArray[np.floating]: ... @overload -def convolve( - a: _ArrayLikeComplex_co, - v: _ArrayLikeComplex_co, - mode: _CorrelateMode = ..., -) -> NDArray[complexfloating[Any, Any]]: ... +def convolve(a: _ArrayLikeComplex_co, v: _ArrayLikeComplex_co, mode: _CorrelateMode = ...) -> NDArray[np.complexfloating]: ... @overload -def convolve( - a: _ArrayLikeTD64_co, - v: _ArrayLikeTD64_co, - mode: _CorrelateMode = ..., -) -> NDArray[timedelta64]: ... +def convolve(a: _ArrayLikeTD64_co, v: _ArrayLikeTD64_co, mode: _CorrelateMode = ...) -> NDArray[np.timedelta64]: ... @overload -def convolve( - a: _ArrayLikeObject_co, - v: _ArrayLikeObject_co, - mode: _CorrelateMode = ..., -) -> NDArray[object_]: ... +def convolve(a: _ArrayLikeObject_co, v: _ArrayLikeObject_co, mode: _CorrelateMode = ...) -> NDArray[np.object_]: ... + +# @overload -def outer( - a: _ArrayLikeUnknown, - b: _ArrayLikeUnknown, - out: None = ..., -) -> NDArray[Any]: ... +def outer(a: _ArrayLikeUnknown, b: _ArrayLikeUnknown, out: None = ...) -> NDArray[Any]: ... @overload -def outer( - a: _ArrayLikeBool_co, - b: _ArrayLikeBool_co, - out: None = ..., -) -> NDArray[np.bool]: ... +def outer(a: _ArrayLikeBool_co, b: _ArrayLikeBool_co, out: None = ...) -> NDArray[np.bool]: ... @overload -def outer( - a: _ArrayLikeUInt_co, - b: _ArrayLikeUInt_co, - out: None = ..., -) -> NDArray[unsignedinteger[Any]]: ... +def outer(a: _ArrayLikeUInt_co, b: _ArrayLikeUInt_co, out: None = ...) -> NDArray[np.unsignedinteger]: ... @overload -def outer( - a: _ArrayLikeInt_co, - b: _ArrayLikeInt_co, - out: None = ..., -) -> NDArray[signedinteger[Any]]: ... +def outer(a: _ArrayLikeInt_co, b: _ArrayLikeInt_co, out: None = ...) -> NDArray[np.signedinteger]: ... @overload -def outer( - a: _ArrayLikeFloat_co, - b: _ArrayLikeFloat_co, - out: None = ..., -) -> NDArray[floating[Any]]: ... +def outer(a: _ArrayLikeFloat_co, b: _ArrayLikeFloat_co, out: None = ...) -> NDArray[np.floating]: ... @overload -def outer( - a: _ArrayLikeComplex_co, - b: _ArrayLikeComplex_co, - out: None = ..., -) -> NDArray[complexfloating[Any, Any]]: ... +def outer(a: _ArrayLikeComplex_co, b: _ArrayLikeComplex_co, out: None = ...) -> NDArray[np.complexfloating]: ... @overload -def outer( - a: _ArrayLikeTD64_co, - b: _ArrayLikeTD64_co, - out: None = ..., -) -> NDArray[timedelta64]: ... +def outer(a: _ArrayLikeTD64_co, b: _ArrayLikeTD64_co, out: None = ...) -> NDArray[np.timedelta64]: ... @overload -def outer( - a: _ArrayLikeObject_co, - b: _ArrayLikeObject_co, - out: None = ..., -) -> NDArray[object_]: ... +def outer(a: _ArrayLikeObject_co, b: _ArrayLikeObject_co, out: None = ...) -> NDArray[np.object_]: ... @overload def outer( a: _ArrayLikeComplex_co | _ArrayLikeTD64_co | _ArrayLikeObject_co, b: _ArrayLikeComplex_co | _ArrayLikeTD64_co | _ArrayLikeObject_co, - out: _ArrayType, -) -> _ArrayType: ... + out: _ArrayT, +) -> _ArrayT: ... + +# @overload def tensordot( a: _ArrayLikeUnknown, @@ -631,59 +519,49 @@ def tensordot( a: _ArrayLikeUInt_co, b: _ArrayLikeUInt_co, axes: int | tuple[_ShapeLike, _ShapeLike] = ..., -) -> NDArray[unsignedinteger[Any]]: ... +) -> NDArray[np.unsignedinteger]: ... @overload def tensordot( a: _ArrayLikeInt_co, b: _ArrayLikeInt_co, axes: int | tuple[_ShapeLike, _ShapeLike] = ..., -) -> NDArray[signedinteger[Any]]: ... +) -> NDArray[np.signedinteger]: ... @overload def tensordot( a: _ArrayLikeFloat_co, b: _ArrayLikeFloat_co, axes: int | tuple[_ShapeLike, _ShapeLike] = ..., -) -> NDArray[floating[Any]]: ... +) -> NDArray[np.floating]: ... @overload def tensordot( a: _ArrayLikeComplex_co, b: _ArrayLikeComplex_co, axes: int | tuple[_ShapeLike, _ShapeLike] = ..., -) -> NDArray[complexfloating[Any, Any]]: ... +) -> NDArray[np.complexfloating]: ... @overload def tensordot( a: _ArrayLikeTD64_co, b: _ArrayLikeTD64_co, axes: int | tuple[_ShapeLike, _ShapeLike] = ..., -) -> NDArray[timedelta64]: ... +) -> NDArray[np.timedelta64]: ... @overload def tensordot( a: _ArrayLikeObject_co, b: _ArrayLikeObject_co, axes: int | tuple[_ShapeLike, _ShapeLike] = ..., -) -> NDArray[object_]: ... +) -> NDArray[np.object_]: ... + +# @overload -def roll( - a: _ArrayLike[_SCT], - shift: _ShapeLike, - axis: _ShapeLike | None = ..., -) -> NDArray[_SCT]: ... +def roll(a: _ArrayLike[_SCT], shift: _ShapeLike, axis: _ShapeLike | None = ...) -> NDArray[_SCT]: ... @overload -def roll( - a: ArrayLike, - shift: _ShapeLike, - axis: _ShapeLike | None = ..., -) -> NDArray[Any]: ... -def rollaxis( - a: NDArray[_SCT], - axis: int, - start: int = ..., -) -> NDArray[_SCT]: ... -def moveaxis( - a: NDArray[_SCT], - source: _ShapeLike, - destination: _ShapeLike, -) -> NDArray[_SCT]: ... +def roll(a: ArrayLike, shift: _ShapeLike, axis: _ShapeLike | None = ...) -> NDArray[Any]: ... + +# +def rollaxis(a: NDArray[_SCT], axis: int, start: int = ...) -> NDArray[_SCT]: ... +def moveaxis(a: NDArray[_SCT], source: _ShapeLike, destination: _ShapeLike) -> NDArray[_SCT]: ... + +# @overload def cross( x1: _ArrayLikeUnknown, @@ -710,7 +588,7 @@ def cross( axisb: int = ..., axisc: int = ..., axis: int | None = ..., -) -> NDArray[unsignedinteger[Any]]: ... +) -> NDArray[np.unsignedinteger]: ... @overload def cross( x1: _ArrayLikeInt_co, @@ -719,7 +597,7 @@ def cross( axisb: int = ..., axisc: int = ..., axis: int | None = ..., -) -> NDArray[signedinteger[Any]]: ... +) -> NDArray[np.signedinteger]: ... @overload def cross( x1: _ArrayLikeFloat_co, @@ -728,7 +606,7 @@ def cross( axisb: int = ..., axisc: int = ..., axis: int | None = ..., -) -> NDArray[floating[Any]]: ... +) -> NDArray[np.floating]: ... @overload def cross( x1: _ArrayLikeComplex_co, @@ -737,7 +615,7 @@ def cross( axisb: int = ..., axisc: int = ..., axis: int | None = ..., -) -> NDArray[complexfloating[Any, Any]]: ... +) -> NDArray[np.complexfloating]: ... @overload def cross( x1: _ArrayLikeObject_co, @@ -746,19 +624,21 @@ def cross( axisb: int = ..., axisc: int = ..., axis: int | None = ..., -) -> NDArray[object_]: ... +) -> NDArray[np.object_]: ... + +# @overload def indices( dimensions: Sequence[int], dtype: type[int] = ..., sparse: L[False] = ..., -) -> NDArray[int_]: ... +) -> NDArray[np.int_]: ... @overload def indices( dimensions: Sequence[int], dtype: type[int] = ..., sparse: L[True] = ..., -) -> tuple[NDArray[int_], ...]: ... +) -> tuple[NDArray[np.int_], ...]: ... @overload def indices( dimensions: Sequence[int], @@ -783,6 +663,8 @@ def indices( dtype: DTypeLike, sparse: L[True], ) -> tuple[NDArray[Any], ...]: ... + +# def fromfunction( function: Callable[..., _T], shape: Sequence[int], @@ -791,41 +673,28 @@ def fromfunction( like: _SupportsArrayFunc = ..., **kwargs: Any, ) -> _T: ... -def isscalar(element: object) -> TypeGuard[generic | bool | int | float | complex | str | bytes | memoryview]: ... + +# +def isscalar(element: object) -> TypeIs[np.generic | int | float | complex | str | bytes]: ... + +# def binary_repr(num: SupportsIndex, width: int | None = ...) -> str: ... -def base_repr( - number: SupportsAbs[float], - base: float = ..., - padding: SupportsIndex = ..., -) -> str: ... -@overload -def identity( - n: int, - dtype: None = ..., - *, - like: _SupportsArrayFunc = ..., -) -> NDArray[float64]: ... + +# +def base_repr(number: SupportsAbs[float], base: float = ..., padding: SupportsIndex = ...) -> str: ... + +# @overload -def identity( - n: int, - dtype: _DTypeLike[_SCT], - *, - like: _SupportsArrayFunc = ..., -) -> NDArray[_SCT]: ... +def identity(n: int, dtype: None = ..., *, like: _SupportsArrayFunc = ...) -> NDArray[np.float64]: ... @overload -def identity( - n: int, - dtype: DTypeLike, - *, - like: _SupportsArrayFunc = ..., -) -> NDArray[Any]: ... -def allclose( - a: ArrayLike, - b: ArrayLike, - rtol: ArrayLike = ..., - atol: ArrayLike = ..., - equal_nan: bool = ..., -) -> bool: ... +def identity(n: int, dtype: _DTypeLike[_SCT], *, like: _SupportsArrayFunc = ...) -> NDArray[_SCT]: ... +@overload +def identity(n: int, dtype: DTypeLike, *, like: _SupportsArrayFunc = ...) -> NDArray[Any]: ... + +# +def allclose(a: ArrayLike, b: ArrayLike, rtol: ArrayLike = ..., atol: ArrayLike = ..., equal_nan: bool = ...) -> bool: ... + +# @overload def isclose( a: _ScalarLike_co, @@ -842,19 +711,23 @@ def isclose( atol: ArrayLike = ..., equal_nan: bool = ..., ) -> NDArray[np.bool]: ... + +# def array_equal(a1: ArrayLike, a2: ArrayLike, equal_nan: bool = ...) -> bool: ... def array_equiv(a1: ArrayLike, a2: ArrayLike) -> bool: ... + +# @overload def astype( - x: ndarray[_ShapeType, dtype[Any]], + x: ndarray[_ShapeT, dtype[Any]], dtype: _DTypeLike[_SCT], copy: bool = ..., device: L["cpu"] | None = ..., -) -> ndarray[_ShapeType, dtype[_SCT]]: ... +) -> ndarray[_ShapeT, dtype[_SCT]]: ... @overload def astype( - x: ndarray[_ShapeType, dtype[Any]], + x: ndarray[_ShapeT, dtype[Any]], dtype: DTypeLike, copy: bool = ..., device: L["cpu"] | None = ..., -) -> ndarray[_ShapeType, dtype[Any]]: ... +) -> ndarray[_ShapeT, dtype[Any]]: ... diff --git a/src/numpy-stubs/_core/numerictypes.pyi b/src/numpy-stubs/_core/numerictypes.pyi index cbff275f..27d8e636 100644 --- a/src/numpy-stubs/_core/numerictypes.pyi +++ b/src/numpy-stubs/_core/numerictypes.pyi @@ -1,13 +1,8 @@ import builtins -from typing import ( - Any, - Literal as L, - TypedDict, - type_check_only, -) +from typing import Any, Final, Literal as L, TypedDict, type_check_only import numpy as np -from numpy import ( +from numpy import ( # noqa: ICN003 bool, bool_, byte, @@ -49,7 +44,6 @@ from numpy import ( str_, timedelta64, ubyte, - uint, uint8, uint16, uint32, @@ -78,15 +72,8 @@ from numpy._typing._extended_precision import ( uint256, ) -from ._type_aliases import sctypeDict # noqa: F401 -from .multiarray import ( - busday_count, - busday_offset, - busdaycalendar, - datetime_as_string, - datetime_data, - is_busday, -) +from ._type_aliases import sctypeDict as sctypeDict +from .multiarray import busday_count, busday_offset, busdaycalendar, datetime_as_string, datetime_data, is_busday __all__ = [ "ScalarType", @@ -149,11 +136,11 @@ __all__ = [ "timedelta64", "typecodes", "ubyte", - "uint", "uint8", "uint16", "uint32", "uint64", + "uint64", "uint128", "uint256", "uintc", @@ -177,40 +164,42 @@ class _TypeCodes(TypedDict): Datetime: L["Mm"] All: L["?bhilqnpBHILQNPefdgFDGSUVOMm"] -def isdtype(dtype: dtype[Any] | type[Any], kind: DTypeLike | tuple[DTypeLike, ...]) -> builtins.bool: ... +def isdtype(dtype: dtype[Any] | type, kind: DTypeLike | tuple[DTypeLike, ...]) -> builtins.bool: ... def issubdtype(arg1: DTypeLike, arg2: DTypeLike) -> builtins.bool: ... -typecodes: _TypeCodes -ScalarType: tuple[ - type[int], - type[float], - type[complex], - type[builtins.bool], - type[bytes], - type[str], - type[memoryview], - type[np.bool], - type[csingle], - type[cdouble], - type[clongdouble], - type[half], - type[single], - type[double], - type[longdouble], - type[byte], - type[short], - type[intc], - type[long], - type[longlong], - type[timedelta64], - type[datetime64], - type[object_], - type[bytes_], - type[str_], - type[ubyte], - type[ushort], - type[uintc], - type[ulong], - type[ulonglong], - type[void], -] +typecodes: Final[_TypeCodes] = ... +ScalarType: Final[ + tuple[ + type[int], + type[float], + type[complex], + type[builtins.bool], + type[bytes], + type[str], + type[memoryview], + type[np.bool], + type[csingle], + type[cdouble], + type[clongdouble], + type[half], + type[single], + type[double], + type[longdouble], + type[byte], + type[short], + type[intc], + type[long], + type[longlong], + type[timedelta64], + type[datetime64], + type[object_], + type[bytes_], + type[str_], + type[ubyte], + type[ushort], + type[uintc], + type[ulong], + type[ulonglong], + type[void], + ] +] = ... diff --git a/src/numpy-stubs/_core/records.pyi b/src/numpy-stubs/_core/records.pyi index d8358971..6f6f2769 100644 --- a/src/numpy-stubs/_core/records.pyi +++ b/src/numpy-stubs/_core/records.pyi @@ -3,15 +3,7 @@ from collections.abc import Iterable, Sequence from types import EllipsisType from typing import Any, Literal, Protocol, SupportsIndex, TypeAlias, TypeVar, overload, type_check_only -from numpy import ( - _ByteOrder, - _OrderKACF, - _SupportsBuffer, - dtype, - generic, - ndarray, - void, -) +import numpy as np from numpy._typing import ( ArrayLike, DTypeLike, @@ -36,11 +28,11 @@ __all__ = [ ] _T = TypeVar("_T") -_SCT = TypeVar("_SCT", bound=generic) -_DType_co = TypeVar("_DType_co", bound=dtype[Any], covariant=True) +_SCT = TypeVar("_SCT", bound=np.generic) +_DType_co = TypeVar("_DType_co", bound=np.dtype[Any], covariant=True) _ShapeT_co = TypeVar("_ShapeT_co", bound=tuple[int, ...], covariant=True) -_RecArray: TypeAlias = recarray[Any, dtype[_SCT]] +_RecArray: TypeAlias = recarray[Any, np.dtype[_SCT]] @type_check_only class _SupportsReadInto(Protocol): @@ -48,16 +40,16 @@ class _SupportsReadInto(Protocol): def tell(self, /) -> int: ... def readinto(self, buffer: memoryview, /) -> int: ... -class record(void): - def __getattribute__(self, attr: str) -> Any: ... - def __setattr__(self, attr: str, val: ArrayLike) -> None: ... +class record(np.void): def pprint(self) -> str: ... + def __getattribute__(self, attr: str, /) -> Any: ... + def __setattr__(self, attr: str, val: ArrayLike, /) -> None: ... @overload - def __getitem__(self, key: str | SupportsIndex) -> Any: ... + def __getitem__(self, key: str | SupportsIndex, /) -> Any: ... @overload - def __getitem__(self, key: list[str]) -> record: ... + def __getitem__(self, key: list[str], /) -> record: ... -class recarray(ndarray[_ShapeT_co, _DType_co]): +class recarray(np.ndarray[_ShapeT_co, _DType_co]): # NOTE: While not strictly mandatory, we're demanding here that arguments # for the `format_parser`- and `dtype`-based dtype constructors are # mutually exclusive @@ -66,23 +58,23 @@ class recarray(ndarray[_ShapeT_co, _DType_co]): cls, shape: _ShapeLike, dtype: None = ..., - buf: _SupportsBuffer | None = ..., + buf: np._SupportsBuffer | None = ..., offset: SupportsIndex = ..., strides: _ShapeLike | None = ..., *, formats: DTypeLike, names: str | Sequence[str] | None = ..., titles: str | Sequence[str] | None = ..., - byteorder: _ByteOrder | None = ..., + byteorder: np._ByteOrder | None = ..., aligned: bool = ..., - order: _OrderKACF = ..., - ) -> recarray[Any, dtype[record]]: ... + order: np._OrderKACF = ..., + ) -> _RecArray[record]: ... @overload def __new__( cls, shape: _ShapeLike, dtype: DTypeLike, - buf: _SupportsBuffer | None = ..., + buf: np._SupportsBuffer | None = ..., offset: SupportsIndex = ..., strides: _ShapeLike | None = ..., formats: None = ..., @@ -90,8 +82,8 @@ class recarray(ndarray[_ShapeT_co, _DType_co]): titles: None = ..., byteorder: None = ..., aligned: Literal[False] = ..., - order: _OrderKACF = ..., - ) -> recarray[Any, dtype[Any]]: ... + order: np._OrderKACF = ..., + ) -> _RecArray[Any]: ... def __array_finalize__(self, obj: Incomplete) -> None: ... def __getattribute__(self, attr: str) -> Any: ... def __setattr__(self, attr: str, val: ArrayLike) -> None: ... @@ -99,7 +91,7 @@ class recarray(ndarray[_ShapeT_co, _DType_co]): def __getitem__(self, indx: (SupportsIndex | _ArrayLikeInt_co | tuple[SupportsIndex | _ArrayLikeInt_co, ...])) -> Any: ... @overload def __getitem__( - self: recarray[Any, dtype[void]], + self: _RecArray[np.void], indx: slice | EllipsisType | SupportsIndex @@ -116,25 +108,25 @@ class recarray(ndarray[_ShapeT_co, _DType_co]): | _ArrayLikeInt_co | tuple[slice | EllipsisType | _ArrayLikeInt_co | SupportsIndex | None, ...] | None, - ) -> ndarray[_Shape, _DType_co]: ... + ) -> np.ndarray[_Shape, _DType_co]: ... @overload def __getitem__(self, indx: str) -> NDArray[Any]: ... @overload - def __getitem__(self, indx: list[str]) -> recarray[_ShapeT_co, dtype[record]]: ... + def __getitem__(self, indx: list[str]) -> recarray[_ShapeT_co, np.dtype[record]]: ... @overload def field(self, attr: int | str, val: None = ...) -> Any: ... @overload def field(self, attr: int | str, val: ArrayLike) -> None: ... class format_parser: - dtype: dtype[void] + dtype: np.dtype[np.void] def __init__( self, formats: DTypeLike, names: str | Sequence[str] | None, titles: str | Sequence[str] | None, aligned: bool = ..., - byteorder: _ByteOrder | None = ..., + byteorder: np._ByteOrder | None = ..., ) -> None: ... @overload @@ -158,7 +150,7 @@ def fromarrays( names: str | Sequence[str] | None = ..., titles: str | Sequence[str] | None = ..., aligned: bool = ..., - byteorder: _ByteOrder | None = ..., + byteorder: np._ByteOrder | None = ..., ) -> _RecArray[record]: ... @overload def fromrecords( @@ -181,11 +173,11 @@ def fromrecords( names: str | Sequence[str] | None = ..., titles: str | Sequence[str] | None = ..., aligned: bool = ..., - byteorder: _ByteOrder | None = ..., + byteorder: np._ByteOrder | None = ..., ) -> _RecArray[record]: ... @overload def fromstring( - datastring: _SupportsBuffer, + datastring: np._SupportsBuffer, dtype: DTypeLike, shape: _ShapeLike | None = ..., offset: int = ..., @@ -197,7 +189,7 @@ def fromstring( ) -> _RecArray[record]: ... @overload def fromstring( - datastring: _SupportsBuffer, + datastring: np._SupportsBuffer, dtype: None = ..., shape: _ShapeLike | None = ..., offset: int = ..., @@ -206,7 +198,7 @@ def fromstring( names: str | Sequence[str] | None = ..., titles: str | Sequence[str] | None = ..., aligned: bool = ..., - byteorder: _ByteOrder | None = ..., + byteorder: np._ByteOrder | None = ..., ) -> _RecArray[record]: ... @overload def fromfile( @@ -231,7 +223,7 @@ def fromfile( names: str | Sequence[str] | None = ..., titles: str | Sequence[str] | None = ..., aligned: bool = ..., - byteorder: _ByteOrder | None = ..., + byteorder: np._ByteOrder | None = ..., ) -> _RecArray[record]: ... @overload def array( @@ -270,7 +262,7 @@ def array( names: str | Sequence[str] | None = ..., titles: str | Sequence[str] | None = ..., aligned: bool = ..., - byteorder: _ByteOrder | None = ..., + byteorder: np._ByteOrder | None = ..., copy: bool = ..., ) -> _RecArray[record]: ... @overload @@ -297,7 +289,7 @@ def array( names: str | Sequence[str] | None = ..., titles: str | Sequence[str] | None = ..., aligned: bool = ..., - byteorder: _ByteOrder | None = ..., + byteorder: np._ByteOrder | None = ..., copy: bool = ..., ) -> _RecArray[record]: ... @overload @@ -324,7 +316,7 @@ def array( names: str | Sequence[str] | None = ..., titles: str | Sequence[str] | None = ..., aligned: bool = ..., - byteorder: _ByteOrder | None = ..., + byteorder: np._ByteOrder | None = ..., copy: bool = ..., ) -> _RecArray[record]: ... def find_duplicate(list: Iterable[_T]) -> list[_T]: ... diff --git a/src/numpy-stubs/_core/shape_base.pyi b/src/numpy-stubs/_core/shape_base.pyi index cdea52b1..db4ce019 100644 --- a/src/numpy-stubs/_core/shape_base.pyi +++ b/src/numpy-stubs/_core/shape_base.pyi @@ -1,59 +1,55 @@ from collections.abc import Sequence from typing import Any, SupportsIndex, TypeVar, overload -from numpy import _CastingKind, generic -from numpy._typing import ( - ArrayLike, - DTypeLike, - NDArray, - _ArrayLike, - _DTypeLike, -) +import numpy as np +from numpy._typing import ArrayLike, DTypeLike, NDArray, _ArrayLike, _DTypeLike -__all__ = [ - "atleast_1d", - "atleast_2d", - "atleast_3d", - "block", - "hstack", - "stack", - "unstack", - "vstack", -] +__all__ = ["atleast_1d", "atleast_2d", "atleast_3d", "block", "hstack", "stack", "unstack", "vstack"] -_SCT = TypeVar("_SCT", bound=generic) -_ArrayType = TypeVar("_ArrayType", bound=NDArray[Any]) +_SCT = TypeVar("_SCT", bound=np.generic) +_ArrayT = TypeVar("_ArrayT", bound=NDArray[Any]) +# @overload def atleast_1d(arys: _ArrayLike[_SCT], /) -> NDArray[_SCT]: ... @overload def atleast_1d(arys: ArrayLike, /) -> NDArray[Any]: ... @overload def atleast_1d(*arys: ArrayLike) -> tuple[NDArray[Any], ...]: ... + +# @overload def atleast_2d(arys: _ArrayLike[_SCT], /) -> NDArray[_SCT]: ... @overload def atleast_2d(arys: ArrayLike, /) -> NDArray[Any]: ... @overload def atleast_2d(*arys: ArrayLike) -> tuple[NDArray[Any], ...]: ... + +# @overload def atleast_3d(arys: _ArrayLike[_SCT], /) -> NDArray[_SCT]: ... @overload def atleast_3d(arys: ArrayLike, /) -> NDArray[Any]: ... @overload def atleast_3d(*arys: ArrayLike) -> tuple[NDArray[Any], ...]: ... + +# @overload -def vstack(tup: Sequence[_ArrayLike[_SCT]], *, dtype: None = ..., casting: _CastingKind = ...) -> NDArray[_SCT]: ... +def vstack(tup: Sequence[_ArrayLike[_SCT]], *, dtype: None = ..., casting: np._CastingKind = ...) -> NDArray[_SCT]: ... @overload -def vstack(tup: Sequence[ArrayLike], *, dtype: _DTypeLike[_SCT], casting: _CastingKind = ...) -> NDArray[_SCT]: ... +def vstack(tup: Sequence[ArrayLike], *, dtype: _DTypeLike[_SCT], casting: np._CastingKind = ...) -> NDArray[_SCT]: ... @overload -def vstack(tup: Sequence[ArrayLike], *, dtype: DTypeLike = ..., casting: _CastingKind = ...) -> NDArray[Any]: ... +def vstack(tup: Sequence[ArrayLike], *, dtype: DTypeLike = ..., casting: np._CastingKind = ...) -> NDArray[Any]: ... + +# @overload -def hstack(tup: Sequence[_ArrayLike[_SCT]], *, dtype: None = ..., casting: _CastingKind = ...) -> NDArray[_SCT]: ... +def hstack(tup: Sequence[_ArrayLike[_SCT]], *, dtype: None = ..., casting: np._CastingKind = ...) -> NDArray[_SCT]: ... @overload -def hstack(tup: Sequence[ArrayLike], *, dtype: _DTypeLike[_SCT], casting: _CastingKind = ...) -> NDArray[_SCT]: ... +def hstack(tup: Sequence[ArrayLike], *, dtype: _DTypeLike[_SCT], casting: np._CastingKind = ...) -> NDArray[_SCT]: ... @overload -def hstack(tup: Sequence[ArrayLike], *, dtype: DTypeLike = ..., casting: _CastingKind = ...) -> NDArray[Any]: ... +def hstack(tup: Sequence[ArrayLike], *, dtype: DTypeLike = ..., casting: np._CastingKind = ...) -> NDArray[Any]: ... + +# @overload def stack( arrays: Sequence[_ArrayLike[_SCT]], @@ -61,7 +57,7 @@ def stack( out: None = ..., *, dtype: None = ..., - casting: _CastingKind = ..., + casting: np._CastingKind = ..., ) -> NDArray[_SCT]: ... @overload def stack( @@ -70,7 +66,7 @@ def stack( out: None = ..., *, dtype: _DTypeLike[_SCT], - casting: _CastingKind = ..., + casting: np._CastingKind = ..., ) -> NDArray[_SCT]: ... @overload def stack( @@ -79,31 +75,25 @@ def stack( out: None = ..., *, dtype: DTypeLike = ..., - casting: _CastingKind = ..., + casting: np._CastingKind = ..., ) -> NDArray[Any]: ... @overload def stack( arrays: Sequence[ArrayLike], axis: SupportsIndex = ..., - out: _ArrayType = ..., + out: _ArrayT = ..., *, dtype: DTypeLike = ..., - casting: _CastingKind = ..., -) -> _ArrayType: ... + casting: np._CastingKind = ..., +) -> _ArrayT: ... + +# @overload -def unstack( - array: _ArrayLike[_SCT], - /, - *, - axis: int = ..., -) -> tuple[NDArray[_SCT], ...]: ... +def unstack(array: _ArrayLike[_SCT], /, *, axis: int = ...) -> tuple[NDArray[_SCT], ...]: ... @overload -def unstack( - array: ArrayLike, - /, - *, - axis: int = ..., -) -> tuple[NDArray[Any], ...]: ... +def unstack(array: ArrayLike, /, *, axis: int = ...) -> tuple[NDArray[Any], ...]: ... + +# @overload def block(arrays: _ArrayLike[_SCT]) -> NDArray[_SCT]: ... @overload diff --git a/src/numpy-stubs/ctypeslib/_ctypeslib.pyi b/src/numpy-stubs/ctypeslib/_ctypeslib.pyi index 6f3523b4..792d823a 100644 --- a/src/numpy-stubs/ctypeslib/_ctypeslib.pyi +++ b/src/numpy-stubs/ctypeslib/_ctypeslib.pyi @@ -1,45 +1,13 @@ -# NOTE: Numpy's mypy plugin is used for importing the correct -# platform-specific `ctypes._SimpleCData[int]` sub-type import ctypes as ct from _typeshed import StrOrBytesPath from collections.abc import Iterable, Sequence -from ctypes import c_int64 as _c_intp -from typing import ( - Any, - ClassVar, - Generic, - Literal as L, - TypeAlias, - TypeVar, - overload, -) +from typing import Any, ClassVar, Generic, Literal as L, TypeAlias, TypeVar, overload import numpy as np -from numpy import ( - byte, - double, - dtype, - generic, - intc, - long, - longdouble, - longlong, - ndarray, - short, - single, - ubyte, - uintc, - ulong, - ulonglong, - ushort, - void, -) from numpy._core._internal import _ctypes from numpy._core.multiarray import flagsobj from numpy._typing import ( - # DTypes DTypeLike, - # Arrays NDArray, _ArrayLike, _BoolCodes, @@ -50,7 +18,6 @@ from numpy._typing import ( _LongCodes, _LongDoubleCodes, _LongLongCodes, - # Shapes _Shape, _ShapeLike, _ShortCodes, @@ -65,10 +32,15 @@ from numpy._typing import ( __all__ = ["as_array", "as_ctypes", "as_ctypes_type", "c_intp", "load_library", "ndpointer"] -# TODO: Add a proper `_Shape` bound once we've got variadic typevars -_DType = TypeVar("_DType", bound=dtype[Any]) -_DTypeOptional = TypeVar("_DTypeOptional", bound=dtype[Any] | None) -_SCT = TypeVar("_SCT", bound=generic) +### + +_SCT = TypeVar("_SCT", bound=np.generic) +_DTypeT = TypeVar("_DTypeT", bound=np.dtype[Any]) +_ShapeT = TypeVar("_ShapeT", bound=_Shape) +_DTypeT_co = TypeVar("_DTypeT_co", bound=np.dtype[Any], covariant=True) +_ShapeT_co = TypeVar("_ShapeT_co", bound=_Shape, default=_Shape, covariant=True) +_DTypeT0_co = TypeVar("_DTypeT0_co", bound=np.dtype[Any] | None, default=None, covariant=True) +_ShapeT0_co = TypeVar("_ShapeT0_co", bound=_Shape | None, default=None, covariant=True) _FlagsKind: TypeAlias = L[ "C_CONTIGUOUS", @@ -87,31 +59,28 @@ _FlagsKind: TypeAlias = L[ "X", ] -# TODO: Add a shape typevar once we have variadic typevars (PEP 646) -class _ndptr(ct.c_void_p, Generic[_DTypeOptional]): +class _ndptr(ct.c_void_p, Generic[_DTypeT0_co, _ShapeT0_co]): # In practice these 4 classvars are defined in the dynamic class # returned by `ndpointer` - _dtype_: ClassVar[_DTypeOptional] - _shape_: ClassVar[None] + _dtype_: _DTypeT0_co + _shape_: _ShapeT0_co _ndim_: ClassVar[int | None] _flags_: ClassVar[list[_FlagsKind] | None] @overload @classmethod - def from_param(cls: type[_ndptr[None]], obj: NDArray[Any]) -> _ctypes[Any]: ... + def from_param(cls: type[_ndptr[_DTypeT, _ShapeT]], obj: np.ndarray[_ShapeT, _DTypeT]) -> _ctypes[int]: ... @overload @classmethod - def from_param(cls: type[_ndptr[_DType]], obj: ndarray[Any, _DType]) -> _ctypes[Any]: ... + def from_param(cls: type[_ndptr], obj: NDArray[Any]) -> _ctypes[int]: ... -class _concrete_ndptr(_ndptr[_DType]): - _dtype_: ClassVar[_DType] - _shape_: ClassVar[tuple[int, ...]] +class _concrete_ndptr(_ndptr[_DTypeT_co, _ShapeT_co], Generic[_DTypeT_co, _ShapeT_co]): @property - def contents(self) -> ndarray[_Shape, _DType]: ... + def contents(self) -> np.ndarray[_ShapeT_co, _DTypeT_co]: ... def load_library(libname: StrOrBytesPath, loader_path: StrOrBytesPath) -> ct.CDLL: ... -c_intp = _c_intp +c_intp: TypeAlias = ct.c_int32 | ct.c_int64 @overload def ndpointer( @@ -127,7 +96,7 @@ def ndpointer( *, shape: _ShapeLike, flags: _FlagsKind | Iterable[_FlagsKind] | int | flagsobj | None = ..., -) -> type[_concrete_ndptr[dtype[_SCT]]]: ... +) -> type[_concrete_ndptr[np.dtype[_SCT]]]: ... @overload def ndpointer( dtype: DTypeLike, @@ -135,51 +104,51 @@ def ndpointer( *, shape: _ShapeLike, flags: _FlagsKind | Iterable[_FlagsKind] | int | flagsobj | None = ..., -) -> type[_concrete_ndptr[dtype[Any]]]: ... +) -> type[_concrete_ndptr[np.dtype[Any]]]: ... @overload def ndpointer( dtype: _DTypeLike[_SCT], ndim: int = ..., shape: None = ..., flags: _FlagsKind | Iterable[_FlagsKind] | int | flagsobj | None = ..., -) -> type[_ndptr[dtype[_SCT]]]: ... +) -> type[_ndptr[np.dtype[_SCT]]]: ... @overload def ndpointer( dtype: DTypeLike, ndim: int = ..., shape: None = ..., flags: _FlagsKind | Iterable[_FlagsKind] | int | flagsobj | None = ..., -) -> type[_ndptr[dtype[Any]]]: ... +) -> type[_ndptr[np.dtype[Any]]]: ... @overload def as_ctypes_type(dtype: _BoolCodes | _DTypeLike[np.bool] | type[ct.c_bool]) -> type[ct.c_bool]: ... @overload -def as_ctypes_type(dtype: _ByteCodes | _DTypeLike[byte] | type[ct.c_byte]) -> type[ct.c_byte]: ... +def as_ctypes_type(dtype: _ByteCodes | _DTypeLike[np.byte] | type[ct.c_byte]) -> type[ct.c_byte]: ... @overload -def as_ctypes_type(dtype: _ShortCodes | _DTypeLike[short] | type[ct.c_short]) -> type[ct.c_short]: ... +def as_ctypes_type(dtype: _ShortCodes | _DTypeLike[np.short] | type[ct.c_short]) -> type[ct.c_short]: ... @overload -def as_ctypes_type(dtype: _IntCCodes | _DTypeLike[intc] | type[ct.c_int]) -> type[ct.c_int]: ... +def as_ctypes_type(dtype: _IntCCodes | _DTypeLike[np.intc] | type[ct.c_int]) -> type[ct.c_int]: ... @overload -def as_ctypes_type(dtype: _LongCodes | _DTypeLike[long] | type[ct.c_long]) -> type[ct.c_long]: ... +def as_ctypes_type(dtype: _LongCodes | _DTypeLike[np.long] | type[ct.c_long]) -> type[ct.c_long]: ... @overload def as_ctypes_type(dtype: type[int]) -> type[c_intp]: ... @overload -def as_ctypes_type(dtype: _LongLongCodes | _DTypeLike[longlong] | type[ct.c_longlong]) -> type[ct.c_longlong]: ... +def as_ctypes_type(dtype: _LongLongCodes | _DTypeLike[np.longlong] | type[ct.c_longlong]) -> type[ct.c_longlong]: ... @overload -def as_ctypes_type(dtype: _UByteCodes | _DTypeLike[ubyte] | type[ct.c_ubyte]) -> type[ct.c_ubyte]: ... +def as_ctypes_type(dtype: _UByteCodes | _DTypeLike[np.ubyte] | type[ct.c_ubyte]) -> type[ct.c_ubyte]: ... @overload -def as_ctypes_type(dtype: _UShortCodes | _DTypeLike[ushort] | type[ct.c_ushort]) -> type[ct.c_ushort]: ... +def as_ctypes_type(dtype: _UShortCodes | _DTypeLike[np.ushort] | type[ct.c_ushort]) -> type[ct.c_ushort]: ... @overload -def as_ctypes_type(dtype: _UIntCCodes | _DTypeLike[uintc] | type[ct.c_uint]) -> type[ct.c_uint]: ... +def as_ctypes_type(dtype: _UIntCCodes | _DTypeLike[np.uintc] | type[ct.c_uint]) -> type[ct.c_uint]: ... @overload -def as_ctypes_type(dtype: _ULongCodes | _DTypeLike[ulong] | type[ct.c_ulong]) -> type[ct.c_ulong]: ... +def as_ctypes_type(dtype: _ULongCodes | _DTypeLike[np.ulong] | type[ct.c_ulong]) -> type[ct.c_ulong]: ... @overload -def as_ctypes_type(dtype: _ULongLongCodes | _DTypeLike[ulonglong] | type[ct.c_ulonglong]) -> type[ct.c_ulonglong]: ... +def as_ctypes_type(dtype: _ULongLongCodes | _DTypeLike[np.ulonglong] | type[ct.c_ulonglong]) -> type[ct.c_ulonglong]: ... @overload -def as_ctypes_type(dtype: _SingleCodes | _DTypeLike[single] | type[ct.c_float]) -> type[ct.c_float]: ... +def as_ctypes_type(dtype: _SingleCodes | _DTypeLike[np.single] | type[ct.c_float]) -> type[ct.c_float]: ... @overload -def as_ctypes_type(dtype: _DoubleCodes | _DTypeLike[double] | type[float | ct.c_double]) -> type[ct.c_double]: ... +def as_ctypes_type(dtype: _DoubleCodes | _DTypeLike[np.double] | type[float | ct.c_double]) -> type[ct.c_double]: ... @overload -def as_ctypes_type(dtype: _LongDoubleCodes | _DTypeLike[longdouble] | type[ct.c_longdouble]) -> type[ct.c_longdouble]: ... +def as_ctypes_type(dtype: _LongDoubleCodes | _DTypeLike[np.longdouble] | type[ct.c_longdouble]) -> type[ct.c_longdouble]: ... @overload def as_ctypes_type(dtype: _VoidDTypeLike) -> type[Any]: ... # `ctypes.Union` or `ctypes.Structure` @overload @@ -193,60 +162,60 @@ def as_array(obj: object, shape: _ShapeLike | None = ...) -> NDArray[Any]: ... @overload def as_ctypes(obj: np.bool) -> ct.c_bool: ... @overload -def as_ctypes(obj: byte) -> ct.c_byte: ... +def as_ctypes(obj: np.byte) -> ct.c_byte: ... @overload -def as_ctypes(obj: short) -> ct.c_short: ... +def as_ctypes(obj: np.short) -> ct.c_short: ... @overload -def as_ctypes(obj: intc) -> ct.c_int: ... +def as_ctypes(obj: np.intc) -> ct.c_int: ... @overload -def as_ctypes(obj: long) -> ct.c_long: ... +def as_ctypes(obj: np.long) -> ct.c_long: ... @overload -def as_ctypes(obj: longlong) -> ct.c_longlong: ... +def as_ctypes(obj: np.longlong) -> ct.c_longlong: ... @overload -def as_ctypes(obj: ubyte) -> ct.c_ubyte: ... +def as_ctypes(obj: np.ubyte) -> ct.c_ubyte: ... @overload -def as_ctypes(obj: ushort) -> ct.c_ushort: ... +def as_ctypes(obj: np.ushort) -> ct.c_ushort: ... @overload -def as_ctypes(obj: uintc) -> ct.c_uint: ... +def as_ctypes(obj: np.uintc) -> ct.c_uint: ... @overload -def as_ctypes(obj: ulong) -> ct.c_ulong: ... +def as_ctypes(obj: np.ulong) -> ct.c_ulong: ... @overload -def as_ctypes(obj: ulonglong) -> ct.c_ulonglong: ... +def as_ctypes(obj: np.ulonglong) -> ct.c_ulonglong: ... @overload -def as_ctypes(obj: single) -> ct.c_float: ... +def as_ctypes(obj: np.single) -> ct.c_float: ... @overload -def as_ctypes(obj: double) -> ct.c_double: ... +def as_ctypes(obj: np.double) -> ct.c_double: ... @overload -def as_ctypes(obj: longdouble) -> ct.c_longdouble: ... +def as_ctypes(obj: np.longdouble) -> ct.c_longdouble: ... @overload -def as_ctypes(obj: void) -> Any: ... # `ctypes.Union` or `ctypes.Structure` +def as_ctypes(obj: np.void) -> Any: ... # `ctypes.Union` or `ctypes.Structure` @overload def as_ctypes(obj: NDArray[np.bool]) -> ct.Array[ct.c_bool]: ... @overload -def as_ctypes(obj: NDArray[byte]) -> ct.Array[ct.c_byte]: ... +def as_ctypes(obj: NDArray[np.byte]) -> ct.Array[ct.c_byte]: ... @overload -def as_ctypes(obj: NDArray[short]) -> ct.Array[ct.c_short]: ... +def as_ctypes(obj: NDArray[np.short]) -> ct.Array[ct.c_short]: ... @overload -def as_ctypes(obj: NDArray[intc]) -> ct.Array[ct.c_int]: ... +def as_ctypes(obj: NDArray[np.intc]) -> ct.Array[ct.c_int]: ... @overload -def as_ctypes(obj: NDArray[long]) -> ct.Array[ct.c_long]: ... +def as_ctypes(obj: NDArray[np.long]) -> ct.Array[ct.c_long]: ... @overload -def as_ctypes(obj: NDArray[longlong]) -> ct.Array[ct.c_longlong]: ... +def as_ctypes(obj: NDArray[np.longlong]) -> ct.Array[ct.c_longlong]: ... @overload -def as_ctypes(obj: NDArray[ubyte]) -> ct.Array[ct.c_ubyte]: ... +def as_ctypes(obj: NDArray[np.ubyte]) -> ct.Array[ct.c_ubyte]: ... @overload -def as_ctypes(obj: NDArray[ushort]) -> ct.Array[ct.c_ushort]: ... +def as_ctypes(obj: NDArray[np.ushort]) -> ct.Array[ct.c_ushort]: ... @overload -def as_ctypes(obj: NDArray[uintc]) -> ct.Array[ct.c_uint]: ... +def as_ctypes(obj: NDArray[np.uintc]) -> ct.Array[ct.c_uint]: ... @overload -def as_ctypes(obj: NDArray[ulong]) -> ct.Array[ct.c_ulong]: ... +def as_ctypes(obj: NDArray[np.ulong]) -> ct.Array[ct.c_ulong]: ... @overload -def as_ctypes(obj: NDArray[ulonglong]) -> ct.Array[ct.c_ulonglong]: ... +def as_ctypes(obj: NDArray[np.ulonglong]) -> ct.Array[ct.c_ulonglong]: ... @overload -def as_ctypes(obj: NDArray[single]) -> ct.Array[ct.c_float]: ... +def as_ctypes(obj: NDArray[np.single]) -> ct.Array[ct.c_float]: ... @overload -def as_ctypes(obj: NDArray[double]) -> ct.Array[ct.c_double]: ... +def as_ctypes(obj: NDArray[np.double]) -> ct.Array[ct.c_double]: ... @overload -def as_ctypes(obj: NDArray[longdouble]) -> ct.Array[ct.c_longdouble]: ... +def as_ctypes(obj: NDArray[np.longdouble]) -> ct.Array[ct.c_longdouble]: ... @overload -def as_ctypes(obj: NDArray[void]) -> ct.Array[Any]: ... # `ctypes.Union` or `ctypes.Structure` +def as_ctypes(obj: NDArray[np.void]) -> ct.Array[Any]: ... # `ctypes.Union` or `ctypes.Structure` diff --git a/src/numpy-stubs/fft/_helper.pyi b/src/numpy-stubs/fft/_helper.pyi index d508ae1c..eeb83d2f 100644 --- a/src/numpy-stubs/fft/_helper.pyi +++ b/src/numpy-stubs/fft/_helper.pyi @@ -1,48 +1,32 @@ from typing import Any, Literal as L, TypeVar, overload -from numpy import complexfloating, floating, generic, integer -from numpy._typing import ( - ArrayLike, - NDArray, - _ArrayLike, - _ArrayLikeComplex_co, - _ArrayLikeFloat_co, - _ShapeLike, -) +import numpy as np +from numpy._typing import ArrayLike, NDArray, _ArrayLike, _ArrayLikeComplex_co, _ArrayLikeFloat_co, _ShapeLike __all__ = ["fftfreq", "fftshift", "ifftshift", "rfftfreq"] -_SCT = TypeVar("_SCT", bound=generic) +_SCT = TypeVar("_SCT", bound=np.generic) +# @overload def fftshift(x: _ArrayLike[_SCT], axes: _ShapeLike | None = ...) -> NDArray[_SCT]: ... @overload def fftshift(x: ArrayLike, axes: _ShapeLike | None = ...) -> NDArray[Any]: ... + +# @overload def ifftshift(x: _ArrayLike[_SCT], axes: _ShapeLike | None = ...) -> NDArray[_SCT]: ... @overload def ifftshift(x: ArrayLike, axes: _ShapeLike | None = ...) -> NDArray[Any]: ... + +# +@overload +def fftfreq(n: int | np.integer, d: _ArrayLikeFloat_co = ..., device: L["cpu"] | None = ...) -> NDArray[np.floating]: ... +@overload +def fftfreq(n: int | np.integer, d: _ArrayLikeComplex_co = ..., device: L["cpu"] | None = ...) -> NDArray[np.inexact]: ... + +# +@overload +def rfftfreq(n: int | np.integer, d: _ArrayLikeFloat_co = ..., device: L["cpu"] | None = ...) -> NDArray[np.floating]: ... @overload -def fftfreq( - n: int | integer[Any], - d: _ArrayLikeFloat_co = ..., - device: L["cpu"] | None = ..., -) -> NDArray[floating[Any]]: ... -@overload -def fftfreq( - n: int | integer[Any], - d: _ArrayLikeComplex_co = ..., - device: L["cpu"] | None = ..., -) -> NDArray[complexfloating[Any, Any]]: ... -@overload -def rfftfreq( - n: int | integer[Any], - d: _ArrayLikeFloat_co = ..., - device: L["cpu"] | None = ..., -) -> NDArray[floating[Any]]: ... -@overload -def rfftfreq( - n: int | integer[Any], - d: _ArrayLikeComplex_co = ..., - device: L["cpu"] | None = ..., -) -> NDArray[complexfloating[Any, Any]]: ... +def rfftfreq(n: int | np.integer, d: _ArrayLikeComplex_co = ..., device: L["cpu"] | None = ...) -> NDArray[np.inexact]: ... diff --git a/src/numpy-stubs/fft/_pocketfft.pyi b/src/numpy-stubs/fft/_pocketfft.pyi index 20264b0c..c434efd6 100644 --- a/src/numpy-stubs/fft/_pocketfft.pyi +++ b/src/numpy-stubs/fft/_pocketfft.pyi @@ -1,8 +1,9 @@ from collections.abc import Sequence from typing import Literal as L, TypeAlias -from numpy import complex128, float64 -from numpy._typing import ArrayLike, NDArray, _ArrayLikeNumber_co +import numpy as np +import numpy.typing as npt +from numpy._typing import _ArrayLikeNumber_co __all__ = [ "fft", @@ -24,33 +25,33 @@ __all__ = [ _NormKind: TypeAlias = L["backward", "ortho", "forward"] | None def fft( - a: ArrayLike, + a: npt.ArrayLike, n: int | None = ..., axis: int = ..., norm: _NormKind = ..., - out: NDArray[complex128] | None = ..., -) -> NDArray[complex128]: ... + out: npt.NDArray[np.complex128] | None = ..., +) -> npt.NDArray[np.complex128]: ... def ifft( - a: ArrayLike, + a: npt.ArrayLike, n: int | None = ..., axis: int = ..., norm: _NormKind = ..., - out: NDArray[complex128] | None = ..., -) -> NDArray[complex128]: ... + out: npt.NDArray[np.complex128] | None = ..., +) -> npt.NDArray[np.complex128]: ... def rfft( - a: ArrayLike, + a: npt.ArrayLike, n: int | None = ..., axis: int = ..., norm: _NormKind = ..., - out: NDArray[complex128] | None = ..., -) -> NDArray[complex128]: ... + out: npt.NDArray[np.complex128] | None = ..., +) -> npt.NDArray[np.complex128]: ... def irfft( - a: ArrayLike, + a: npt.ArrayLike, n: int | None = ..., axis: int = ..., norm: _NormKind = ..., - out: NDArray[float64] | None = ..., -) -> NDArray[float64]: ... + out: npt.NDArray[np.float64] | None = ..., +) -> npt.NDArray[np.float64]: ... # Input array must be compatible with `np.conjugate` def hfft( @@ -58,68 +59,68 @@ def hfft( n: int | None = ..., axis: int = ..., norm: _NormKind = ..., - out: NDArray[float64] | None = ..., -) -> NDArray[float64]: ... + out: npt.NDArray[np.float64] | None = ..., +) -> npt.NDArray[np.float64]: ... def ihfft( - a: ArrayLike, + a: npt.ArrayLike, n: int | None = ..., axis: int = ..., norm: _NormKind = ..., - out: NDArray[complex128] | None = ..., -) -> NDArray[complex128]: ... + out: npt.NDArray[np.complex128] | None = ..., +) -> npt.NDArray[np.complex128]: ... def fftn( - a: ArrayLike, + a: npt.ArrayLike, s: Sequence[int] | None = ..., axes: Sequence[int] | None = ..., norm: _NormKind = ..., - out: NDArray[complex128] | None = ..., -) -> NDArray[complex128]: ... + out: npt.NDArray[np.complex128] | None = ..., +) -> npt.NDArray[np.complex128]: ... def ifftn( - a: ArrayLike, + a: npt.ArrayLike, s: Sequence[int] | None = ..., axes: Sequence[int] | None = ..., norm: _NormKind = ..., - out: NDArray[complex128] | None = ..., -) -> NDArray[complex128]: ... + out: npt.NDArray[np.complex128] | None = ..., +) -> npt.NDArray[np.complex128]: ... def rfftn( - a: ArrayLike, + a: npt.ArrayLike, s: Sequence[int] | None = ..., axes: Sequence[int] | None = ..., norm: _NormKind = ..., - out: NDArray[complex128] | None = ..., -) -> NDArray[complex128]: ... + out: npt.NDArray[np.complex128] | None = ..., +) -> npt.NDArray[np.complex128]: ... def irfftn( - a: ArrayLike, + a: npt.ArrayLike, s: Sequence[int] | None = ..., axes: Sequence[int] | None = ..., norm: _NormKind = ..., - out: NDArray[float64] | None = ..., -) -> NDArray[float64]: ... + out: npt.NDArray[np.float64] | None = ..., +) -> npt.NDArray[np.float64]: ... def fft2( - a: ArrayLike, + a: npt.ArrayLike, s: Sequence[int] | None = ..., axes: Sequence[int] | None = ..., norm: _NormKind = ..., - out: NDArray[complex128] | None = ..., -) -> NDArray[complex128]: ... + out: npt.NDArray[np.complex128] | None = ..., +) -> npt.NDArray[np.complex128]: ... def ifft2( - a: ArrayLike, + a: npt.ArrayLike, s: Sequence[int] | None = ..., axes: Sequence[int] | None = ..., norm: _NormKind = ..., - out: NDArray[complex128] | None = ..., -) -> NDArray[complex128]: ... + out: npt.NDArray[np.complex128] | None = ..., +) -> npt.NDArray[np.complex128]: ... def rfft2( - a: ArrayLike, + a: npt.ArrayLike, s: Sequence[int] | None = ..., axes: Sequence[int] | None = ..., norm: _NormKind = ..., - out: NDArray[complex128] | None = ..., -) -> NDArray[complex128]: ... + out: npt.NDArray[np.complex128] | None = ..., +) -> npt.NDArray[np.complex128]: ... def irfft2( - a: ArrayLike, + a: npt.ArrayLike, s: Sequence[int] | None = ..., axes: Sequence[int] | None = ..., norm: _NormKind = ..., - out: NDArray[float64] | None = ..., -) -> NDArray[float64]: ... + out: npt.NDArray[np.float64] | None = ..., +) -> npt.NDArray[np.float64]: ... diff --git a/src/numpy-stubs/lib/_array_utils_impl.pyi b/src/numpy-stubs/lib/_array_utils_impl.pyi index 90254636..10e1986d 100644 --- a/src/numpy-stubs/lib/_array_utils_impl.pyi +++ b/src/numpy-stubs/lib/_array_utils_impl.pyi @@ -1,8 +1,8 @@ from collections.abc import Iterable from typing import Any -from numpy import generic -from numpy.typing import NDArray +import numpy as np +import numpy.typing as npt __all__ = ["byte_bounds", "normalize_axis_index", "normalize_axis_tuple"] @@ -10,15 +10,11 @@ __all__ = ["byte_bounds", "normalize_axis_index", "normalize_axis_tuple"] # implementing the `__array_interface__` protocol. The caveat is # that certain keys, marked as optional in the spec, must be present for # `byte_bounds`. This concerns `"strides"` and `"data"`. -def byte_bounds(a: generic | NDArray[Any]) -> tuple[int, int]: ... +def byte_bounds(a: np.generic | npt.NDArray[Any]) -> tuple[int, int]: ... +def normalize_axis_index(axis: int = ..., ndim: int = ..., msg_prefix: str | None = ...) -> int: ... def normalize_axis_tuple( axis: int | Iterable[int], ndim: int = ..., argname: str | None = ..., allow_duplicate: bool | None = ..., ) -> tuple[int, int]: ... -def normalize_axis_index( - axis: int = ..., - ndim: int = ..., - msg_prefix: str | None = ..., -) -> int: ... diff --git a/src/numpy-stubs/lib/_arraypad_impl.pyi b/src/numpy-stubs/lib/_arraypad_impl.pyi index 2105a1d3..489aa28e 100644 --- a/src/numpy-stubs/lib/_arraypad_impl.pyi +++ b/src/numpy-stubs/lib/_arraypad_impl.pyi @@ -1,35 +1,14 @@ -from typing import ( - Any, - Literal as L, - Protocol, - TypeAlias, - TypeVar, - overload, - type_check_only, -) +from collections.abc import Mapping +from typing import Any, Literal as L, Protocol, TypeAlias, TypeVar, overload, type_check_only -from numpy import generic -from numpy._typing import ( - ArrayLike, - NDArray, - _ArrayLike, - _ArrayLikeInt, -) +import numpy as np +from numpy._typing import ArrayLike, NDArray, _ArrayLike, _ArrayLikeInt __all__ = ["pad"] -_SCT = TypeVar("_SCT", bound=generic) +### -@type_check_only -class _ModeFunc(Protocol): - def __call__( - self, - vector: NDArray[Any], - iaxis_pad_width: tuple[int, int], - iaxis: int, - kwargs: dict[str, Any], - /, - ) -> None: ... +_SCT = TypeVar("_SCT", bound=np.generic) _ModeKind: TypeAlias = L[ "constant", @@ -45,10 +24,14 @@ _ModeKind: TypeAlias = L[ "empty", ] +@type_check_only +class _ModeFunc(Protocol): + def __call__(self, vector: NDArray[Any], pad: tuple[int, int], iaxis: int, kwargs: Mapping[str, object], /) -> None: ... + +### + # TODO: In practice each keyword argument is exclusive to one or more # specific modes. Consider adding more overloads to express this in the future. - -# Expand `**kwargs` into explicit keyword-only arguments @overload def pad( array: _ArrayLike[_SCT], @@ -72,16 +55,6 @@ def pad( reflect_type: L["odd", "even"] = ..., ) -> NDArray[Any]: ... @overload -def pad( - array: _ArrayLike[_SCT], - pad_width: _ArrayLikeInt, - mode: _ModeFunc, - **kwargs: Any, -) -> NDArray[_SCT]: ... +def pad(array: _ArrayLike[_SCT], pad_width: _ArrayLikeInt, mode: _ModeFunc, **kwargs: object) -> NDArray[_SCT]: ... @overload -def pad( - array: ArrayLike, - pad_width: _ArrayLikeInt, - mode: _ModeFunc, - **kwargs: Any, -) -> NDArray[Any]: ... +def pad(array: ArrayLike, pad_width: _ArrayLikeInt, mode: _ModeFunc, **kwargs: object) -> NDArray[Any]: ... diff --git a/src/numpy-stubs/lib/_arraysetops_impl.pyi b/src/numpy-stubs/lib/_arraysetops_impl.pyi index a70aa617..07b47dcf 100644 --- a/src/numpy-stubs/lib/_arraysetops_impl.pyi +++ b/src/numpy-stubs/lib/_arraysetops_impl.pyi @@ -1,44 +1,7 @@ -from typing import ( - Any, - Generic, - Literal as L, - NamedTuple, - SupportsIndex, - TypeVar, - overload, -) +from typing import Any, Generic, Literal as L, NamedTuple, SupportsIndex, TypeVar, overload from typing_extensions import deprecated import numpy as np -from numpy import ( - byte, - bytes_, - cdouble, - clongdouble, - csingle, - datetime64, - double, - generic, - half, - int8, - int_, - intc, - intp, - longdouble, - longlong, - number, - object_, - short, - single, - str_, - timedelta64, - ubyte, - uint, - uintc, - ulonglong, - ushort, - void, -) from numpy._typing import ( ArrayLike, NDArray, @@ -65,8 +28,8 @@ __all__ = [ "unique_values", ] -_SCT = TypeVar("_SCT", bound=generic) -_NumberType = TypeVar("_NumberType", bound=number[Any]) +_SCT = TypeVar("_SCT", bound=np.generic) +_NumberT = TypeVar("_NumberT", bound=np.number) # Explicitly set all allowed values to prevent accidental castings to # abstract dtypes (their common super-type). @@ -74,78 +37,66 @@ _NumberType = TypeVar("_NumberType", bound=number[Any]) # Only relevant if two or more arguments are parametrized, (e.g. `setdiff1d`) # which could result in, for example, `int64` and `float64`producing a # `number[_64Bit]` array -_SCTNoCast = TypeVar( - "_SCTNoCast", +_AnyScalarT = TypeVar( + "_AnyScalarT", np.bool, - ushort, - ubyte, - uintc, - uint, - ulonglong, - short, - byte, - intc, - int_, - longlong, - half, - single, - double, - longdouble, - csingle, - cdouble, - clongdouble, - timedelta64, - datetime64, - object_, - str_, - bytes_, - void, + np.int8, + np.int16, + np.int32, + np.int64, + np.uint8, + np.uint16, + np.uint32, + np.uint64, + np.float16, + np.float32, + np.float64, + np.longdouble, + np.complex64, + np.complex128, + np.clongdouble, + np.timedelta64, + np.datetime64, + np.object_, + np.bytes_, + np.str_, + np.void, ) class UniqueAllResult(NamedTuple, Generic[_SCT]): values: NDArray[_SCT] - indices: NDArray[intp] - inverse_indices: NDArray[intp] - counts: NDArray[intp] + indices: NDArray[np.int_] + inverse_indices: NDArray[np.int_] + counts: NDArray[np.int_] class UniqueCountsResult(NamedTuple, Generic[_SCT]): values: NDArray[_SCT] - counts: NDArray[intp] + counts: NDArray[np.int_] class UniqueInverseResult(NamedTuple, Generic[_SCT]): values: NDArray[_SCT] - inverse_indices: NDArray[intp] + inverse_indices: NDArray[np.int_] @overload -def ediff1d( - ary: _ArrayLikeBool_co, - to_end: ArrayLike | None = ..., - to_begin: ArrayLike | None = ..., -) -> NDArray[int8]: ... -@overload -def ediff1d( - ary: _ArrayLike[_NumberType], - to_end: ArrayLike | None = ..., - to_begin: ArrayLike | None = ..., -) -> NDArray[_NumberType]: ... +def ediff1d(ary: _ArrayLikeBool_co, to_end: ArrayLike | None = ..., to_begin: ArrayLike | None = ...) -> NDArray[np.int8]: ... @overload -def ediff1d( - ary: _ArrayLikeNumber_co, - to_end: ArrayLike | None = ..., - to_begin: ArrayLike | None = ..., -) -> NDArray[Any]: ... +def ediff1d(ary: _ArrayLike[_NumberT], to_end: ArrayLike | None = ..., to_begin: ArrayLike | None = ...) -> NDArray[_NumberT]: ... @overload def ediff1d( ary: _ArrayLikeDT64_co | _ArrayLikeTD64_co, to_end: ArrayLike | None = ..., to_begin: ArrayLike | None = ..., -) -> NDArray[timedelta64]: ... +) -> NDArray[np.timedelta64]: ... @overload def ediff1d( ary: _ArrayLikeObject_co, to_end: ArrayLike | None = ..., to_begin: ArrayLike | None = ..., -) -> NDArray[object_]: ... +) -> NDArray[np.object_]: ... +@overload +def ediff1d(ary: _ArrayLikeNumber_co, to_end: ArrayLike | None = ..., to_begin: ArrayLike | None = ...) -> NDArray[Any]: ... + +# @overload def unique( ar: _ArrayLike[_SCT], @@ -175,7 +126,7 @@ def unique( axis: SupportsIndex | None = ..., *, equal_nan: bool = ..., -) -> tuple[NDArray[_SCT], NDArray[intp]]: ... +) -> tuple[NDArray[_SCT], NDArray[np.int_]]: ... @overload def unique( ar: ArrayLike, @@ -185,7 +136,7 @@ def unique( axis: SupportsIndex | None = ..., *, equal_nan: bool = ..., -) -> tuple[NDArray[Any], NDArray[intp]]: ... +) -> tuple[NDArray[Any], NDArray[np.int_]]: ... @overload def unique( ar: _ArrayLike[_SCT], @@ -195,7 +146,7 @@ def unique( axis: SupportsIndex | None = ..., *, equal_nan: bool = ..., -) -> tuple[NDArray[_SCT], NDArray[intp]]: ... +) -> tuple[NDArray[_SCT], NDArray[np.int_]]: ... @overload def unique( ar: ArrayLike, @@ -205,7 +156,7 @@ def unique( axis: SupportsIndex | None = ..., *, equal_nan: bool = ..., -) -> tuple[NDArray[Any], NDArray[intp]]: ... +) -> tuple[NDArray[Any], NDArray[np.int_]]: ... @overload def unique( ar: _ArrayLike[_SCT], @@ -215,7 +166,7 @@ def unique( axis: SupportsIndex | None = ..., *, equal_nan: bool = ..., -) -> tuple[NDArray[_SCT], NDArray[intp]]: ... +) -> tuple[NDArray[_SCT], NDArray[np.int_]]: ... @overload def unique( ar: ArrayLike, @@ -225,7 +176,7 @@ def unique( axis: SupportsIndex | None = ..., *, equal_nan: bool = ..., -) -> tuple[NDArray[Any], NDArray[intp]]: ... +) -> tuple[NDArray[Any], NDArray[np.int_]]: ... @overload def unique( ar: _ArrayLike[_SCT], @@ -235,7 +186,7 @@ def unique( axis: SupportsIndex | None = ..., *, equal_nan: bool = ..., -) -> tuple[NDArray[_SCT], NDArray[intp], NDArray[intp]]: ... +) -> tuple[NDArray[_SCT], NDArray[np.int_], NDArray[np.int_]]: ... @overload def unique( ar: ArrayLike, @@ -245,7 +196,7 @@ def unique( axis: SupportsIndex | None = ..., *, equal_nan: bool = ..., -) -> tuple[NDArray[Any], NDArray[intp], NDArray[intp]]: ... +) -> tuple[NDArray[Any], NDArray[np.int_], NDArray[np.int_]]: ... @overload def unique( ar: _ArrayLike[_SCT], @@ -255,7 +206,7 @@ def unique( axis: SupportsIndex | None = ..., *, equal_nan: bool = ..., -) -> tuple[NDArray[_SCT], NDArray[intp], NDArray[intp]]: ... +) -> tuple[NDArray[_SCT], NDArray[np.int_], NDArray[np.int_]]: ... @overload def unique( ar: ArrayLike, @@ -265,7 +216,7 @@ def unique( axis: SupportsIndex | None = ..., *, equal_nan: bool = ..., -) -> tuple[NDArray[Any], NDArray[intp], NDArray[intp]]: ... +) -> tuple[NDArray[Any], NDArray[np.int_], NDArray[np.int_]]: ... @overload def unique( ar: _ArrayLike[_SCT], @@ -275,7 +226,7 @@ def unique( axis: SupportsIndex | None = ..., *, equal_nan: bool = ..., -) -> tuple[NDArray[_SCT], NDArray[intp], NDArray[intp]]: ... +) -> tuple[NDArray[_SCT], NDArray[np.int_], NDArray[np.int_]]: ... @overload def unique( ar: ArrayLike, @@ -285,7 +236,7 @@ def unique( axis: SupportsIndex | None = ..., *, equal_nan: bool = ..., -) -> tuple[NDArray[Any], NDArray[intp], NDArray[intp]]: ... +) -> tuple[NDArray[Any], NDArray[np.int_], NDArray[np.int_]]: ... @overload def unique( ar: _ArrayLike[_SCT], @@ -295,7 +246,7 @@ def unique( axis: SupportsIndex | None = ..., *, equal_nan: bool = ..., -) -> tuple[NDArray[_SCT], NDArray[intp], NDArray[intp], NDArray[intp]]: ... +) -> tuple[NDArray[_SCT], NDArray[np.int_], NDArray[np.int_], NDArray[np.int_]]: ... @overload def unique( ar: ArrayLike, @@ -305,30 +256,40 @@ def unique( axis: SupportsIndex | None = ..., *, equal_nan: bool = ..., -) -> tuple[NDArray[Any], NDArray[intp], NDArray[intp], NDArray[intp]]: ... +) -> tuple[NDArray[Any], NDArray[np.int_], NDArray[np.int_], NDArray[np.int_]]: ... + +# @overload def unique_all(x: _ArrayLike[_SCT], /) -> UniqueAllResult[_SCT]: ... @overload def unique_all(x: ArrayLike, /) -> UniqueAllResult[Any]: ... + +# @overload def unique_counts(x: _ArrayLike[_SCT], /) -> UniqueCountsResult[_SCT]: ... @overload def unique_counts(x: ArrayLike, /) -> UniqueCountsResult[Any]: ... + +# @overload def unique_inverse(x: _ArrayLike[_SCT], /) -> UniqueInverseResult[_SCT]: ... @overload def unique_inverse(x: ArrayLike, /) -> UniqueInverseResult[Any]: ... + +# @overload def unique_values(x: _ArrayLike[_SCT], /) -> NDArray[_SCT]: ... @overload def unique_values(x: ArrayLike, /) -> NDArray[Any]: ... + +# @overload def intersect1d( - ar1: _ArrayLike[_SCTNoCast], - ar2: _ArrayLike[_SCTNoCast], + ar1: _ArrayLike[_AnyScalarT], + ar2: _ArrayLike[_AnyScalarT], assume_unique: bool = ..., return_indices: L[False] = ..., -) -> NDArray[_SCTNoCast]: ... +) -> NDArray[_AnyScalarT]: ... @overload def intersect1d( ar1: ArrayLike, @@ -338,30 +299,26 @@ def intersect1d( ) -> NDArray[Any]: ... @overload def intersect1d( - ar1: _ArrayLike[_SCTNoCast], - ar2: _ArrayLike[_SCTNoCast], + ar1: _ArrayLike[_AnyScalarT], + ar2: _ArrayLike[_AnyScalarT], assume_unique: bool = ..., return_indices: L[True] = ..., -) -> tuple[NDArray[_SCTNoCast], NDArray[intp], NDArray[intp]]: ... +) -> tuple[NDArray[_AnyScalarT], NDArray[np.int_], NDArray[np.int_]]: ... @overload def intersect1d( ar1: ArrayLike, ar2: ArrayLike, assume_unique: bool = ..., return_indices: L[True] = ..., -) -> tuple[NDArray[Any], NDArray[intp], NDArray[intp]]: ... +) -> tuple[NDArray[Any], NDArray[np.int_], NDArray[np.int_]]: ... + +# @overload -def setxor1d( - ar1: _ArrayLike[_SCTNoCast], - ar2: _ArrayLike[_SCTNoCast], - assume_unique: bool = ..., -) -> NDArray[_SCTNoCast]: ... +def setxor1d(ar1: _ArrayLike[_AnyScalarT], ar2: _ArrayLike[_AnyScalarT], assume_unique: bool = ...) -> NDArray[_AnyScalarT]: ... @overload -def setxor1d( - ar1: ArrayLike, - ar2: ArrayLike, - assume_unique: bool = ..., -) -> NDArray[Any]: ... +def setxor1d(ar1: ArrayLike, ar2: ArrayLike, assume_unique: bool = ...) -> NDArray[Any]: ... + +# def isin( element: ArrayLike, test_elements: ArrayLike, @@ -370,6 +327,8 @@ def isin( *, kind: str | None = ..., ) -> NDArray[np.bool]: ... + +# @deprecated("Use 'isin' instead") def in1d( element: ArrayLike, @@ -379,25 +338,13 @@ def in1d( *, kind: str | None = ..., ) -> NDArray[np.bool]: ... + +# @overload -def union1d( - ar1: _ArrayLike[_SCTNoCast], - ar2: _ArrayLike[_SCTNoCast], -) -> NDArray[_SCTNoCast]: ... +def union1d(ar1: _ArrayLike[_AnyScalarT], ar2: _ArrayLike[_AnyScalarT]) -> NDArray[_AnyScalarT]: ... @overload -def union1d( - ar1: ArrayLike, - ar2: ArrayLike, -) -> NDArray[Any]: ... +def union1d(ar1: ArrayLike, ar2: ArrayLike) -> NDArray[Any]: ... @overload -def setdiff1d( - ar1: _ArrayLike[_SCTNoCast], - ar2: _ArrayLike[_SCTNoCast], - assume_unique: bool = ..., -) -> NDArray[_SCTNoCast]: ... +def setdiff1d(ar1: _ArrayLike[_AnyScalarT], ar2: _ArrayLike[_AnyScalarT], assume_unique: bool = ...) -> NDArray[_AnyScalarT]: ... @overload -def setdiff1d( - ar1: ArrayLike, - ar2: ArrayLike, - assume_unique: bool = ..., -) -> NDArray[Any]: ... +def setdiff1d(ar1: ArrayLike, ar2: ArrayLike, assume_unique: bool = ...) -> NDArray[Any]: ... diff --git a/src/numpy-stubs/lib/_arrayterator_impl.pyi b/src/numpy-stubs/lib/_arrayterator_impl.pyi index 80b074a5..90d15d62 100644 --- a/src/numpy-stubs/lib/_arrayterator_impl.pyi +++ b/src/numpy-stubs/lib/_arrayterator_impl.pyi @@ -1,43 +1,35 @@ from collections.abc import Generator, Iterator from types import EllipsisType -from typing import ( - Any, - TypeAlias, - TypeVar, - overload, -) +from typing import Any, TypeAlias, TypeVar -from numpy import dtype, generic, ndarray -from numpy._typing import DTypeLike, NDArray, _Shape as _AnyShape +import numpy as np __all__ = ["Arrayterator"] -# TODO: Rename to ``_ShapeType`` -_Shape = TypeVar("_Shape", bound=_AnyShape) -_DType = TypeVar("_DType", bound=dtype[Any]) -_ScalarType = TypeVar("_ScalarType", bound=generic) +_ShapeT_co = TypeVar("_ShapeT_co", bound=tuple[int, ...], covariant=True) +_DTypeT_co = TypeVar("_DTypeT_co", bound=np.dtype[Any], covariant=True) +_SCT = TypeVar("_SCT", bound=np.generic) -_Index: TypeAlias = EllipsisType | int | slice | tuple[EllipsisType | int | slice, ...] +_AnyIndex: TypeAlias = EllipsisType | int | slice | tuple[EllipsisType | int | slice, ...] -# NOTE: In reality `Arrayterator` does not actually inherit from `ndarray`, -# but its ``__getattr__` method does wrap around the former and thus has -# access to all its methods +### -class Arrayterator(ndarray[_Shape, _DType]): - var: ndarray[_Shape, _DType] # type: ignore[assignment] +# NOTE: In reality `Arrayterator` does not actually inherit from `ndarray`, # but its `__getattr__ method does wrap around the +# former and thus has access to all its methods +class Arrayterator(np.ndarray[_ShapeT_co, _DTypeT_co]): + var: np.ndarray[_ShapeT_co, _DTypeT_co] # type: ignore[assignment] buf_size: int | None start: list[int] stop: list[int] step: list[int] - @property # type: ignore[misc] - def shape(self) -> tuple[int, ...]: ... @property - def flat(self: NDArray[_ScalarType]) -> Generator[_ScalarType, None, None]: ... - def __init__(self, var: ndarray[_Shape, _DType], buf_size: int | None = ...) -> None: ... - @overload - def __array__(self, dtype: None = ..., copy: bool | None = ...) -> ndarray[_AnyShape, _DType]: ... - @overload - def __array__(self, dtype: DTypeLike, copy: bool | None = ...) -> NDArray[Any]: ... - def __getitem__(self, index: _Index) -> Arrayterator[_AnyShape, _DType]: ... - def __iter__(self) -> Iterator[ndarray[_AnyShape, _DType]]: ... + def shape(self) -> _ShapeT_co: ... + @property + def flat(self: Arrayterator[Any, np.dtype[_SCT]]) -> Generator[_SCT]: ... + + # + def __init__(self, var: np.ndarray[_ShapeT_co, _DTypeT_co], buf_size: int | None = ...) -> None: ... + def __array__(self, dtype: None = ..., copy: bool | None = ...) -> np.ndarray[_ShapeT_co, _DTypeT_co]: ... + def __getitem__(self, index: _AnyIndex, /) -> Arrayterator[Any, _DTypeT_co]: ... + def __iter__(self) -> Iterator[np.ndarray[Any, _DTypeT_co]]: ... diff --git a/src/numpy-stubs/lib/_function_base_impl.pyi b/src/numpy-stubs/lib/_function_base_impl.pyi index ab8ae9a9..fbc80eb4 100644 --- a/src/numpy-stubs/lib/_function_base_impl.pyi +++ b/src/numpy-stubs/lib/_function_base_impl.pyi @@ -8,29 +8,14 @@ from typing import ( SupportsIndex, SupportsInt, TypeAlias, - TypeGuard, TypeVar, overload, type_check_only, ) -from typing_extensions import deprecated +from typing_extensions import TypeIs, deprecated import numpy as np -from numpy import ( - _OrderKACF, - bool_, - complex128, - complexfloating, - datetime64, - float64, - floating, - generic, - integer, - intp, - object_, - timedelta64, - vectorize, -) +from numpy import vectorize # noqa: ICN003 from numpy._core.multiarray import bincount from numpy._typing import ( ArrayLike, @@ -97,12 +82,31 @@ __all__ = [ _T = TypeVar("_T") _T_co = TypeVar("_T_co", covariant=True) -# The `{}ss` suffix refers to the Python 3.12 syntax: `**P` _Pss = ParamSpec("_Pss") -_SCT = TypeVar("_SCT", bound=generic) -_ArrayType = TypeVar("_ArrayType", bound=NDArray[Any]) +_SCT = TypeVar("_SCT", bound=np.generic) +_SCT_fcm = TypeVar("_SCT_fcm", bound=np.inexact | np.timedelta64) +_ArrayT = TypeVar("_ArrayT", bound=NDArray[Any]) _2Tuple: TypeAlias = tuple[_T, _T] +_MethodKind: TypeAlias = L[ + "inverted_cdf", + "averaged_inverted_cdf", + "closest_observation", + "interpolated_inverted_cdf", + "hazen", + "weibull", + "linear", + "median_unbiased", + "normal_unbiased", + "lower", + "higher", + "midpoint", + "nearest", +] + +@type_check_only +class _SupportsRMulFloat(Protocol[_T_co]): + def __rmul__(self, other: float, /) -> _T_co: ... @type_check_only class _TrimZerosSequence(Protocol[_T_co]): @@ -112,18 +116,14 @@ class _TrimZerosSequence(Protocol[_T_co]): @overload def __getitem__(self, key: slice, /) -> _T_co: ... +### + @overload -def rot90( - m: _ArrayLike[_SCT], - k: int = ..., - axes: tuple[int, int] = ..., -) -> NDArray[_SCT]: ... +def rot90(m: _ArrayLike[_SCT], k: int = ..., axes: tuple[int, int] = ...) -> NDArray[_SCT]: ... @overload -def rot90( - m: ArrayLike, - k: int = ..., - axes: tuple[int, int] = ..., -) -> NDArray[Any]: ... +def rot90(m: ArrayLike, k: int = ..., axes: tuple[int, int] = ...) -> NDArray[Any]: ... + +# @overload def flip(m: _SCT, axis: None = ...) -> _SCT: ... @overload @@ -132,7 +132,11 @@ def flip(m: _ScalarLike_co, axis: None = ...) -> Any: ... def flip(m: _ArrayLike[_SCT], axis: _ShapeLike | None = ...) -> NDArray[_SCT]: ... @overload def flip(m: ArrayLike, axis: _ShapeLike | None = ...) -> NDArray[Any]: ... -def iterable(y: object) -> TypeGuard[Iterable[Any]]: ... + +# +def iterable(y: object) -> TypeIs[Iterable[Any]]: ... + +# @overload def average( a: _ArrayLikeFloat_co, @@ -140,7 +144,7 @@ def average( weights: _ArrayLikeFloat_co | None = ..., returned: L[False] = ..., keepdims: L[False] = ..., -) -> floating[Any]: ... +) -> np.floating: ... @overload def average( a: _ArrayLikeComplex_co, @@ -148,7 +152,7 @@ def average( weights: _ArrayLikeComplex_co | None = ..., returned: L[False] = ..., keepdims: L[False] = ..., -) -> complexfloating[Any, Any]: ... +) -> np.complexfloating: ... @overload def average( a: _ArrayLikeObject_co, @@ -164,7 +168,7 @@ def average( weights: _ArrayLikeFloat_co | None = ..., returned: L[True] = ..., keepdims: L[False] = ..., -) -> _2Tuple[floating[Any]]: ... +) -> _2Tuple[np.floating]: ... @overload def average( a: _ArrayLikeComplex_co, @@ -172,7 +176,7 @@ def average( weights: _ArrayLikeComplex_co | None = ..., returned: L[True] = ..., keepdims: L[False] = ..., -) -> _2Tuple[complexfloating[Any, Any]]: ... +) -> _2Tuple[np.complexfloating]: ... @overload def average( a: _ArrayLikeObject_co, @@ -197,34 +201,22 @@ def average( returned: L[True] = ..., keepdims: bool = ..., ) -> _2Tuple[Any]: ... + +# @overload -def asarray_chkfinite( - a: _ArrayLike[_SCT], - dtype: None = ..., - order: _OrderKACF = ..., -) -> NDArray[_SCT]: ... +def asarray_chkfinite(a: _ArrayLike[_SCT], dtype: None = ..., order: np._OrderKACF = ...) -> NDArray[_SCT]: ... @overload -def asarray_chkfinite( - a: object, - dtype: None = ..., - order: _OrderKACF = ..., -) -> NDArray[Any]: ... +def asarray_chkfinite(a: object, dtype: None = ..., order: np._OrderKACF = ...) -> NDArray[Any]: ... @overload -def asarray_chkfinite( - a: Any, - dtype: _DTypeLike[_SCT], - order: _OrderKACF = ..., -) -> NDArray[_SCT]: ... +def asarray_chkfinite(a: Any, dtype: _DTypeLike[_SCT], order: np._OrderKACF = ...) -> NDArray[_SCT]: ... @overload -def asarray_chkfinite( - a: Any, - dtype: DTypeLike, - order: _OrderKACF = ..., -) -> NDArray[Any]: ... +def asarray_chkfinite(a: Any, dtype: DTypeLike, order: np._OrderKACF = ...) -> NDArray[Any]: ... + +# @overload def piecewise( x: _ArrayLike[_SCT], - condlist: _ArrayLike[bool_] | Sequence[_ArrayLikeBool_co], + condlist: _ArrayLike[np.bool_] | Sequence[_ArrayLikeBool_co], funclist: Sequence[Callable[Concatenate[NDArray[_SCT], _Pss], NDArray[_SCT | Any]] | _SCT | object], /, *args: _Pss.args, @@ -233,56 +225,32 @@ def piecewise( @overload def piecewise( x: ArrayLike, - condlist: _ArrayLike[bool_] | Sequence[_ArrayLikeBool_co], + condlist: _ArrayLike[np.bool_] | Sequence[_ArrayLikeBool_co], funclist: Sequence[Callable[Concatenate[NDArray[Any], _Pss], NDArray[Any]] | object], /, *args: _Pss.args, **kw: _Pss.kwargs, ) -> NDArray[Any]: ... -def select( - condlist: Sequence[ArrayLike], - choicelist: Sequence[ArrayLike], - default: ArrayLike = ..., -) -> NDArray[Any]: ... + +# +def select(condlist: Sequence[ArrayLike], choicelist: Sequence[ArrayLike], default: ArrayLike = ...) -> NDArray[Any]: ... + +# @overload -def copy( - a: _ArrayType, - order: _OrderKACF, - subok: L[True], -) -> _ArrayType: ... +def copy(a: _ArrayT, order: np._OrderKACF, subok: L[True]) -> _ArrayT: ... @overload -def copy( - a: _ArrayType, - order: _OrderKACF = ..., - *, - subok: L[True], -) -> _ArrayType: ... +def copy(a: _ArrayT, order: np._OrderKACF = ..., *, subok: L[True]) -> _ArrayT: ... @overload -def copy( - a: _ArrayLike[_SCT], - order: _OrderKACF = ..., - subok: L[False] = ..., -) -> NDArray[_SCT]: ... +def copy(a: _ArrayLike[_SCT], order: np._OrderKACF = ..., subok: L[False] = ...) -> NDArray[_SCT]: ... @overload -def copy( - a: ArrayLike, - order: _OrderKACF = ..., - subok: L[False] = ..., -) -> NDArray[Any]: ... -def gradient( - f: ArrayLike, - *varargs: ArrayLike, - axis: _ShapeLike | None = ..., - edge_order: L[1, 2] = ..., -) -> Any: ... +def copy(a: ArrayLike, order: np._OrderKACF = ..., subok: L[False] = ...) -> NDArray[Any]: ... + +# +def gradient(f: ArrayLike, *varargs: ArrayLike, axis: _ShapeLike | None = ..., edge_order: L[1, 2] = ...) -> Any: ... + +# @overload -def diff( - a: _T, - n: L[0], - axis: SupportsIndex = ..., - prepend: ArrayLike = ..., - append: ArrayLike = ..., -) -> _T: ... +def diff(a: _T, n: L[0], axis: SupportsIndex = ..., prepend: ArrayLike = ..., append: ArrayLike = ...) -> _T: ... @overload def diff( a: ArrayLike, @@ -291,6 +259,8 @@ def diff( prepend: ArrayLike = ..., append: ArrayLike = ..., ) -> NDArray[Any]: ... + +# @overload # float scalar def interp( x: _FloatLike_co, @@ -299,16 +269,16 @@ def interp( left: _FloatLike_co | None = None, right: _FloatLike_co | None = None, period: _FloatLike_co | None = None, -) -> float64: ... +) -> np.float64: ... @overload # float array def interp( - x: NDArray[floating | integer | np.bool] | _NestedSequence[_FloatLike_co], + x: NDArray[np.floating | np.integer | np.bool] | _NestedSequence[_FloatLike_co], xp: _ArrayLikeFloat_co, fp: _ArrayLikeFloat_co, left: _FloatLike_co | None = None, right: _FloatLike_co | None = None, period: _FloatLike_co | None = None, -) -> NDArray[float64]: ... +) -> NDArray[np.float64]: ... @overload # float scalar or array def interp( x: _ArrayLikeFloat_co, @@ -317,52 +287,52 @@ def interp( left: _FloatLike_co | None = None, right: _FloatLike_co | None = None, period: _FloatLike_co | None = None, -) -> NDArray[float64] | float64: ... +) -> NDArray[np.float64] | np.float64: ... @overload # complex scalar def interp( x: _FloatLike_co, xp: _ArrayLikeFloat_co, - fp: _ArrayLike[complexfloating], + fp: _ArrayLike[np.complexfloating], left: _NumberLike_co | None = None, right: _NumberLike_co | None = None, period: _FloatLike_co | None = None, -) -> complex128: ... +) -> np.complex128: ... @overload # complex or float scalar def interp( x: _FloatLike_co, xp: _ArrayLikeFloat_co, - fp: Sequence[complex | complexfloating], + fp: Sequence[complex | np.ccomplexfloating], left: _NumberLike_co | None = None, right: _NumberLike_co | None = None, period: _FloatLike_co | None = None, -) -> complex128 | float64: ... +) -> np.complex128 | np.float64: ... @overload # complex array def interp( - x: NDArray[floating | integer | np.bool] | _NestedSequence[_FloatLike_co], + x: NDArray[np.floating | np.integer | np.bool] | _NestedSequence[_FloatLike_co], xp: _ArrayLikeFloat_co, - fp: _ArrayLike[complexfloating], + fp: _ArrayLike[np.complexfloating], left: _NumberLike_co | None = None, right: _NumberLike_co | None = None, period: _FloatLike_co | None = None, -) -> NDArray[complex128]: ... +) -> NDArray[np.complex128]: ... @overload # complex or float array def interp( - x: NDArray[floating | integer | np.bool] | _NestedSequence[_FloatLike_co], + x: NDArray[np.floating | np.integer | np.bool] | _NestedSequence[_FloatLike_co], xp: _ArrayLikeFloat_co, - fp: Sequence[complex | complexfloating], + fp: Sequence[complex | np.complexfloating], left: _NumberLike_co | None = None, right: _NumberLike_co | None = None, period: _FloatLike_co | None = None, -) -> NDArray[complex128 | float64]: ... +) -> NDArray[np.complex128 | np.float64]: ... @overload # complex scalar or array def interp( x: _ArrayLikeFloat_co, xp: _ArrayLikeFloat_co, - fp: _ArrayLike[complexfloating], + fp: _ArrayLike[np.complexfloating], left: _NumberLike_co | None = None, right: _NumberLike_co | None = None, period: _FloatLike_co | None = None, -) -> NDArray[complex128] | complex128: ... +) -> NDArray[np.complex128] | np.complex128: ... @overload # complex or float scalar or array def interp( x: _ArrayLikeFloat_co, @@ -371,15 +341,19 @@ def interp( left: _NumberLike_co | None = None, right: _NumberLike_co | None = None, period: _FloatLike_co | None = None, -) -> NDArray[complex128 | float64] | complex128 | float64: ... +) -> NDArray[np.complex128 | np.float64] | np.complex128 | np.float64: ... + +# @overload -def angle(z: _ComplexLike_co, deg: bool = ...) -> floating[Any]: ... +def angle(z: _ComplexLike_co, deg: bool = ...) -> np.floating: ... @overload -def angle(z: object_, deg: bool = ...) -> Any: ... +def angle(z: np.object_, deg: bool = ...) -> Any: ... @overload -def angle(z: _ArrayLikeComplex_co, deg: bool = ...) -> NDArray[floating[Any]]: ... +def angle(z: _ArrayLikeComplex_co, deg: bool = ...) -> NDArray[np.floating]: ... @overload -def angle(z: _ArrayLikeObject_co, deg: bool = ...) -> NDArray[object_]: ... +def angle(z: _ArrayLikeObject_co, deg: bool = ...) -> NDArray[np.object_]: ... + +# @overload def unwrap( p: _ArrayLikeFloat_co, @@ -387,7 +361,7 @@ def unwrap( axis: int = ..., *, period: float = ..., -) -> NDArray[floating[Any]]: ... +) -> NDArray[np.floating]: ... @overload def unwrap( p: _ArrayLikeObject_co, @@ -395,17 +369,22 @@ def unwrap( axis: int = ..., *, period: float = ..., -) -> NDArray[object_]: ... -def sort_complex(a: ArrayLike) -> NDArray[complexfloating[Any, Any]]: ... -def trim_zeros( - filt: _TrimZerosSequence[_T], - trim: L["f", "b", "fb", "bf"] = ..., -) -> _T: ... +) -> NDArray[np.object_]: ... + +# +def sort_complex(a: ArrayLike) -> NDArray[np.complexfloating]: ... +def trim_zeros(filt: _TrimZerosSequence[_T], trim: L["f", "b", "fb", "bf"] = ...) -> _T: ... + +# @overload def extract(condition: ArrayLike, arr: _ArrayLike[_SCT]) -> NDArray[_SCT]: ... @overload def extract(condition: ArrayLike, arr: ArrayLike) -> NDArray[Any]: ... + +# def place(arr: NDArray[Any], mask: ArrayLike, vals: Any) -> None: ... + +# @overload def cov( m: _ArrayLikeFloat_co, @@ -417,7 +396,7 @@ def cov( aweights: ArrayLike | None = ..., *, dtype: None = ..., -) -> NDArray[floating[Any]]: ... +) -> NDArray[np.floating]: ... @overload def cov( m: _ArrayLikeComplex_co, @@ -429,7 +408,7 @@ def cov( aweights: ArrayLike | None = ..., *, dtype: None = ..., -) -> NDArray[complexfloating[Any, Any]]: ... +) -> NDArray[np.complexfloating]: ... @overload def cov( m: _ArrayLikeComplex_co, @@ -463,7 +442,7 @@ def corrcoef( rowvar: bool = ..., *, dtype: None = ..., -) -> NDArray[floating[Any]]: ... +) -> NDArray[np.floating]: ... @overload def corrcoef( m: _ArrayLikeComplex_co, @@ -471,7 +450,7 @@ def corrcoef( rowvar: bool = ..., *, dtype: None = ..., -) -> NDArray[complexfloating[Any, Any]]: ... +) -> NDArray[np.complexfloating]: ... @overload def corrcoef( m: _ArrayLikeComplex_co, @@ -488,23 +467,26 @@ def corrcoef( *, dtype: DTypeLike, ) -> NDArray[Any]: ... -def blackman(M: _FloatLike_co) -> NDArray[floating[Any]]: ... -def bartlett(M: _FloatLike_co) -> NDArray[floating[Any]]: ... -def hanning(M: _FloatLike_co) -> NDArray[floating[Any]]: ... -def hamming(M: _FloatLike_co) -> NDArray[floating[Any]]: ... -def i0(x: _ArrayLikeFloat_co) -> NDArray[floating[Any]]: ... -def kaiser( - M: _FloatLike_co, - beta: _FloatLike_co, -) -> NDArray[floating[Any]]: ... + +# +def blackman(M: _FloatLike_co) -> NDArray[np.floating]: ... +def bartlett(M: _FloatLike_co) -> NDArray[np.floating]: ... +def hanning(M: _FloatLike_co) -> NDArray[np.floating]: ... +def hamming(M: _FloatLike_co) -> NDArray[np.floating]: ... +def i0(x: _ArrayLikeFloat_co) -> NDArray[np.floating]: ... +def kaiser(M: _FloatLike_co, beta: _FloatLike_co) -> NDArray[np.floating]: ... + +# @overload -def sinc(x: _FloatLike_co) -> floating[Any]: ... +def sinc(x: _FloatLike_co) -> np.floating: ... @overload -def sinc(x: _ComplexLike_co) -> complexfloating[Any, Any]: ... +def sinc(x: _ComplexLike_co) -> np.complexfloating: ... @overload -def sinc(x: _ArrayLikeFloat_co) -> NDArray[floating[Any]]: ... +def sinc(x: _ArrayLikeFloat_co) -> NDArray[np.floating]: ... @overload -def sinc(x: _ArrayLikeComplex_co) -> NDArray[complexfloating[Any, Any]]: ... +def sinc(x: _ArrayLikeComplex_co) -> NDArray[np.complexfloating]: ... + +# @overload def median( a: _ArrayLikeFloat_co, @@ -512,7 +494,7 @@ def median( out: None = ..., overwrite_input: bool = ..., keepdims: L[False] = ..., -) -> floating[Any]: ... +) -> np.floating: ... @overload def median( a: _ArrayLikeComplex_co, @@ -520,7 +502,7 @@ def median( out: None = ..., overwrite_input: bool = ..., keepdims: L[False] = ..., -) -> complexfloating[Any, Any]: ... +) -> np.complexfloating: ... @overload def median( a: _ArrayLikeTD64_co, @@ -528,7 +510,7 @@ def median( out: None = ..., overwrite_input: bool = ..., keepdims: L[False] = ..., -) -> timedelta64: ... +) -> np.timedelta64: ... @overload def median( a: _ArrayLikeObject_co, @@ -549,37 +531,22 @@ def median( def median( a: _ArrayLikeFloat_co | _ArrayLikeComplex_co | _ArrayLikeTD64_co | _ArrayLikeObject_co, axis: _ShapeLike | None, - out: _ArrayType, + out: _ArrayT, /, overwrite_input: bool = ..., keepdims: bool = ..., -) -> _ArrayType: ... +) -> _ArrayT: ... @overload def median( a: _ArrayLikeFloat_co | _ArrayLikeComplex_co | _ArrayLikeTD64_co | _ArrayLikeObject_co, axis: _ShapeLike | None = ..., *, - out: _ArrayType, + out: _ArrayT, overwrite_input: bool = ..., keepdims: bool = ..., -) -> _ArrayType: ... - -_MethodKind: TypeAlias = L[ - "inverted_cdf", - "averaged_inverted_cdf", - "closest_observation", - "interpolated_inverted_cdf", - "hazen", - "weibull", - "linear", - "median_unbiased", - "normal_unbiased", - "lower", - "higher", - "midpoint", - "nearest", -] +) -> _ArrayT: ... +# @overload def percentile( a: _ArrayLikeFloat_co, @@ -591,7 +558,7 @@ def percentile( keepdims: L[False] = ..., *, weights: _ArrayLikeFloat_co | None = ..., -) -> floating[Any]: ... +) -> np.floating: ... @overload def percentile( a: _ArrayLikeComplex_co, @@ -603,7 +570,7 @@ def percentile( keepdims: L[False] = ..., *, weights: _ArrayLikeFloat_co | None = ..., -) -> complexfloating[Any, Any]: ... +) -> np.complexfloating: ... @overload def percentile( a: _ArrayLikeTD64_co, @@ -615,7 +582,7 @@ def percentile( keepdims: L[False] = ..., *, weights: _ArrayLikeFloat_co | None = ..., -) -> timedelta64: ... +) -> np.timedelta64: ... @overload def percentile( a: _ArrayLikeDT64_co, @@ -627,7 +594,7 @@ def percentile( keepdims: L[False] = ..., *, weights: _ArrayLikeFloat_co | None = ..., -) -> datetime64: ... +) -> np.datetime64: ... @overload def percentile( a: _ArrayLikeObject_co, @@ -651,7 +618,7 @@ def percentile( keepdims: L[False] = ..., *, weights: _ArrayLikeFloat_co | None = ..., -) -> NDArray[floating[Any]]: ... +) -> NDArray[np.floating]: ... @overload def percentile( a: _ArrayLikeComplex_co, @@ -663,7 +630,7 @@ def percentile( keepdims: L[False] = ..., *, weights: _ArrayLikeFloat_co | None = ..., -) -> NDArray[complexfloating[Any, Any]]: ... +) -> NDArray[np.complexfloating]: ... @overload def percentile( a: _ArrayLikeTD64_co, @@ -675,7 +642,7 @@ def percentile( keepdims: L[False] = ..., *, weights: _ArrayLikeFloat_co | None = ..., -) -> NDArray[timedelta64]: ... +) -> NDArray[np.timedelta64]: ... @overload def percentile( a: _ArrayLikeDT64_co, @@ -687,7 +654,7 @@ def percentile( keepdims: L[False] = ..., *, weights: _ArrayLikeFloat_co | None = ..., -) -> NDArray[datetime64]: ... +) -> NDArray[np.datetime64]: ... @overload def percentile( a: _ArrayLikeObject_co, @@ -699,7 +666,7 @@ def percentile( keepdims: L[False] = ..., *, weights: _ArrayLikeFloat_co | None = ..., -) -> NDArray[object_]: ... +) -> NDArray[np.object_]: ... @overload def percentile( a: _ArrayLikeComplex_co | _ArrayLikeTD64_co | _ArrayLikeDT64_co | _ArrayLikeObject_co, @@ -717,74 +684,66 @@ def percentile( a: _ArrayLikeComplex_co | _ArrayLikeTD64_co | _ArrayLikeDT64_co | _ArrayLikeObject_co, q: _ArrayLikeFloat_co, axis: _ShapeLike | None, - out: _ArrayType, + out: _ArrayT, /, overwrite_input: bool = ..., method: _MethodKind = ..., keepdims: bool = ..., *, weights: _ArrayLikeFloat_co | None = ..., -) -> _ArrayType: ... +) -> _ArrayT: ... @overload def percentile( a: _ArrayLikeComplex_co | _ArrayLikeTD64_co | _ArrayLikeDT64_co | _ArrayLikeObject_co, q: _ArrayLikeFloat_co, axis: _ShapeLike | None = ..., *, - out: _ArrayType, + out: _ArrayT, overwrite_input: bool = ..., method: _MethodKind = ..., keepdims: bool = ..., weights: _ArrayLikeFloat_co | None = ..., -) -> _ArrayType: ... +) -> _ArrayT: ... # NOTE: Not an alias, but they do have identical signatures # (that we can reuse) quantile = percentile -_SCT_fm = TypeVar( - "_SCT_fm", - bound=floating[Any] | complexfloating[Any, Any] | timedelta64, -) - -class _SupportsRMulFloat(Protocol[_T_co]): - def __rmul__(self, other: float, /) -> _T_co: ... - @overload -def trapezoid( # type: ignore[overload-overlap] +def trapezoid( y: Sequence[_FloatLike_co], x: Sequence[_FloatLike_co] | None = ..., dx: float = ..., axis: SupportsIndex = ..., -) -> float64: ... +) -> np.float64: ... @overload def trapezoid( y: Sequence[_ComplexLike_co], x: Sequence[_ComplexLike_co] | None = ..., dx: float = ..., axis: SupportsIndex = ..., -) -> complex128: ... +) -> np.complex128: ... @overload def trapezoid( - y: _ArrayLike[bool_ | integer[Any]], - x: _ArrayLike[bool_ | integer[Any]] | None = ..., + y: _ArrayLike[np.bool_ | np.integer], + x: _ArrayLike[np.bool_ | np.integer] | None = ..., dx: float = ..., axis: SupportsIndex = ..., -) -> float64 | NDArray[float64]: ... +) -> np.float64 | NDArray[np.float64]: ... @overload -def trapezoid( # type: ignore[overload-overlap] +def trapezoid( y: _ArrayLikeObject_co, x: _ArrayLikeFloat_co | _ArrayLikeObject_co | None = ..., dx: float = ..., axis: SupportsIndex = ..., -) -> float | NDArray[object_]: ... +) -> float | NDArray[np.object_]: ... @overload def trapezoid( - y: _ArrayLike[_SCT_fm], - x: _ArrayLike[_SCT_fm] | _ArrayLikeInt_co | None = ..., + y: _ArrayLike[_SCT_fcm], + x: _ArrayLike[_SCT_fcm] | _ArrayLikeInt_co | None = ..., dx: float = ..., axis: SupportsIndex = ..., -) -> _SCT_fm | NDArray[_SCT_fm]: ... +) -> _SCT_fcm | NDArray[_SCT_fcm]: ... @overload def trapezoid( y: Sequence[_SupportsRMulFloat[_T]], @@ -798,32 +757,27 @@ def trapezoid( x: _ArrayLikeComplex_co | _ArrayLikeTD64_co | _ArrayLikeObject_co | None = ..., dx: float = ..., axis: SupportsIndex = ..., -) -> ( - floating[Any] - | complexfloating[Any, Any] - | timedelta64 - | NDArray[floating[Any] | complexfloating[Any, Any] | timedelta64 | object_] -): ... +) -> np.inexact | np.timedelta64 | NDArray[np.inexact | np.timedelta64 | np.object_]: ... + +# @deprecated("Use 'trapezoid' instead") -def trapz(y: ArrayLike, x: ArrayLike | None = None, dx: float = 1.0, axis: int = -1) -> generic | NDArray[generic]: ... -def meshgrid( - *xi: ArrayLike, - copy: bool = ..., - sparse: bool = ..., - indexing: L["xy", "ij"] = ..., -) -> tuple[NDArray[Any], ...]: ... -@overload -def delete( - arr: _ArrayLike[_SCT], - obj: slice | _ArrayLikeInt_co, - axis: SupportsIndex | None = ..., -) -> NDArray[_SCT]: ... +def trapz( + y: ArrayLike, + x: ArrayLike | None = None, + dx: float = 1.0, + axis: int = -1, +) -> np.inexact | np.timedelta64 | NDArray[np.inexact | np.timedelta64 | np.object_]: ... + +# +def meshgrid(*xi: ArrayLike, copy: bool = ..., sparse: bool = ..., indexing: L["xy", "ij"] = ...) -> tuple[NDArray[Any], ...]: ... + +# @overload -def delete( - arr: ArrayLike, - obj: slice | _ArrayLikeInt_co, - axis: SupportsIndex | None = ..., -) -> NDArray[Any]: ... +def delete(arr: _ArrayLike[_SCT], obj: slice | _ArrayLikeInt_co, axis: SupportsIndex | None = ...) -> NDArray[_SCT]: ... +@overload +def delete(arr: ArrayLike, obj: slice | _ArrayLikeInt_co, axis: SupportsIndex | None = ...) -> NDArray[Any]: ... + +# @overload def insert( arr: _ArrayLike[_SCT], @@ -838,20 +792,12 @@ def insert( values: ArrayLike, axis: SupportsIndex | None = ..., ) -> NDArray[Any]: ... -def append( - arr: ArrayLike, - values: ArrayLike, - axis: SupportsIndex | None = ..., -) -> NDArray[Any]: ... + +# +def append(arr: ArrayLike, values: ArrayLike, axis: SupportsIndex | None = ...) -> NDArray[Any]: ... + +# @overload -def digitize( - x: _FloatLike_co, - bins: _ArrayLikeFloat_co, - right: bool = ..., -) -> intp: ... +def digitize(x: _FloatLike_co, bins: _ArrayLikeFloat_co, right: bool = ...) -> np.int_: ... @overload -def digitize( - x: _ArrayLikeFloat_co, - bins: _ArrayLikeFloat_co, - right: bool = ..., -) -> NDArray[intp]: ... +def digitize(x: _ArrayLikeFloat_co, bins: _ArrayLikeFloat_co, right: bool = ...) -> NDArray[np.int_]: ... diff --git a/src/numpy-stubs/lib/_index_tricks_impl.pyi b/src/numpy-stubs/lib/_index_tricks_impl.pyi index 4365253c..16e52e3b 100644 --- a/src/numpy-stubs/lib/_index_tricks_impl.pyi +++ b/src/numpy-stubs/lib/_index_tricks_impl.pyi @@ -1,40 +1,12 @@ +from _typeshed import Incomplete from collections.abc import Sequence -from typing import ( - Any, - Generic, - Literal, - SupportsIndex, - TypeVar, - overload, -) +from typing import Any, Final, Generic, Literal, SupportsIndex, overload +from typing_extensions import TypeVar import numpy as np -from numpy import ( - bytes_, - complex128, - dtype, - float64, - int_, - # Circumvent a naming conflict with `AxisConcatenator.matrix` - matrix as _Matrix, - ndarray, - ndenumerate, - ndindex, - str_, -) +from numpy import ndenumerate, ndindex # noqa: ICN003 from numpy._core.multiarray import ravel_multi_index, unravel_index -from numpy._typing import ( - # Arrays - ArrayLike, - # DTypes - DTypeLike, - NDArray, - _FiniteNestedSequence, - _NestedSequence, - # Shapes - _Shape, - _SupportsDType, -) +from numpy._typing import ArrayLike, DTypeLike, NDArray, _FiniteNestedSequence, _NestedSequence, _Shape, _SupportsDType __all__ = [ "c_", @@ -54,75 +26,59 @@ __all__ = [ ] _T = TypeVar("_T") -_DType = TypeVar("_DType", bound=dtype[Any]) -_BoolType = TypeVar("_BoolType", Literal[True], Literal[False]) -_TupType = TypeVar("_TupType", bound=tuple[Any, ...]) -_ArrayType = TypeVar("_ArrayType", bound=NDArray[Any]) +_DTypeT = TypeVar("_DTypeT", bound=np.dtype[Any]) +_BoolT_co = TypeVar("_BoolT_co", bound=bool, default=bool, covariant=True) +_TupleT = TypeVar("_TupleT", bound=tuple[object, ...]) +_ArrayT = TypeVar("_ArrayT", bound=NDArray[Any]) @overload -def ix_(*args: _FiniteNestedSequence[_SupportsDType[_DType]]) -> tuple[ndarray[_Shape, _DType], ...]: ... +def ix_(*args: _FiniteNestedSequence[_SupportsDType[_DTypeT]]) -> tuple[np.ndarray[_Shape, _DTypeT], ...]: ... @overload -def ix_(*args: str | _NestedSequence[str]) -> tuple[NDArray[str_], ...]: ... +def ix_(*args: str | _NestedSequence[str]) -> tuple[NDArray[np.str_], ...]: ... @overload -def ix_(*args: bytes | _NestedSequence[bytes]) -> tuple[NDArray[bytes_], ...]: ... +def ix_(*args: bytes | _NestedSequence[bytes]) -> tuple[NDArray[np.bytes_], ...]: ... @overload def ix_(*args: bool | _NestedSequence[bool]) -> tuple[NDArray[np.bool], ...]: ... @overload -def ix_(*args: int | _NestedSequence[int]) -> tuple[NDArray[int_], ...]: ... +def ix_(*args: int | _NestedSequence[int]) -> tuple[NDArray[np.int_], ...]: ... @overload -def ix_(*args: float | _NestedSequence[float]) -> tuple[NDArray[float64], ...]: ... +def ix_(*args: float | _NestedSequence[float]) -> tuple[NDArray[np.float64], ...]: ... @overload -def ix_(*args: complex | _NestedSequence[complex]) -> tuple[NDArray[complex128], ...]: ... +def ix_(*args: complex | _NestedSequence[complex]) -> tuple[NDArray[np.complex128], ...]: ... -class nd_grid(Generic[_BoolType]): - sparse: _BoolType - def __init__(self, sparse: _BoolType = ...) -> None: ... +class nd_grid(Generic[_BoolT_co]): + sparse: _BoolT_co + def __init__(self, sparse: _BoolT_co = ...) -> None: ... @overload - def __getitem__( - self: nd_grid[Literal[False]], - key: slice | Sequence[slice], - ) -> NDArray[Any]: ... + def __getitem__(self: nd_grid[Literal[False]], key: slice | Sequence[slice]) -> NDArray[Any]: ... @overload - def __getitem__( - self: nd_grid[Literal[True]], - key: slice | Sequence[slice], - ) -> tuple[NDArray[Any], ...]: ... + def __getitem__(self: nd_grid[Literal[True]], key: slice | Sequence[slice]) -> tuple[NDArray[Any], ...]: ... class MGridClass(nd_grid[Literal[False]]): def __init__(self) -> None: ... -mgrid: MGridClass +mgrid: Final[MGridClass] = ... class OGridClass(nd_grid[Literal[True]]): def __init__(self) -> None: ... -ogrid: OGridClass +ogrid: Final[OGridClass] = ... class AxisConcatenator: axis: int matrix: bool ndmin: int trans1d: int - def __init__( - self, - axis: int = ..., - matrix: bool = ..., - ndmin: int = ..., - trans1d: int = ..., - ) -> None: ... + def __init__(self, axis: int = ..., matrix: bool = ..., ndmin: int = ..., trans1d: int = ...) -> None: ... @staticmethod @overload - def concatenate( # type: ignore[misc] - *a: ArrayLike, axis: SupportsIndex = ..., out: None = ... - ) -> NDArray[Any]: ... + def concatenate(*a: ArrayLike, axis: SupportsIndex = ..., out: None = ...) -> NDArray[Any]: ... @staticmethod @overload - def concatenate(*a: ArrayLike, axis: SupportsIndex = ..., out: _ArrayType = ...) -> _ArrayType: ... + def concatenate(*a: ArrayLike, axis: SupportsIndex = ..., out: _ArrayT) -> _ArrayT: ... @staticmethod - def makemat(data: ArrayLike, dtype: DTypeLike = ..., copy: bool = ...) -> _Matrix[Any, Any]: ... - - # TODO: Sort out this `__getitem__` method - def __getitem__(self, key: Any) -> Any: ... + def makemat(data: ArrayLike, dtype: DTypeLike = ..., copy: bool = ...) -> np.matrix[Any, Any]: ... + def __getitem__(self, key: Incomplete, /) -> Incomplete: ... class RClass(AxisConcatenator): axis: Literal[0] @@ -131,7 +87,7 @@ class RClass(AxisConcatenator): trans1d: Literal[-1] def __init__(self) -> None: ... -r_: RClass +r_: Final[RClass] = ... class CClass(AxisConcatenator): axis: Literal[-1] @@ -140,23 +96,21 @@ class CClass(AxisConcatenator): trans1d: Literal[0] def __init__(self) -> None: ... -c_: CClass +c_: Final[CClass] = ... -class IndexExpression(Generic[_BoolType]): - maketuple: _BoolType - def __init__(self, maketuple: _BoolType) -> None: ... +class IndexExpression(Generic[_BoolT_co]): + maketuple: _BoolT_co + def __init__(self, maketuple: _BoolT_co) -> None: ... @overload - def __getitem__(self, item: _TupType) -> _TupType: ... # type: ignore[misc] + def __getitem__(self, item: _TupleT) -> _TupleT: ... # type: ignore[misc] @overload def __getitem__(self: IndexExpression[Literal[True]], item: _T) -> tuple[_T]: ... @overload def __getitem__(self: IndexExpression[Literal[False]], item: _T) -> _T: ... -index_exp: IndexExpression[Literal[True]] -s_: IndexExpression[Literal[False]] +index_exp: Final[IndexExpression[Literal[True]]] = ... +s_: Final[IndexExpression[Literal[False]]] = ... def fill_diagonal(a: NDArray[Any], val: Any, wrap: bool = ...) -> None: ... -def diag_indices(n: int, ndim: int = ...) -> tuple[NDArray[int_], ...]: ... -def diag_indices_from(arr: ArrayLike) -> tuple[NDArray[int_], ...]: ... - -# NOTE: see `numpy/__init__.pyi` for `ndenumerate` and `ndindex` +def diag_indices(n: int, ndim: int = ...) -> tuple[NDArray[np.int_], ...]: ... +def diag_indices_from(arr: ArrayLike) -> tuple[NDArray[np.int_], ...]: ... diff --git a/src/numpy-stubs/lib/_npyio_impl.pyi b/src/numpy-stubs/lib/_npyio_impl.pyi index 8f362514..ca7a6cbc 100644 --- a/src/numpy-stubs/lib/_npyio_impl.pyi +++ b/src/numpy-stubs/lib/_npyio_impl.pyi @@ -3,35 +3,12 @@ import zipfile from _typeshed import StrOrBytesPath, StrPath, SupportsKeysAndGetItem, SupportsRead, SupportsWrite from collections.abc import Callable, Collection, Iterable, Iterator, Mapping, Sequence from re import Pattern -from typing import ( - IO, - Any, - Generic, - Literal as L, - Protocol, - Self, - TypeVar, - overload, - type_check_only, -) -from typing_extensions import deprecated +from typing import IO, Any, Generic, Literal as L, Protocol, TypeVar, overload, type_check_only +from typing_extensions import Self, deprecated -from numpy import ( - dtype, - float64, - generic, - recarray, - record, - void, -) +import numpy as np from numpy._core.multiarray import packbits, unpackbits -from numpy._typing import ( - ArrayLike, - DTypeLike, - NDArray, - _DTypeLike, - _SupportsArrayFunc, -) +from numpy._typing import ArrayLike, DTypeLike, NDArray, _DTypeLike, _SupportsArrayFunc from numpy.ma.mrecords import MaskedRecords __all__ = [ @@ -48,9 +25,8 @@ __all__ = [ ] _T = TypeVar("_T") -_T_contra = TypeVar("_T_contra", contravariant=True) _T_co = TypeVar("_T_co", covariant=True) -_SCT = TypeVar("_SCT", bound=generic) +_SCT = TypeVar("_SCT", bound=np.generic) @type_check_only class _SupportsReadSeek(SupportsRead[_T_co], Protocol[_T_co]): @@ -72,28 +48,22 @@ class NpzFile(Mapping[str, NDArray[Any]]): @property def f(self: _T) -> BagObj[_T]: ... @f.setter - def f(self: _T, value: BagObj[_T]) -> None: ... + def f(self: _T, value: BagObj[_T], /) -> None: ... def __init__( self, fid: IO[str], own_fid: bool = ..., allow_pickle: bool = ..., - pickle_kwargs: Mapping[str, Any] | None = ..., + pickle_kwargs: Mapping[str, object] | None = ..., ) -> None: ... def __enter__(self) -> Self: ... - def __exit__( - self, - exc_type: type[BaseException] | None, - exc_value: BaseException | None, - traceback: types.TracebackType | None, - /, - ) -> None: ... + def __exit__(self, cls: type[BaseException] | None, e: BaseException | None, tb: types.TracebackType | None, /) -> None: ... def close(self) -> None: ... def __del__(self) -> None: ... def __iter__(self) -> Iterator[str]: ... def __len__(self) -> int: ... - def __getitem__(self, key: str) -> NDArray[Any]: ... - def __contains__(self, key: str) -> bool: ... + def __getitem__(self, key: str, /) -> NDArray[Any]: ... + def __contains__(self, key: str, /) -> bool: ... class DataSource: def __init__(self, destpath: StrPath | None = ...) -> None: ... @@ -103,13 +73,7 @@ class DataSource: # Whether the file-object is opened in string or bytes mode (by default) # depends on the file-extension of `path` - def open( - self, - path: str, - mode: str = ..., - encoding: str | None = ..., - newline: str | None = ..., - ) -> IO[Any]: ... + def open(self, path: str, mode: str = ..., encoding: str | None = ..., newline: str | None = ...) -> IO[Any]: ... # NOTE: Returns a `NpzFile` if file is a zip file; # returns an `ndarray`/`memmap` otherwise @@ -121,34 +85,14 @@ def load( encoding: L["ASCII", "latin1", "bytes"] = ..., ) -> Any: ... @overload -def save( - file: StrPath | SupportsWrite[bytes], - arr: ArrayLike, - allow_pickle: bool = ..., -) -> None: ... +def save(file: StrPath | SupportsWrite[bytes], arr: ArrayLike, allow_pickle: bool = ...) -> None: ... @overload @deprecated("The 'fix_imports' flag is deprecated in NumPy 2.1.") -def save( - file: StrPath | SupportsWrite[bytes], - arr: ArrayLike, - allow_pickle: bool = ..., - *, - fix_imports: bool, -) -> None: ... +def save(file: StrPath | SupportsWrite[bytes], arr: ArrayLike, allow_pickle: bool = ..., *, fix_imports: bool) -> None: ... @overload @deprecated("The 'fix_imports' flag is deprecated in NumPy 2.1.") -def save( - file: StrPath | SupportsWrite[bytes], - arr: ArrayLike, - allow_pickle: bool, - fix_imports: bool, -) -> None: ... -def savez( - file: StrPath | SupportsWrite[bytes], - *args: ArrayLike, - allow_pickle: bool = ..., - **kwds: ArrayLike, -) -> None: ... +def save(file: StrPath | SupportsWrite[bytes], arr: ArrayLike, allow_pickle: bool, fix_imports: bool) -> None: ... +def savez(file: StrPath | SupportsWrite[bytes], *args: ArrayLike, allow_pickle: bool = ..., **kwds: ArrayLike) -> None: ... def savez_compressed( file: StrPath | SupportsWrite[bytes], *args: ArrayLike, @@ -174,7 +118,7 @@ def loadtxt( *, quotechar: str | None = ..., like: _SupportsArrayFunc | None = ..., -) -> NDArray[float64]: ... +) -> NDArray[np.float64]: ... @overload def loadtxt( fname: StrPath | Iterable[str] | Iterable[bytes], @@ -326,26 +270,26 @@ def recfromtxt( fname: StrPath | Iterable[str] | Iterable[bytes], *, usemask: L[False] = ..., - **kwargs: Any, -) -> recarray[Any, dtype[record]]: ... + **kwargs: object, +) -> np.recarray[Any, np.dtype[np.record]]: ... @overload def recfromtxt( fname: StrPath | Iterable[str] | Iterable[bytes], *, usemask: L[True], - **kwargs: Any, -) -> MaskedRecords[Any, dtype[void]]: ... + **kwargs: object, +) -> MaskedRecords[Any, np.dtype[np.void]]: ... @overload def recfromcsv( fname: StrPath | Iterable[str] | Iterable[bytes], *, usemask: L[False] = ..., - **kwargs: Any, -) -> recarray[Any, dtype[record]]: ... + **kwargs: object, +) -> np.recarray[Any, np.dtype[np.record]]: ... @overload def recfromcsv( fname: StrPath | Iterable[str] | Iterable[bytes], *, usemask: L[True], - **kwargs: Any, -) -> MaskedRecords[Any, dtype[void]]: ... + **kwargs: object, +) -> MaskedRecords[Any, np.dtype[np.void]]: ... diff --git a/src/numpy-stubs/lib/_polynomial_impl.pyi b/src/numpy-stubs/lib/_polynomial_impl.pyi index d14f2298..0e4fdd9a 100644 --- a/src/numpy-stubs/lib/_polynomial_impl.pyi +++ b/src/numpy-stubs/lib/_polynomial_impl.pyi @@ -1,27 +1,7 @@ -from typing import ( - Any, - Literal as L, - NoReturn, - SupportsIndex, - SupportsInt, - TypeAlias, - TypeVar, - overload, -) +from typing import Any, Literal as L, NoReturn, SupportsIndex, SupportsInt, TypeAlias, TypeVar, overload import numpy as np -from numpy import ( - complex128, - complexfloating, - float64, - floating, - int32, - int64, - object_, - poly1d, - signedinteger, - unsignedinteger, -) +from numpy import poly1d # noqa: ICN003 from numpy._typing import ( ArrayLike, NDArray, @@ -36,77 +16,47 @@ from numpy._typing import ( _T = TypeVar("_T") _2Tup: TypeAlias = tuple[_T, _T] -_5Tup: TypeAlias = tuple[ - _T, - NDArray[float64], - NDArray[int32], - NDArray[float64], - NDArray[float64], -] +_5Tup: TypeAlias = tuple[_T, NDArray[np.np.float64], NDArray[np.int32], NDArray[np.float64], NDArray[np.float64]] -__all__ = [ - "poly", - "poly1d", - "polyadd", - "polyder", - "polydiv", - "polyfit", - "polyint", - "polymul", - "polysub", - "polyval", - "roots", -] +__all__ = ["poly", "poly1d", "polyadd", "polyder", "polydiv", "polyfit", "polyint", "polymul", "polysub", "polyval", "roots"] -def poly(seq_of_zeros: ArrayLike) -> NDArray[floating[Any]]: ... +def poly(seq_of_zeros: ArrayLike) -> NDArray[np.floating]: ... # Returns either a float or complex array depending on the input values. # See `np.linalg.eigvals`. -def roots(p: ArrayLike) -> NDArray[complexfloating[Any, Any]] | NDArray[floating[Any]]: ... +def roots(p: ArrayLike) -> NDArray[np.inexact]: ... @overload def polyint( - p: poly1d, + p: np.poly1d, m: SupportsInt | SupportsIndex = ..., k: _ArrayLikeComplex_co | _ArrayLikeObject_co | None = ..., -) -> poly1d: ... +) -> np.poly1d: ... @overload def polyint( p: _ArrayLikeFloat_co, m: SupportsInt | SupportsIndex = ..., k: _ArrayLikeFloat_co | None = ..., -) -> NDArray[floating[Any]]: ... +) -> NDArray[np.floating]: ... @overload def polyint( p: _ArrayLikeComplex_co, m: SupportsInt | SupportsIndex = ..., k: _ArrayLikeComplex_co | None = ..., -) -> NDArray[complexfloating[Any, Any]]: ... +) -> NDArray[np.complexfloating]: ... @overload def polyint( p: _ArrayLikeObject_co, m: SupportsInt | SupportsIndex = ..., k: _ArrayLikeObject_co | None = ..., -) -> NDArray[object_]: ... +) -> NDArray[np.object_]: ... @overload -def polyder( - p: poly1d, - m: SupportsInt | SupportsIndex = ..., -) -> poly1d: ... +def polyder(p: np.poly1d, m: SupportsInt | SupportsIndex = ...) -> np.poly1d: ... @overload -def polyder( - p: _ArrayLikeFloat_co, - m: SupportsInt | SupportsIndex = ..., -) -> NDArray[floating[Any]]: ... +def polyder(p: _ArrayLikeFloat_co, m: SupportsInt | SupportsIndex = ...) -> NDArray[np.floating]: ... @overload -def polyder( - p: _ArrayLikeComplex_co, - m: SupportsInt | SupportsIndex = ..., -) -> NDArray[complexfloating[Any, Any]]: ... +def polyder(p: _ArrayLikeComplex_co, m: SupportsInt | SupportsIndex = ...) -> NDArray[np.complexfloating]: ... @overload -def polyder( - p: _ArrayLikeObject_co, - m: SupportsInt | SupportsIndex = ..., -) -> NDArray[object_]: ... +def polyder(p: _ArrayLikeObject_co, m: SupportsInt | SupportsIndex = ...) -> NDArray[np.object_]: ... @overload def polyfit( x: _ArrayLikeFloat_co, @@ -116,7 +66,7 @@ def polyfit( full: L[False] = ..., w: _ArrayLikeFloat_co | None = ..., cov: L[False] = ..., -) -> NDArray[float64]: ... +) -> NDArray[np.float64]: ... @overload def polyfit( x: _ArrayLikeComplex_co, @@ -126,7 +76,7 @@ def polyfit( full: L[False] = ..., w: _ArrayLikeFloat_co | None = ..., cov: L[False] = ..., -) -> NDArray[complex128]: ... +) -> NDArray[np.complex128]: ... @overload def polyfit( x: _ArrayLikeFloat_co, @@ -136,7 +86,7 @@ def polyfit( full: L[False] = ..., w: _ArrayLikeFloat_co | None = ..., cov: L[True, "unscaled"] = ..., -) -> _2Tup[NDArray[float64]]: ... +) -> _2Tup[NDArray[np.float64]]: ... @overload def polyfit( x: _ArrayLikeComplex_co, @@ -146,7 +96,7 @@ def polyfit( full: L[False] = ..., w: _ArrayLikeFloat_co | None = ..., cov: L[True, "unscaled"] = ..., -) -> _2Tup[NDArray[complex128]]: ... +) -> _2Tup[NDArray[np.complex128]]: ... @overload def polyfit( x: _ArrayLikeFloat_co, @@ -156,7 +106,7 @@ def polyfit( full: L[True] = ..., w: _ArrayLikeFloat_co | None = ..., cov: bool | L["unscaled"] = ..., -) -> _5Tup[NDArray[float64]]: ... +) -> _5Tup[NDArray[np.float64]]: ... @overload def polyfit( x: _ArrayLikeComplex_co, @@ -166,143 +116,62 @@ def polyfit( full: L[True] = ..., w: _ArrayLikeFloat_co | None = ..., cov: bool | L["unscaled"] = ..., -) -> _5Tup[NDArray[complex128]]: ... +) -> _5Tup[NDArray[np.complex128]]: ... @overload -def polyval( - p: _ArrayLikeBool_co, - x: _ArrayLikeBool_co, -) -> NDArray[int64]: ... +def polyval(p: _ArrayLikeBool_co, x: _ArrayLikeBool_co) -> NDArray[np.int64]: ... @overload -def polyval( - p: _ArrayLikeUInt_co, - x: _ArrayLikeUInt_co, -) -> NDArray[unsignedinteger[Any]]: ... +def polyval(p: _ArrayLikeUInt_co, x: _ArrayLikeUInt_co) -> NDArray[np.unsignedinteger]: ... @overload -def polyval( - p: _ArrayLikeInt_co, - x: _ArrayLikeInt_co, -) -> NDArray[signedinteger[Any]]: ... +def polyval(p: _ArrayLikeInt_co, x: _ArrayLikeInt_co) -> NDArray[np.signedinteger]: ... @overload -def polyval( - p: _ArrayLikeFloat_co, - x: _ArrayLikeFloat_co, -) -> NDArray[floating[Any]]: ... +def polyval(p: _ArrayLikeFloat_co, x: _ArrayLikeFloat_co) -> NDArray[np.floating]: ... @overload -def polyval( - p: _ArrayLikeComplex_co, - x: _ArrayLikeComplex_co, -) -> NDArray[complexfloating[Any, Any]]: ... +def polyval(p: _ArrayLikeComplex_co, x: _ArrayLikeComplex_co) -> NDArray[np.complexfloating]: ... @overload -def polyval( - p: _ArrayLikeObject_co, - x: _ArrayLikeObject_co, -) -> NDArray[object_]: ... -@overload -def polyadd( - a1: poly1d, - a2: _ArrayLikeComplex_co | _ArrayLikeObject_co, -) -> poly1d: ... -@overload -def polyadd( - a1: _ArrayLikeComplex_co | _ArrayLikeObject_co, - a2: poly1d, -) -> poly1d: ... -@overload -def polyadd( - a1: _ArrayLikeBool_co, - a2: _ArrayLikeBool_co, -) -> NDArray[np.bool]: ... -@overload -def polyadd( - a1: _ArrayLikeUInt_co, - a2: _ArrayLikeUInt_co, -) -> NDArray[unsignedinteger[Any]]: ... -@overload -def polyadd( - a1: _ArrayLikeInt_co, - a2: _ArrayLikeInt_co, -) -> NDArray[signedinteger[Any]]: ... -@overload -def polyadd( - a1: _ArrayLikeFloat_co, - a2: _ArrayLikeFloat_co, -) -> NDArray[floating[Any]]: ... -@overload -def polyadd( - a1: _ArrayLikeComplex_co, - a2: _ArrayLikeComplex_co, -) -> NDArray[complexfloating[Any, Any]]: ... -@overload -def polyadd( - a1: _ArrayLikeObject_co, - a2: _ArrayLikeObject_co, -) -> NDArray[object_]: ... -@overload -def polysub( - a1: poly1d, - a2: _ArrayLikeComplex_co | _ArrayLikeObject_co, -) -> poly1d: ... -@overload -def polysub( - a1: _ArrayLikeComplex_co | _ArrayLikeObject_co, - a2: poly1d, -) -> poly1d: ... -@overload -def polysub( - a1: _ArrayLikeBool_co, - a2: _ArrayLikeBool_co, -) -> NoReturn: ... -@overload -def polysub( - a1: _ArrayLikeUInt_co, - a2: _ArrayLikeUInt_co, -) -> NDArray[unsignedinteger[Any]]: ... -@overload -def polysub( - a1: _ArrayLikeInt_co, - a2: _ArrayLikeInt_co, -) -> NDArray[signedinteger[Any]]: ... -@overload -def polysub( - a1: _ArrayLikeFloat_co, - a2: _ArrayLikeFloat_co, -) -> NDArray[floating[Any]]: ... -@overload -def polysub( - a1: _ArrayLikeComplex_co, - a2: _ArrayLikeComplex_co, -) -> NDArray[complexfloating[Any, Any]]: ... -@overload -def polysub( - a1: _ArrayLikeObject_co, - a2: _ArrayLikeObject_co, -) -> NDArray[object_]: ... +def polyval(p: _ArrayLikeObject_co, x: _ArrayLikeObject_co) -> NDArray[np.object_]: ... +@overload +def polyadd(a1: np.poly1d, a2: _ArrayLikeComplex_co | _ArrayLikeObject_co) -> np.poly1d: ... +@overload +def polyadd(a1: _ArrayLikeComplex_co | _ArrayLikeObject_co, a2: np.poly1d) -> np.poly1d: ... +@overload +def polyadd(a1: _ArrayLikeBool_co, a2: _ArrayLikeBool_co) -> NDArray[np.bool]: ... +@overload +def polyadd(a1: _ArrayLikeUInt_co, a2: _ArrayLikeUInt_co) -> NDArray[np.unsignedinteger]: ... +@overload +def polyadd(a1: _ArrayLikeInt_co, a2: _ArrayLikeInt_co) -> NDArray[np.signedinteger]: ... +@overload +def polyadd(a1: _ArrayLikeFloat_co, a2: _ArrayLikeFloat_co) -> NDArray[np.floating]: ... +@overload +def polyadd(a1: _ArrayLikeComplex_co, a2: _ArrayLikeComplex_co) -> NDArray[np.complexfloating]: ... +@overload +def polyadd(a1: _ArrayLikeObject_co, a2: _ArrayLikeObject_co) -> NDArray[np.object_]: ... +@overload +def polysub(a1: np.poly1d, a2: _ArrayLikeComplex_co | _ArrayLikeObject_co) -> np.poly1d: ... +@overload +def polysub(a1: _ArrayLikeComplex_co | _ArrayLikeObject_co, a2: np.poly1d) -> np.poly1d: ... +@overload +def polysub(a1: _ArrayLikeBool_co, a2: _ArrayLikeBool_co) -> NoReturn: ... +@overload +def polysub(a1: _ArrayLikeUInt_co, a2: _ArrayLikeUInt_co) -> NDArray[np.unsignedinteger]: ... +@overload +def polysub(a1: _ArrayLikeInt_co, a2: _ArrayLikeInt_co) -> NDArray[np.signedinteger]: ... +@overload +def polysub(a1: _ArrayLikeFloat_co, a2: _ArrayLikeFloat_co) -> NDArray[np.floating]: ... +@overload +def polysub(a1: _ArrayLikeComplex_co, a2: _ArrayLikeComplex_co) -> NDArray[np.complexfloating]: ... +@overload +def polysub(a1: _ArrayLikeObject_co, a2: _ArrayLikeObject_co) -> NDArray[np.object_]: ... # NOTE: Not an alias, but they do have the same signature (that we can reuse) polymul = polyadd @overload -def polydiv( - u: poly1d, - v: _ArrayLikeComplex_co | _ArrayLikeObject_co, -) -> _2Tup[poly1d]: ... -@overload -def polydiv( - u: _ArrayLikeComplex_co | _ArrayLikeObject_co, - v: poly1d, -) -> _2Tup[poly1d]: ... -@overload -def polydiv( - u: _ArrayLikeFloat_co, - v: _ArrayLikeFloat_co, -) -> _2Tup[NDArray[floating[Any]]]: ... -@overload -def polydiv( - u: _ArrayLikeComplex_co, - v: _ArrayLikeComplex_co, -) -> _2Tup[NDArray[complexfloating[Any, Any]]]: ... -@overload -def polydiv( - u: _ArrayLikeObject_co, - v: _ArrayLikeObject_co, -) -> _2Tup[NDArray[Any]]: ... +def polydiv(u: np.poly1d, v: _ArrayLikeComplex_co | _ArrayLikeObject_co) -> _2Tup[np.poly1d]: ... +@overload +def polydiv(u: _ArrayLikeComplex_co | _ArrayLikeObject_co, v: np.poly1d) -> _2Tup[np.poly1d]: ... +@overload +def polydiv(u: _ArrayLikeFloat_co, v: _ArrayLikeFloat_co) -> _2Tup[NDArray[np.floating]]: ... +@overload +def polydiv(u: _ArrayLikeComplex_co, v: _ArrayLikeComplex_co) -> _2Tup[NDArray[np.complexfloating]]: ... +@overload +def polydiv(u: _ArrayLikeObject_co, v: _ArrayLikeObject_co) -> _2Tup[NDArray[Any]]: ... diff --git a/src/numpy-stubs/lib/_scimath_impl.pyi b/src/numpy-stubs/lib/_scimath_impl.pyi index 49f1093c..9cbb6d9b 100644 --- a/src/numpy-stubs/lib/_scimath_impl.pyi +++ b/src/numpy-stubs/lib/_scimath_impl.pyi @@ -1,85 +1,79 @@ from typing import Any, overload -from numpy import complexfloating -from numpy._typing import ( - NDArray, - _ArrayLikeComplex_co, - _ArrayLikeFloat_co, - _ComplexLike_co, - _FloatLike_co, -) +import numpy as np +from numpy._typing import NDArray, _ArrayLikeComplex_co, _ArrayLikeFloat_co, _ComplexLike_co, _FloatLike_co __all__ = ["arccos", "arcsin", "arctanh", "log", "log2", "log10", "logn", "power", "sqrt"] @overload def sqrt(x: _FloatLike_co) -> Any: ... @overload -def sqrt(x: _ComplexLike_co) -> complexfloating[Any, Any]: ... +def sqrt(x: _ComplexLike_co) -> np.complexfloating: ... @overload def sqrt(x: _ArrayLikeFloat_co) -> NDArray[Any]: ... @overload -def sqrt(x: _ArrayLikeComplex_co) -> NDArray[complexfloating[Any, Any]]: ... +def sqrt(x: _ArrayLikeComplex_co) -> NDArray[np.complexfloating]: ... @overload def log(x: _FloatLike_co) -> Any: ... @overload -def log(x: _ComplexLike_co) -> complexfloating[Any, Any]: ... +def log(x: _ComplexLike_co) -> np.complexfloating: ... @overload def log(x: _ArrayLikeFloat_co) -> NDArray[Any]: ... @overload -def log(x: _ArrayLikeComplex_co) -> NDArray[complexfloating[Any, Any]]: ... +def log(x: _ArrayLikeComplex_co) -> NDArray[np.complexfloating]: ... @overload def log10(x: _FloatLike_co) -> Any: ... @overload -def log10(x: _ComplexLike_co) -> complexfloating[Any, Any]: ... +def log10(x: _ComplexLike_co) -> np.complexfloating: ... @overload def log10(x: _ArrayLikeFloat_co) -> NDArray[Any]: ... @overload -def log10(x: _ArrayLikeComplex_co) -> NDArray[complexfloating[Any, Any]]: ... +def log10(x: _ArrayLikeComplex_co) -> NDArray[np.complexfloating]: ... @overload def log2(x: _FloatLike_co) -> Any: ... @overload -def log2(x: _ComplexLike_co) -> complexfloating[Any, Any]: ... +def log2(x: _ComplexLike_co) -> np.complexfloating: ... @overload def log2(x: _ArrayLikeFloat_co) -> NDArray[Any]: ... @overload -def log2(x: _ArrayLikeComplex_co) -> NDArray[complexfloating[Any, Any]]: ... +def log2(x: _ArrayLikeComplex_co) -> NDArray[np.complexfloating]: ... @overload def logn(n: _FloatLike_co, x: _FloatLike_co) -> Any: ... @overload -def logn(n: _ComplexLike_co, x: _ComplexLike_co) -> complexfloating[Any, Any]: ... +def logn(n: _ComplexLike_co, x: _ComplexLike_co) -> np.complexfloating: ... @overload def logn(n: _ArrayLikeFloat_co, x: _ArrayLikeFloat_co) -> NDArray[Any]: ... @overload -def logn(n: _ArrayLikeComplex_co, x: _ArrayLikeComplex_co) -> NDArray[complexfloating[Any, Any]]: ... +def logn(n: _ArrayLikeComplex_co, x: _ArrayLikeComplex_co) -> NDArray[np.complexfloating]: ... @overload def power(x: _FloatLike_co, p: _FloatLike_co) -> Any: ... @overload -def power(x: _ComplexLike_co, p: _ComplexLike_co) -> complexfloating[Any, Any]: ... +def power(x: _ComplexLike_co, p: _ComplexLike_co) -> np.complexfloating: ... @overload def power(x: _ArrayLikeFloat_co, p: _ArrayLikeFloat_co) -> NDArray[Any]: ... @overload -def power(x: _ArrayLikeComplex_co, p: _ArrayLikeComplex_co) -> NDArray[complexfloating[Any, Any]]: ... +def power(x: _ArrayLikeComplex_co, p: _ArrayLikeComplex_co) -> NDArray[np.complexfloating]: ... @overload def arccos(x: _FloatLike_co) -> Any: ... @overload -def arccos(x: _ComplexLike_co) -> complexfloating[Any, Any]: ... +def arccos(x: _ComplexLike_co) -> np.complexfloating: ... @overload def arccos(x: _ArrayLikeFloat_co) -> NDArray[Any]: ... @overload -def arccos(x: _ArrayLikeComplex_co) -> NDArray[complexfloating[Any, Any]]: ... +def arccos(x: _ArrayLikeComplex_co) -> NDArray[np.complexfloating]: ... @overload def arcsin(x: _FloatLike_co) -> Any: ... @overload -def arcsin(x: _ComplexLike_co) -> complexfloating[Any, Any]: ... +def arcsin(x: _ComplexLike_co) -> np.complexfloating: ... @overload def arcsin(x: _ArrayLikeFloat_co) -> NDArray[Any]: ... @overload -def arcsin(x: _ArrayLikeComplex_co) -> NDArray[complexfloating[Any, Any]]: ... +def arcsin(x: _ArrayLikeComplex_co) -> NDArray[np.complexfloating]: ... @overload def arctanh(x: _FloatLike_co) -> Any: ... @overload -def arctanh(x: _ComplexLike_co) -> complexfloating[Any, Any]: ... +def arctanh(x: _ComplexLike_co) -> np.complexfloating: ... @overload def arctanh(x: _ArrayLikeFloat_co) -> NDArray[Any]: ... @overload -def arctanh(x: _ArrayLikeComplex_co) -> NDArray[complexfloating[Any, Any]]: ... +def arctanh(x: _ArrayLikeComplex_co) -> NDArray[np.complexfloating]: ... diff --git a/src/numpy-stubs/lib/_shape_base_impl.pyi b/src/numpy-stubs/lib/_shape_base_impl.pyi index 133264b9..458e37aa 100644 --- a/src/numpy-stubs/lib/_shape_base_impl.pyi +++ b/src/numpy-stubs/lib/_shape_base_impl.pyi @@ -1,26 +1,7 @@ from collections.abc import Callable, Sequence -from typing import ( - Any, - Concatenate, - ParamSpec, - Protocol, - SupportsIndex, - TypeVar, - overload, - type_check_only, -) +from typing import Any, Concatenate, ParamSpec, Protocol, SupportsIndex, TypeVar, overload, type_check_only import numpy as np -from numpy import ( - complexfloating, - floating, - generic, - integer, - object_, - signedinteger, - ufunc, - unsignedinteger, -) from numpy._core.shape_base import vstack as row_stack from numpy._typing import ( ArrayLike, @@ -54,7 +35,7 @@ __all__ = [ ] _P = ParamSpec("_P") -_SCT = TypeVar("_SCT", bound=generic) +_SCT = TypeVar("_SCT", bound=np.generic) # Signature of `__array_wrap__` @type_check_only @@ -62,7 +43,7 @@ class _ArrayWrap(Protocol): def __call__( self, array: NDArray[Any], - context: tuple[ufunc, tuple[Any, ...], int] | None = ..., + context: tuple[np.ufunc, tuple[Any, ...], int] | None = ..., return_scalar: bool = ..., /, ) -> Any: ... @@ -72,17 +53,8 @@ class _SupportsArrayWrap(Protocol): @property def __array_wrap__(self) -> _ArrayWrap: ... -def take_along_axis( - arr: _SCT | NDArray[_SCT], - indices: NDArray[integer[Any]], - axis: int | None, -) -> NDArray[_SCT]: ... -def put_along_axis( - arr: NDArray[_SCT], - indices: NDArray[integer[Any]], - values: ArrayLike, - axis: int | None, -) -> None: ... +def take_along_axis(arr: _SCT | NDArray[_SCT], indices: NDArray[np.integer], axis: int | None) -> NDArray[_SCT]: ... +def put_along_axis(arr: NDArray[_SCT], indices: NDArray[np.integer], values: ArrayLike, axis: int | None) -> None: ... @overload def apply_along_axis( func1d: Callable[Concatenate[NDArray[Any], _P], _ArrayLike[_SCT]], @@ -105,15 +77,9 @@ def apply_over_axes( axes: int | Sequence[int], ) -> NDArray[_SCT]: ... @overload -def expand_dims( - a: _ArrayLike[_SCT], - axis: _ShapeLike, -) -> NDArray[_SCT]: ... +def expand_dims(a: _ArrayLike[_SCT], axis: _ShapeLike) -> NDArray[_SCT]: ... @overload -def expand_dims( - a: ArrayLike, - axis: _ShapeLike, -) -> NDArray[Any]: ... +def expand_dims(a: ArrayLike, axis: _ShapeLike) -> NDArray[Any]: ... @overload def column_stack(tup: Sequence[_ArrayLike[_SCT]]) -> NDArray[_SCT]: ... @overload @@ -123,59 +89,25 @@ def dstack(tup: Sequence[_ArrayLike[_SCT]]) -> NDArray[_SCT]: ... @overload def dstack(tup: Sequence[ArrayLike]) -> NDArray[Any]: ... @overload -def array_split( - ary: _ArrayLike[_SCT], - indices_or_sections: _ShapeLike, - axis: SupportsIndex = ..., -) -> list[NDArray[_SCT]]: ... -@overload -def array_split( - ary: ArrayLike, - indices_or_sections: _ShapeLike, - axis: SupportsIndex = ..., -) -> list[NDArray[Any]]: ... -@overload -def split( - ary: _ArrayLike[_SCT], - indices_or_sections: _ShapeLike, - axis: SupportsIndex = ..., -) -> list[NDArray[_SCT]]: ... -@overload -def split( - ary: ArrayLike, - indices_or_sections: _ShapeLike, - axis: SupportsIndex = ..., -) -> list[NDArray[Any]]: ... -@overload -def hsplit( - ary: _ArrayLike[_SCT], - indices_or_sections: _ShapeLike, -) -> list[NDArray[_SCT]]: ... -@overload -def hsplit( - ary: ArrayLike, - indices_or_sections: _ShapeLike, -) -> list[NDArray[Any]]: ... -@overload -def vsplit( - ary: _ArrayLike[_SCT], - indices_or_sections: _ShapeLike, -) -> list[NDArray[_SCT]]: ... -@overload -def vsplit( - ary: ArrayLike, - indices_or_sections: _ShapeLike, -) -> list[NDArray[Any]]: ... -@overload -def dsplit( - ary: _ArrayLike[_SCT], - indices_or_sections: _ShapeLike, -) -> list[NDArray[_SCT]]: ... -@overload -def dsplit( - ary: ArrayLike, - indices_or_sections: _ShapeLike, -) -> list[NDArray[Any]]: ... +def array_split(ary: _ArrayLike[_SCT], indices_or_sections: _ShapeLike, axis: SupportsIndex = ...) -> list[NDArray[_SCT]]: ... +@overload +def array_split(ary: ArrayLike, indices_or_sections: _ShapeLike, axis: SupportsIndex = ...) -> list[NDArray[Any]]: ... +@overload +def split(ary: _ArrayLike[_SCT], indices_or_sections: _ShapeLike, axis: SupportsIndex = ...) -> list[NDArray[_SCT]]: ... +@overload +def split(ary: ArrayLike, indices_or_sections: _ShapeLike, axis: SupportsIndex = ...) -> list[NDArray[Any]]: ... +@overload +def hsplit(ary: _ArrayLike[_SCT], indices_or_sections: _ShapeLike) -> list[NDArray[_SCT]]: ... +@overload +def hsplit(ary: ArrayLike, indices_or_sections: _ShapeLike) -> list[NDArray[Any]]: ... +@overload +def vsplit(ary: _ArrayLike[_SCT], indices_or_sections: _ShapeLike) -> list[NDArray[_SCT]]: ... +@overload +def vsplit(ary: ArrayLike, indices_or_sections: _ShapeLike) -> list[NDArray[Any]]: ... +@overload +def dsplit(ary: _ArrayLike[_SCT], indices_or_sections: _ShapeLike) -> list[NDArray[_SCT]]: ... +@overload +def dsplit(ary: ArrayLike, indices_or_sections: _ShapeLike) -> list[NDArray[Any]]: ... @overload def get_array_wrap(*args: _SupportsArrayWrap) -> _ArrayWrap: ... @overload @@ -183,24 +115,18 @@ def get_array_wrap(*args: object) -> _ArrayWrap | None: ... @overload def kron(a: _ArrayLikeBool_co, b: _ArrayLikeBool_co) -> NDArray[np.bool]: ... # type: ignore[misc] @overload -def kron(a: _ArrayLikeUInt_co, b: _ArrayLikeUInt_co) -> NDArray[unsignedinteger[Any]]: ... # type: ignore[misc] +def kron(a: _ArrayLikeUInt_co, b: _ArrayLikeUInt_co) -> NDArray[np.unsignedinteger]: ... # type: ignore[misc] @overload -def kron(a: _ArrayLikeInt_co, b: _ArrayLikeInt_co) -> NDArray[signedinteger[Any]]: ... # type: ignore[misc] +def kron(a: _ArrayLikeInt_co, b: _ArrayLikeInt_co) -> NDArray[np.signedinteger]: ... # type: ignore[misc] @overload -def kron(a: _ArrayLikeFloat_co, b: _ArrayLikeFloat_co) -> NDArray[floating[Any]]: ... # type: ignore[misc] +def kron(a: _ArrayLikeFloat_co, b: _ArrayLikeFloat_co) -> NDArray[np.floating]: ... # type: ignore[misc] @overload -def kron(a: _ArrayLikeComplex_co, b: _ArrayLikeComplex_co) -> NDArray[complexfloating[Any, Any]]: ... +def kron(a: _ArrayLikeComplex_co, b: _ArrayLikeComplex_co) -> NDArray[np.complexfloating]: ... @overload -def kron(a: _ArrayLikeObject_co, b: Any) -> NDArray[object_]: ... +def kron(a: _ArrayLikeObject_co, b: Any) -> NDArray[np.object_]: ... @overload -def kron(a: Any, b: _ArrayLikeObject_co) -> NDArray[object_]: ... +def kron(a: Any, b: _ArrayLikeObject_co) -> NDArray[np.object_]: ... @overload -def tile( - A: _ArrayLike[_SCT], - reps: int | Sequence[int], -) -> NDArray[_SCT]: ... +def tile(A: _ArrayLike[_SCT], reps: int | Sequence[int]) -> NDArray[_SCT]: ... @overload -def tile( - A: ArrayLike, - reps: int | Sequence[int], -) -> NDArray[Any]: ... +def tile(A: ArrayLike, reps: int | Sequence[int]) -> NDArray[Any]: ... diff --git a/src/numpy-stubs/lib/_stride_tricks_impl.pyi b/src/numpy-stubs/lib/_stride_tricks_impl.pyi index 23922295..df948cc6 100644 --- a/src/numpy-stubs/lib/_stride_tricks_impl.pyi +++ b/src/numpy-stubs/lib/_stride_tricks_impl.pyi @@ -1,21 +1,17 @@ from collections.abc import Iterable from typing import Any, SupportsIndex, TypeVar, overload -from numpy import generic +import numpy as np from numpy._typing import ArrayLike, NDArray, _ArrayLike, _Shape, _ShapeLike __all__ = ["broadcast_arrays", "broadcast_shapes", "broadcast_to"] -_SCT = TypeVar("_SCT", bound=generic) +_SCT = TypeVar("_SCT", bound=np.generic) class DummyArray: __array_interface__: dict[str, Any] base: NDArray[Any] | None - def __init__( - self, - interface: dict[str, Any], - base: NDArray[Any] | None = ..., - ) -> None: ... + def __init__(self, interface: dict[str, Any], base: NDArray[Any] | None = ...) -> None: ... @overload def as_strided( @@ -52,19 +48,8 @@ def sliding_window_view( writeable: bool = ..., ) -> NDArray[Any]: ... @overload -def broadcast_to( - array: _ArrayLike[_SCT], - shape: int | Iterable[int], - subok: bool = ..., -) -> NDArray[_SCT]: ... +def broadcast_to(array: _ArrayLike[_SCT], shape: int | Iterable[int], subok: bool = ...) -> NDArray[_SCT]: ... @overload -def broadcast_to( - array: ArrayLike, - shape: int | Iterable[int], - subok: bool = ..., -) -> NDArray[Any]: ... +def broadcast_to(array: ArrayLike, shape: int | Iterable[int], subok: bool = ...) -> NDArray[Any]: ... def broadcast_shapes(*args: _ShapeLike) -> _Shape: ... -def broadcast_arrays( - *args: ArrayLike, - subok: bool = ..., -) -> tuple[NDArray[Any], ...]: ... +def broadcast_arrays(*args: ArrayLike, subok: bool = ...) -> tuple[NDArray[Any], ...]: ... diff --git a/src/numpy-stubs/lib/_twodim_base_impl.pyi b/src/numpy-stubs/lib/_twodim_base_impl.pyi index c00b002a..8f9a71e4 100644 --- a/src/numpy-stubs/lib/_twodim_base_impl.pyi +++ b/src/numpy-stubs/lib/_twodim_base_impl.pyi @@ -1,28 +1,7 @@ from collections.abc import Callable, Sequence -from typing import ( - Any, - Literal as L, - TypeAlias, - TypeVar, - overload, -) +from typing import Any, Literal as L, TypeAlias, TypeVar, overload import numpy as np -from numpy import ( - _OrderCF, - complex128, - complexfloating, - datetime64, - float64, - floating, - generic, - int_, - intp, - number, - object_, - signedinteger, - timedelta64, -) from numpy._typing import ( ArrayLike, DTypeLike, @@ -56,12 +35,12 @@ __all__ = [ ] _T = TypeVar("_T") -_SCT = TypeVar("_SCT", bound=generic) +_SCT = TypeVar("_SCT", bound=np.generic) # The returned arrays dtype must be compatible with `np.equal` _MaskFunc: TypeAlias = Callable[ - [NDArray[int_], _T], - NDArray[number[Any] | np.bool | timedelta64 | datetime64 | object_], + [NDArray[np.int_], _T], + NDArray[np.number | np.bool | np.timedelta64 | np.datetime64 | np.object_], ] @overload @@ -78,18 +57,18 @@ def eye( M: int | None = ..., k: int = ..., dtype: None = ..., - order: _OrderCF = ..., + order: np._OrderCF = ..., *, device: L["cpu"] | None = ..., like: _SupportsArrayFunc | None = ..., -) -> NDArray[float64]: ... +) -> NDArray[np.float64]: ... @overload def eye( N: int, M: int | None = ..., k: int = ..., dtype: _DTypeLike[_SCT] = ..., - order: _OrderCF = ..., + order: np._OrderCF = ..., *, device: L["cpu"] | None = ..., like: _SupportsArrayFunc | None = ..., @@ -100,7 +79,7 @@ def eye( M: int | None = ..., k: int = ..., dtype: DTypeLike = ..., - order: _OrderCF = ..., + order: np._OrderCF = ..., *, device: L["cpu"] | None = ..., like: _SupportsArrayFunc | None = ..., @@ -115,15 +94,30 @@ def diagflat(v: _ArrayLike[_SCT], k: int = ...) -> NDArray[_SCT]: ... def diagflat(v: ArrayLike, k: int = ...) -> NDArray[Any]: ... @overload def tri( - N: int, M: int | None = ..., k: int = ..., dtype: None = ..., *, like: _SupportsArrayFunc | None = ... -) -> NDArray[float64]: ... + N: int, + M: int | None = ..., + k: int = ..., + dtype: None = ..., + *, + like: _SupportsArrayFunc | None = ..., +) -> NDArray[np.float64]: ... @overload def tri( - N: int, M: int | None = ..., k: int = ..., dtype: _DTypeLike[_SCT] = ..., *, like: _SupportsArrayFunc | None = ... + N: int, + M: int | None = ..., + k: int = ..., + dtype: _DTypeLike[_SCT] = ..., + *, + like: _SupportsArrayFunc | None = ..., ) -> NDArray[_SCT]: ... @overload def tri( - N: int, M: int | None = ..., k: int = ..., dtype: DTypeLike = ..., *, like: _SupportsArrayFunc | None = ... + N: int, + M: int | None = ..., + k: int = ..., + dtype: DTypeLike = ..., + *, + like: _SupportsArrayFunc | None = ..., ) -> NDArray[Any]: ... @overload def tril(v: _ArrayLike[_SCT], k: int = ...) -> NDArray[_SCT]: ... @@ -134,33 +128,17 @@ def triu(v: _ArrayLike[_SCT], k: int = ...) -> NDArray[_SCT]: ... @overload def triu(v: ArrayLike, k: int = ...) -> NDArray[Any]: ... @overload -def vander( # type: ignore[misc] - x: _ArrayLikeInt_co, - N: int | None = ..., - increasing: bool = ..., -) -> NDArray[signedinteger[Any]]: ... -@overload -def vander( # type: ignore[misc] - x: _ArrayLikeFloat_co, - N: int | None = ..., - increasing: bool = ..., -) -> NDArray[floating[Any]]: ... -@overload -def vander( - x: _ArrayLikeComplex_co, - N: int | None = ..., - increasing: bool = ..., -) -> NDArray[complexfloating[Any, Any]]: ... -@overload -def vander( - x: _ArrayLikeObject_co, - N: int | None = ..., - increasing: bool = ..., -) -> NDArray[object_]: ... +def vander(x: _ArrayLikeInt_co, N: int | None = ..., increasing: bool = ...) -> NDArray[np.signedinteger]: ... +@overload +def vander(x: _ArrayLikeFloat_co, N: int | None = ..., increasing: bool = ...) -> NDArray[np.floating]: ... +@overload +def vander(x: _ArrayLikeComplex_co, N: int | None = ..., increasing: bool = ...) -> NDArray[np.complexfloating]: ... +@overload +def vander(x: _ArrayLikeObject_co, N: int | None = ..., increasing: bool = ...) -> NDArray[np.object_]: ... _Int_co: TypeAlias = np.integer[Any] | np.bool _Float_co: TypeAlias = np.floating[Any] | _Int_co -_Number_co: TypeAlias = np.number[Any] | np.bool +_Number_co: TypeAlias = np.np.number | np.bool _ArrayLike1D: TypeAlias = _SupportsArray[np.dtype[_SCT]] | Sequence[_SCT] _ArrayLike2D: TypeAlias = _SupportsArray[np.dtype[_SCT]] | Sequence[_ArrayLike1D[_SCT]] @@ -170,9 +148,9 @@ _ArrayLike1DFloat_co: TypeAlias = _SupportsArray[np.dtype[_Float_co]] | Sequence _ArrayLike2DFloat_co: TypeAlias = _SupportsArray[np.dtype[_Float_co]] | Sequence[_ArrayLike1DFloat_co] _ArrayLike1DNumber_co: TypeAlias = _SupportsArray[np.dtype[_Number_co]] | Sequence[int | float | complex | _Number_co] -_SCT_complex = TypeVar("_SCT_complex", bound=np.complexfloating[Any, Any]) -_SCT_inexact = TypeVar("_SCT_inexact", bound=np.inexact[Any]) -_SCT_number_co = TypeVar("_SCT_number_co", bound=_Number_co) +_SCT_complex = TypeVar("_SCT_complex", bound=np.complexfloating) +_SCT_inexact = TypeVar("_SCT_inexact", bound=np.inexact) +_SCT_numeric = TypeVar("_SCT_numeric", bound=_Number_co) @overload def histogram2d( @@ -183,7 +161,7 @@ def histogram2d( density: bool | None = ..., weights: _ArrayLike1DFloat_co | None = ..., ) -> tuple[ - NDArray[float64], + NDArray[np.float64], NDArray[_SCT_complex], NDArray[_SCT_complex], ]: ... @@ -196,7 +174,7 @@ def histogram2d( density: bool | None = ..., weights: _ArrayLike1DFloat_co | None = ..., ) -> tuple[ - NDArray[float64], + NDArray[np.float64], NDArray[_SCT_complex], NDArray[_SCT_complex], ]: ... @@ -209,7 +187,7 @@ def histogram2d( density: bool | None = ..., weights: _ArrayLike1DFloat_co | None = ..., ) -> tuple[ - NDArray[float64], + NDArray[np.float64], NDArray[_SCT_inexact], NDArray[_SCT_inexact], ]: ... @@ -222,7 +200,7 @@ def histogram2d( density: bool | None = ..., weights: _ArrayLike1DFloat_co | None = ..., ) -> tuple[ - NDArray[float64], + NDArray[np.float64], NDArray[_SCT_inexact], NDArray[_SCT_inexact], ]: ... @@ -235,9 +213,9 @@ def histogram2d( density: bool | None = ..., weights: _ArrayLike1DFloat_co | None = ..., ) -> tuple[ - NDArray[float64], - NDArray[float64], - NDArray[float64], + NDArray[np.float64], + NDArray[np.float64], + NDArray[np.float64], ]: ... @overload def histogram2d( @@ -248,61 +226,61 @@ def histogram2d( density: bool | None = ..., weights: _ArrayLike1DFloat_co | None = ..., ) -> tuple[ - NDArray[float64], - NDArray[complex128 | float64], - NDArray[complex128 | float64], + NDArray[np.float64], + NDArray[np.complex128 | np.float64], + NDArray[np.complex128 | np.float64], ]: ... @overload def histogram2d( x: _ArrayLike1DNumber_co, y: _ArrayLike1DNumber_co, - bins: _ArrayLike1D[_SCT_number_co] | Sequence[_ArrayLike1D[_SCT_number_co]], + bins: _ArrayLike1D[_SCT_numeric] | Sequence[_ArrayLike1D[_SCT_numeric]], range: _ArrayLike2DFloat_co | None = ..., density: bool | None = ..., weights: _ArrayLike1DFloat_co | None = ..., ) -> tuple[ - NDArray[float64], - NDArray[_SCT_number_co], - NDArray[_SCT_number_co], + NDArray[np.float64], + NDArray[_SCT_numeric], + NDArray[_SCT_numeric], ]: ... @overload def histogram2d( x: _ArrayLike1D[_SCT_inexact], y: _ArrayLike1D[_SCT_inexact], - bins: Sequence[_ArrayLike1D[_SCT_number_co] | int], + bins: Sequence[_ArrayLike1D[_SCT_numeric] | int], range: _ArrayLike2DFloat_co | None = ..., density: bool | None = ..., weights: _ArrayLike1DFloat_co | None = ..., ) -> tuple[ - NDArray[float64], - NDArray[_SCT_number_co | _SCT_inexact], - NDArray[_SCT_number_co | _SCT_inexact], + NDArray[np.float64], + NDArray[_SCT_numeric | _SCT_inexact], + NDArray[_SCT_numeric | _SCT_inexact], ]: ... @overload def histogram2d( x: _ArrayLike1DInt_co | Sequence[float | int], y: _ArrayLike1DInt_co | Sequence[float | int], - bins: Sequence[_ArrayLike1D[_SCT_number_co] | int], + bins: Sequence[_ArrayLike1D[_SCT_numeric] | int], range: _ArrayLike2DFloat_co | None = ..., density: bool | None = ..., weights: _ArrayLike1DFloat_co | None = ..., ) -> tuple[ - NDArray[float64], - NDArray[_SCT_number_co | float64], - NDArray[_SCT_number_co | float64], + NDArray[np.float64], + NDArray[_SCT_numeric | np.float64], + NDArray[_SCT_numeric | np.float64], ]: ... @overload def histogram2d( x: Sequence[complex | float | int], y: Sequence[complex | float | int], - bins: Sequence[_ArrayLike1D[_SCT_number_co] | int], + bins: Sequence[_ArrayLike1D[_SCT_numeric] | int], range: _ArrayLike2DFloat_co | None = ..., density: bool | None = ..., weights: _ArrayLike1DFloat_co | None = ..., ) -> tuple[ - NDArray[float64], - NDArray[_SCT_number_co | complex128 | float64], - NDArray[_SCT_number_co | complex128 | float64], + NDArray[np.float64], + NDArray[_SCT_numeric | np.complex128 | np.float64], + NDArray[_SCT_numeric | np.complex128 | np.float64], ]: ... @overload def histogram2d( @@ -313,7 +291,7 @@ def histogram2d( density: bool | None = ..., weights: _ArrayLike1DFloat_co | None = ..., ) -> tuple[ - NDArray[float64], + NDArray[np.float64], NDArray[np.bool], NDArray[np.bool], ]: ... @@ -326,7 +304,7 @@ def histogram2d( density: bool | None = ..., weights: _ArrayLike1DFloat_co | None = ..., ) -> tuple[ - NDArray[float64], + NDArray[np.float64], NDArray[np.int_ | np.bool], NDArray[np.int_ | np.bool], ]: ... @@ -339,7 +317,7 @@ def histogram2d( density: bool | None = ..., weights: _ArrayLike1DFloat_co | None = ..., ) -> tuple[ - NDArray[float64], + NDArray[np.float64], NDArray[np.float64 | np.int_ | np.bool], NDArray[np.float64 | np.int_ | np.bool], ]: ... @@ -352,7 +330,7 @@ def histogram2d( density: bool | None = ..., weights: _ArrayLike1DFloat_co | None = ..., ) -> tuple[ - NDArray[float64], + NDArray[np.float64], NDArray[np.complex128 | np.float64 | np.int_ | np.bool], NDArray[np.complex128 | np.float64 | np.int_ | np.bool], ]: ... @@ -365,28 +343,28 @@ def mask_indices( n: int, mask_func: _MaskFunc[int], k: int = ..., -) -> tuple[NDArray[intp], NDArray[intp]]: ... +) -> tuple[NDArray[np.intp], NDArray[np.intp]]: ... @overload def mask_indices( n: int, mask_func: _MaskFunc[_T], k: _T, -) -> tuple[NDArray[intp], NDArray[intp]]: ... +) -> tuple[NDArray[np.intp], NDArray[np.intp]]: ... def tril_indices( n: int, k: int = ..., m: int | None = ..., -) -> tuple[NDArray[int_], NDArray[int_]]: ... +) -> tuple[NDArray[np.int_], NDArray[np.int_]]: ... def tril_indices_from( arr: NDArray[Any], k: int = ..., -) -> tuple[NDArray[int_], NDArray[int_]]: ... +) -> tuple[NDArray[np.int_], NDArray[np.int_]]: ... def triu_indices( n: int, k: int = ..., m: int | None = ..., -) -> tuple[NDArray[int_], NDArray[int_]]: ... +) -> tuple[NDArray[np.int_], NDArray[np.int_]]: ... def triu_indices_from( arr: NDArray[Any], k: int = ..., -) -> tuple[NDArray[int_], NDArray[int_]]: ... +) -> tuple[NDArray[np.int_], NDArray[np.int_]]: ... diff --git a/src/numpy-stubs/lib/_type_check_impl.pyi b/src/numpy-stubs/lib/_type_check_impl.pyi index b59a44fb..8f0a58c2 100644 --- a/src/numpy-stubs/lib/_type_check_impl.pyi +++ b/src/numpy-stubs/lib/_type_check_impl.pyi @@ -2,23 +2,7 @@ from collections.abc import Container, Iterable from typing import Any, Literal as L, TypeVar, overload import numpy as np -from numpy import ( - _HasRealAndImag, - complexfloating, - dtype, - floating, - generic, - integer, -) -from numpy._typing import ( - ArrayLike, - NBitBase, - NDArray, - _64Bit, - _ArrayLike, - _ScalarLike_co, - _SupportsDType, -) +from numpy._typing import ArrayLike, NBitBase, NDArray, _64Bit, _ArrayLike, _ScalarLike_co, _SupportsDType __all__ = [ "common_type", @@ -35,8 +19,7 @@ __all__ = [ ] _T = TypeVar("_T") -_T_co = TypeVar("_T_co", covariant=True) -_SCT = TypeVar("_SCT", bound=generic) +_SCT = TypeVar("_SCT", bound=np.generic) _NBit1 = TypeVar("_NBit1", bound=NBitBase) _NBit2 = TypeVar("_NBit2", bound=NBitBase) @@ -46,11 +29,11 @@ def mintypecode( default: str = ..., ) -> str: ... @overload -def real(val: _HasRealAndImag[_T, Any]) -> _T: ... +def real(val: np._HasRealAndImag[_T, Any]) -> _T: ... @overload def real(val: ArrayLike) -> NDArray[Any]: ... @overload -def imag(val: _HasRealAndImag[Any, _T]) -> _T: ... +def imag(val: np._HasRealAndImag[Any, _T]) -> _T: ... @overload def imag(val: ArrayLike) -> NDArray[Any]: ... @overload @@ -61,8 +44,8 @@ def iscomplex(x: ArrayLike) -> NDArray[np.bool]: ... def isreal(x: _ScalarLike_co) -> np.bool: ... # type: ignore[misc] @overload def isreal(x: ArrayLike) -> NDArray[np.bool]: ... -def iscomplexobj(x: _SupportsDType[dtype[Any]] | ArrayLike) -> bool: ... -def isrealobj(x: _SupportsDType[dtype[Any]] | ArrayLike) -> bool: ... +def iscomplexobj(x: _SupportsDType[np.dtype[Any]] | ArrayLike) -> bool: ... +def isrealobj(x: _SupportsDType[np.dtype[Any]] | ArrayLike) -> bool: ... @overload def nan_to_num( # type: ignore[misc] x: _SCT, @@ -100,20 +83,11 @@ def nan_to_num( # expected to verify the output dtype (so we can return an unsafe union here) @overload -def real_if_close( # type: ignore[misc] - a: _ArrayLike[complexfloating[_NBit1, _NBit1]], - tol: float = ..., -) -> NDArray[floating[_NBit1]] | NDArray[complexfloating[_NBit1, _NBit1]]: ... +def real_if_close(a: _ArrayLike[np.complexfloating[_NBit1]], tol: float = ...) -> NDArray[np.inexact[_NBit1]]: ... @overload -def real_if_close( - a: _ArrayLike[_SCT], - tol: float = ..., -) -> NDArray[_SCT]: ... +def real_if_close(a: _ArrayLike[_SCT], tol: float = ...) -> NDArray[_SCT]: ... @overload -def real_if_close( - a: ArrayLike, - tol: float = ..., -) -> NDArray[Any]: ... +def real_if_close(a: ArrayLike, tol: float = ...) -> NDArray[Any]: ... @overload def typename(char: L["S1"]) -> L["character"]: ... @overload @@ -159,22 +133,14 @@ def typename(char: L["V"]) -> L["void"]: ... @overload def typename(char: L["O"]) -> L["object"]: ... @overload -def common_type( # type: ignore[misc] - *arrays: _SupportsDType[dtype[integer[Any]]], -) -> type[floating[_64Bit]]: ... +def common_type(*arrays: _SupportsDType[np.dtype[np.integer]]) -> type[np.float64]: ... @overload -def common_type( # type: ignore[misc] - *arrays: _SupportsDType[dtype[floating[_NBit1]]], -) -> type[floating[_NBit1]]: ... +def common_type(*arrays: _SupportsDType[np.dtype[np.floating[_NBit1]]]) -> type[np.floating[_NBit1]]: ... @overload -def common_type( # type: ignore[misc] - *arrays: _SupportsDType[dtype[integer[Any] | floating[_NBit1]]], -) -> type[floating[_NBit1 | _64Bit]]: ... +def common_type(*arrays: _SupportsDType[np.dtype[np.integer | np.floating[_NBit1]]]) -> type[np.floating[_NBit1 | _64Bit]]: ... @overload -def common_type( # type: ignore[misc] - *arrays: _SupportsDType[dtype[floating[_NBit1] | complexfloating[_NBit2, _NBit2]]], -) -> type[complexfloating[_NBit1 | _NBit2, _NBit1 | _NBit2]]: ... +def common_type(*arrays: _SupportsDType[np.dtype[np.inexact[_NBit1]]]) -> type[np.complexfloating[_NBit1]]: ... @overload def common_type( - *arrays: _SupportsDType[dtype[integer[Any] | floating[_NBit1] | complexfloating[_NBit2, _NBit2]]], -) -> type[complexfloating[_64Bit | _NBit1 | _NBit2, _64Bit | _NBit1 | _NBit2]]: ... + *arrays: _SupportsDType[np.dtype[np.integer | np.floating[_NBit1] | np.complexfloating[_NBit2]]], +) -> type[np.complexfloating[_64Bit | _NBit1 | _NBit2]]: ... diff --git a/src/numpy-stubs/lib/_ufunclike_impl.pyi b/src/numpy-stubs/lib/_ufunclike_impl.pyi index 119f4a96..16900096 100644 --- a/src/numpy-stubs/lib/_ufunclike_impl.pyi +++ b/src/numpy-stubs/lib/_ufunclike_impl.pyi @@ -1,65 +1,29 @@ from typing import Any, TypeVar, overload import numpy as np -from numpy import floating, object_ -from numpy._typing import ( - NDArray, - _ArrayLikeFloat_co, - _ArrayLikeObject_co, - _FloatLike_co, -) +from numpy._typing import NDArray, _ArrayLikeFloat_co, _ArrayLikeObject_co, _FloatLike_co __all__ = ["fix", "isneginf", "isposinf"] _ArrayType = TypeVar("_ArrayType", bound=NDArray[Any]) @overload -def fix( # type: ignore[misc] - x: _FloatLike_co, - out: None = ..., -) -> floating[Any]: ... +def fix(x: _FloatLike_co, out: None = ...) -> np.floating: ... @overload -def fix( - x: _ArrayLikeFloat_co, - out: None = ..., -) -> NDArray[floating[Any]]: ... +def fix(x: _ArrayLikeFloat_co, out: None = ...) -> NDArray[np.floating]: ... @overload -def fix( - x: _ArrayLikeObject_co, - out: None = ..., -) -> NDArray[object_]: ... +def fix(x: _ArrayLikeObject_co, out: None = ...) -> NDArray[np.object_]: ... @overload -def fix( - x: _ArrayLikeFloat_co | _ArrayLikeObject_co, - out: _ArrayType, -) -> _ArrayType: ... +def fix(x: _ArrayLikeFloat_co | _ArrayLikeObject_co, out: _ArrayType) -> _ArrayType: ... @overload -def isposinf( # type: ignore[misc] - x: _FloatLike_co, - out: None = ..., -) -> np.bool: ... +def isposinf(x: _FloatLike_co, out: None = ...) -> np.bool: ... @overload -def isposinf( - x: _ArrayLikeFloat_co, - out: None = ..., -) -> NDArray[np.bool]: ... +def isposinf(x: _ArrayLikeFloat_co, out: None = ...) -> NDArray[np.bool]: ... @overload -def isposinf( - x: _ArrayLikeFloat_co, - out: _ArrayType, -) -> _ArrayType: ... +def isposinf(x: _ArrayLikeFloat_co, out: _ArrayType) -> _ArrayType: ... @overload -def isneginf( # type: ignore[misc] - x: _FloatLike_co, - out: None = ..., -) -> np.bool: ... +def isneginf(x: _FloatLike_co, out: None = ...) -> np.bool: ... @overload -def isneginf( - x: _ArrayLikeFloat_co, - out: None = ..., -) -> NDArray[np.bool]: ... +def isneginf(x: _ArrayLikeFloat_co, out: None = ...) -> NDArray[np.bool]: ... @overload -def isneginf( - x: _ArrayLikeFloat_co, - out: _ArrayType, -) -> _ArrayType: ... +def isneginf(x: _ArrayLikeFloat_co, out: _ArrayType) -> _ArrayType: ... diff --git a/src/numpy-stubs/lib/mixins.pyi b/src/numpy-stubs/lib/mixins.pyi index cd45bdcb..d0ef0310 100644 --- a/src/numpy-stubs/lib/mixins.pyi +++ b/src/numpy-stubs/lib/mixins.pyi @@ -1,7 +1,8 @@ -from abc import ABCMeta, abstractmethod -from typing import Any, Literal as L, Self +import abc +from typing import Any, Literal as L +from typing_extensions import Self -from numpy import ufunc +import numpy as np __all__ = ["NDArrayOperatorsMixin"] @@ -12,62 +13,62 @@ __all__ = ["NDArrayOperatorsMixin"] # completely dependent on how `__array_ufunc__` is implemented. # As such, only little type safety can be provided here. -class NDArrayOperatorsMixin(metaclass=ABCMeta): - @abstractmethod +class NDArrayOperatorsMixin(metaclass=abc.ABCMeta): + @abc.abstractmethod def __array_ufunc__( self, - ufunc: ufunc, + ufunc: np.ufunc, method: L["__call__", "reduce", "reduceat", "accumulate", "outer", "at"], *inputs: Any, **kwargs: Any, ) -> Any: ... - def __lt__(self, other: Any) -> Any: ... - def __le__(self, other: Any) -> Any: ... - def __eq__(self, other: object) -> Any: ... - def __ne__(self, other: object) -> Any: ... - def __gt__(self, other: Any) -> Any: ... - def __ge__(self, other: Any) -> Any: ... - def __add__(self, other: Any) -> Any: ... - def __radd__(self, other: Any) -> Any: ... - def __iadd__(self, other: Any) -> Self: ... - def __sub__(self, other: Any) -> Any: ... - def __rsub__(self, other: Any) -> Any: ... - def __isub__(self, other: Any) -> Self: ... - def __mul__(self, other: Any) -> Any: ... - def __rmul__(self, other: Any) -> Any: ... - def __imul__(self, other: Any) -> Self: ... - def __matmul__(self, other: Any) -> Any: ... - def __rmatmul__(self, other: Any) -> Any: ... - def __imatmul__(self, other: Any) -> Self: ... - def __truediv__(self, other: Any) -> Any: ... - def __rtruediv__(self, other: Any) -> Any: ... - def __itruediv__(self, other: Any) -> Self: ... - def __floordiv__(self, other: Any) -> Any: ... - def __rfloordiv__(self, other: Any) -> Any: ... - def __ifloordiv__(self, other: Any) -> Self: ... - def __mod__(self, other: Any) -> Any: ... - def __rmod__(self, other: Any) -> Any: ... - def __imod__(self, other: Any) -> Self: ... - def __divmod__(self, other: Any) -> Any: ... - def __rdivmod__(self, other: Any) -> Any: ... - def __pow__(self, other: Any) -> Any: ... - def __rpow__(self, other: Any) -> Any: ... - def __ipow__(self, other: Any) -> Self: ... - def __lshift__(self, other: Any) -> Any: ... - def __rlshift__(self, other: Any) -> Any: ... - def __ilshift__(self, other: Any) -> Self: ... - def __rshift__(self, other: Any) -> Any: ... - def __rrshift__(self, other: Any) -> Any: ... - def __irshift__(self, other: Any) -> Self: ... - def __and__(self, other: Any) -> Any: ... - def __rand__(self, other: Any) -> Any: ... - def __iand__(self, other: Any) -> Self: ... - def __xor__(self, other: Any) -> Any: ... - def __rxor__(self, other: Any) -> Any: ... - def __ixor__(self, other: Any) -> Self: ... - def __or__(self, other: Any) -> Any: ... - def __ror__(self, other: Any) -> Any: ... - def __ior__(self, other: Any) -> Self: ... + def __lt__(self, other: Any, /) -> Any: ... + def __le__(self, other: Any, /) -> Any: ... + def __eq__(self, other: object, /) -> Any: ... + def __ne__(self, other: object, /) -> Any: ... + def __gt__(self, other: Any, /) -> Any: ... + def __ge__(self, other: Any, /) -> Any: ... + def __add__(self, other: Any, /) -> Any: ... + def __radd__(self, other: Any, /) -> Any: ... + def __iadd__(self, other: Any, /) -> Self: ... + def __sub__(self, other: Any, /) -> Any: ... + def __rsub__(self, other: Any, /) -> Any: ... + def __isub__(self, other: Any, /) -> Self: ... + def __mul__(self, other: Any, /) -> Any: ... + def __rmul__(self, other: Any, /) -> Any: ... + def __imul__(self, other: Any, /) -> Self: ... + def __matmul__(self, other: Any, /) -> Any: ... + def __rmatmul__(self, other: Any, /) -> Any: ... + def __imatmul__(self, other: Any, /) -> Self: ... + def __truediv__(self, other: Any, /) -> Any: ... + def __rtruediv__(self, other: Any, /) -> Any: ... + def __itruediv__(self, other: Any, /) -> Self: ... + def __floordiv__(self, other: Any, /) -> Any: ... + def __rfloordiv__(self, other: Any, /) -> Any: ... + def __ifloordiv__(self, other: Any, /) -> Self: ... + def __mod__(self, other: Any, /) -> Any: ... + def __rmod__(self, other: Any, /) -> Any: ... + def __imod__(self, other: Any, /) -> Self: ... + def __divmod__(self, other: Any, /) -> Any: ... + def __rdivmod__(self, other: Any, /) -> Any: ... + def __pow__(self, other: Any, /) -> Any: ... + def __rpow__(self, other: Any, /) -> Any: ... + def __ipow__(self, other: Any, /) -> Self: ... + def __lshift__(self, other: Any, /) -> Any: ... + def __rlshift__(self, other: Any, /) -> Any: ... + def __ilshift__(self, other: Any, /) -> Self: ... + def __rshift__(self, other: Any, /) -> Any: ... + def __rrshift__(self, other: Any, /) -> Any: ... + def __irshift__(self, other: Any, /) -> Self: ... + def __and__(self, other: Any, /) -> Any: ... + def __rand__(self, other: Any, /) -> Any: ... + def __iand__(self, other: Any, /) -> Self: ... + def __xor__(self, other: Any, /) -> Any: ... + def __rxor__(self, other: Any, /) -> Any: ... + def __ixor__(self, other: Any, /) -> Self: ... + def __or__(self, other: Any, /) -> Any: ... + def __ror__(self, other: Any, /) -> Any: ... + def __ior__(self, other: Any, /) -> Self: ... def __neg__(self) -> Any: ... def __pos__(self) -> Any: ... def __abs__(self) -> Any: ... diff --git a/src/numpy-stubs/linalg/_linalg.pyi b/src/numpy-stubs/linalg/_linalg.pyi index 3a41cfee..4e64f044 100644 --- a/src/numpy-stubs/linalg/_linalg.pyi +++ b/src/numpy-stubs/linalg/_linalg.pyi @@ -11,21 +11,7 @@ from typing import ( ) import numpy as np -from numpy import ( - complex128, - complexfloating, - float64, - floating, - # other - generic, - int32, - object_, - signedinteger, - timedelta64, - unsignedinteger, - # re-exports - vecdot, -) +from numpy import vecdot # noqa: ICN003 from numpy._core.fromnumeric import matrix_transpose from numpy._core.numeric import tensordot from numpy._typing import ( @@ -79,8 +65,6 @@ __all__ = [ ] _T = TypeVar("_T") -_ArrayType = TypeVar("_ArrayType", bound=NDArray[Any]) -_SCT2 = TypeVar("_SCT2", bound=generic, covariant=True) _2Tuple: TypeAlias = tuple[_T, _T] _ModeKind: TypeAlias = L["reduced", "complete", "r", "raw"] @@ -109,100 +93,70 @@ class SVDResult(NamedTuple): Vh: NDArray[Any] @overload -def tensorsolve( - a: _ArrayLikeInt_co, - b: _ArrayLikeInt_co, - axes: Iterable[int] | None = ..., -) -> NDArray[float64]: ... +def tensorsolve(a: _ArrayLikeInt_co, b: _ArrayLikeInt_co, axes: Iterable[int] | None = ...) -> NDArray[np.float64]: ... @overload -def tensorsolve( - a: _ArrayLikeFloat_co, - b: _ArrayLikeFloat_co, - axes: Iterable[int] | None = ..., -) -> NDArray[floating[Any]]: ... +def tensorsolve(a: _ArrayLikeFloat_co, b: _ArrayLikeFloat_co, axes: Iterable[int] | None = ...) -> NDArray[np.floating]: ... @overload def tensorsolve( a: _ArrayLikeComplex_co, b: _ArrayLikeComplex_co, axes: Iterable[int] | None = ..., -) -> NDArray[complexfloating[Any, Any]]: ... +) -> NDArray[np.complexfloating]: ... + +# @overload -def solve( - a: _ArrayLikeInt_co, - b: _ArrayLikeInt_co, -) -> NDArray[float64]: ... +def solve(a: _ArrayLikeInt_co, b: _ArrayLikeInt_co) -> NDArray[np.float64]: ... @overload -def solve( - a: _ArrayLikeFloat_co, - b: _ArrayLikeFloat_co, -) -> NDArray[floating[Any]]: ... +def solve(a: _ArrayLikeFloat_co, b: _ArrayLikeFloat_co) -> NDArray[np.floating]: ... @overload -def solve( - a: _ArrayLikeComplex_co, - b: _ArrayLikeComplex_co, -) -> NDArray[complexfloating[Any, Any]]: ... +def solve(a: _ArrayLikeComplex_co, b: _ArrayLikeComplex_co) -> NDArray[np.complexfloating]: ... + +# @overload -def tensorinv( - a: _ArrayLikeInt_co, - ind: int = ..., -) -> NDArray[float64]: ... +def tensorinv(a: _ArrayLikeInt_co, ind: int = ...) -> NDArray[np.float64]: ... @overload -def tensorinv( - a: _ArrayLikeFloat_co, - ind: int = ..., -) -> NDArray[floating[Any]]: ... +def tensorinv(a: _ArrayLikeFloat_co, ind: int = ...) -> NDArray[np.floating]: ... @overload -def tensorinv( - a: _ArrayLikeComplex_co, - ind: int = ..., -) -> NDArray[complexfloating[Any, Any]]: ... +def tensorinv(a: _ArrayLikeComplex_co, ind: int = ...) -> NDArray[np.complexfloating]: ... + +# @overload -def inv(a: _ArrayLikeInt_co) -> NDArray[float64]: ... +def inv(a: _ArrayLikeInt_co) -> NDArray[np.float64]: ... @overload -def inv(a: _ArrayLikeFloat_co) -> NDArray[floating[Any]]: ... +def inv(a: _ArrayLikeFloat_co) -> NDArray[np.floating]: ... @overload -def inv(a: _ArrayLikeComplex_co) -> NDArray[complexfloating[Any, Any]]: ... +def inv(a: _ArrayLikeComplex_co) -> NDArray[np.complexfloating]: ... # TODO: The supported input and output dtypes are dependent on the value of `n`. -# For example: `n < 0` always casts integer types to float64 -def matrix_power( - a: _ArrayLikeComplex_co | _ArrayLikeObject_co, - n: SupportsIndex, -) -> NDArray[Any]: ... +# For example: `n < 0` always casts integer types to np.float64 +def matrix_power(a: _ArrayLikeComplex_co | _ArrayLikeObject_co, n: SupportsIndex) -> NDArray[Any]: ... @overload -def cholesky(a: _ArrayLikeInt_co) -> NDArray[float64]: ... +def cholesky(a: _ArrayLikeInt_co) -> NDArray[np.float64]: ... @overload -def cholesky(a: _ArrayLikeFloat_co) -> NDArray[floating[Any]]: ... +def cholesky(a: _ArrayLikeFloat_co) -> NDArray[np.floating]: ... @overload -def cholesky(a: _ArrayLikeComplex_co) -> NDArray[complexfloating[Any, Any]]: ... +def cholesky(a: _ArrayLikeComplex_co) -> NDArray[np.complexfloating]: ... @overload def outer(x1: _ArrayLikeUnknown, x2: _ArrayLikeUnknown) -> NDArray[Any]: ... @overload def outer(x1: _ArrayLikeBool_co, x2: _ArrayLikeBool_co) -> NDArray[np.bool]: ... @overload -def outer(x1: _ArrayLikeUInt_co, x2: _ArrayLikeUInt_co) -> NDArray[unsignedinteger[Any]]: ... +def outer(x1: _ArrayLikeUInt_co, x2: _ArrayLikeUInt_co) -> NDArray[np.unsignedinteger]: ... @overload -def outer(x1: _ArrayLikeInt_co, x2: _ArrayLikeInt_co) -> NDArray[signedinteger[Any]]: ... +def outer(x1: _ArrayLikeInt_co, x2: _ArrayLikeInt_co) -> NDArray[np.signedinteger]: ... @overload -def outer(x1: _ArrayLikeFloat_co, x2: _ArrayLikeFloat_co) -> NDArray[floating[Any]]: ... +def outer(x1: _ArrayLikeFloat_co, x2: _ArrayLikeFloat_co) -> NDArray[np.floating]: ... @overload -def outer( - x1: _ArrayLikeComplex_co, - x2: _ArrayLikeComplex_co, -) -> NDArray[complexfloating[Any, Any]]: ... +def outer(x1: _ArrayLikeComplex_co, x2: _ArrayLikeComplex_co) -> NDArray[np.complexfloating]: ... @overload -def outer( - x1: _ArrayLikeTD64_co, - x2: _ArrayLikeTD64_co, - out: None = ..., -) -> NDArray[timedelta64]: ... +def outer(x1: _ArrayLikeTD64_co, x2: _ArrayLikeTD64_co, out: None = ...) -> NDArray[np.timedelta64]: ... @overload -def outer(x1: _ArrayLikeObject_co, x2: _ArrayLikeObject_co) -> NDArray[object_]: ... +def outer(x1: _ArrayLikeObject_co, x2: _ArrayLikeObject_co) -> NDArray[np.object_]: ... @overload def outer( x1: _ArrayLikeComplex_co | _ArrayLikeTD64_co | _ArrayLikeObject_co, x2: _ArrayLikeComplex_co | _ArrayLikeTD64_co | _ArrayLikeObject_co, -) -> _ArrayType: ... +) -> NDArray[Any]: ... @overload def qr(a: _ArrayLikeInt_co, mode: _ModeKind = ...) -> QRResult: ... @overload @@ -210,15 +164,15 @@ def qr(a: _ArrayLikeFloat_co, mode: _ModeKind = ...) -> QRResult: ... @overload def qr(a: _ArrayLikeComplex_co, mode: _ModeKind = ...) -> QRResult: ... @overload -def eigvals(a: _ArrayLikeInt_co) -> NDArray[float64] | NDArray[complex128]: ... +def eigvals(a: _ArrayLikeInt_co) -> NDArray[np.float64] | NDArray[np.complex128]: ... @overload -def eigvals(a: _ArrayLikeFloat_co) -> NDArray[floating[Any]] | NDArray[complexfloating[Any, Any]]: ... +def eigvals(a: _ArrayLikeFloat_co) -> NDArray[np.floating] | NDArray[np.complexfloating]: ... @overload -def eigvals(a: _ArrayLikeComplex_co) -> NDArray[complexfloating[Any, Any]]: ... +def eigvals(a: _ArrayLikeComplex_co) -> NDArray[np.complexfloating]: ... @overload -def eigvalsh(a: _ArrayLikeInt_co, UPLO: L["L", "U", "l", "u"] = ...) -> NDArray[float64]: ... +def eigvalsh(a: _ArrayLikeInt_co, UPLO: L["L", "U", "l", "u"] = ...) -> NDArray[np.float64]: ... @overload -def eigvalsh(a: _ArrayLikeComplex_co, UPLO: L["L", "U", "l", "u"] = ...) -> NDArray[floating[Any]]: ... +def eigvalsh(a: _ArrayLikeComplex_co, UPLO: L["L", "U", "l", "u"] = ...) -> NDArray[np.floating]: ... @overload def eig(a: _ArrayLikeInt_co) -> EigResult: ... @overload @@ -226,56 +180,32 @@ def eig(a: _ArrayLikeFloat_co) -> EigResult: ... @overload def eig(a: _ArrayLikeComplex_co) -> EigResult: ... @overload -def eigh( - a: _ArrayLikeInt_co, - UPLO: L["L", "U", "l", "u"] = ..., -) -> EighResult: ... +def eigh(a: _ArrayLikeInt_co, UPLO: L["L", "U", "l", "u"] = ...) -> EighResult: ... @overload -def eigh( - a: _ArrayLikeFloat_co, - UPLO: L["L", "U", "l", "u"] = ..., -) -> EighResult: ... +def eigh(a: _ArrayLikeFloat_co, UPLO: L["L", "U", "l", "u"] = ...) -> EighResult: ... @overload -def eigh( - a: _ArrayLikeComplex_co, - UPLO: L["L", "U", "l", "u"] = ..., -) -> EighResult: ... +def eigh(a: _ArrayLikeComplex_co, UPLO: L["L", "U", "l", "u"] = ...) -> EighResult: ... @overload -def svd( - a: _ArrayLikeInt_co, - full_matrices: bool = ..., - compute_uv: L[True] = ..., - hermitian: bool = ..., -) -> SVDResult: ... +def svd(a: _ArrayLikeInt_co, full_matrices: bool = ..., compute_uv: L[True] = ..., hermitian: bool = ...) -> SVDResult: ... @overload -def svd( - a: _ArrayLikeFloat_co, - full_matrices: bool = ..., - compute_uv: L[True] = ..., - hermitian: bool = ..., -) -> SVDResult: ... +def svd(a: _ArrayLikeFloat_co, full_matrices: bool = ..., compute_uv: L[True] = ..., hermitian: bool = ...) -> SVDResult: ... @overload -def svd( - a: _ArrayLikeComplex_co, - full_matrices: bool = ..., - compute_uv: L[True] = ..., - hermitian: bool = ..., -) -> SVDResult: ... +def svd(a: _ArrayLikeComplex_co, full_matrices: bool = ..., compute_uv: L[True] = ..., hermitian: bool = ...) -> SVDResult: ... @overload def svd( a: _ArrayLikeInt_co, full_matrices: bool = ..., compute_uv: L[False] = ..., hermitian: bool = ..., -) -> NDArray[float64]: ... +) -> NDArray[np.float64]: ... @overload def svd( a: _ArrayLikeComplex_co, full_matrices: bool = ..., compute_uv: L[False] = ..., hermitian: bool = ..., -) -> NDArray[floating[Any]]: ... -def svdvals(x: _ArrayLikeInt_co | _ArrayLikeFloat_co | _ArrayLikeComplex_co) -> NDArray[floating[Any]]: ... +) -> NDArray[np.floating]: ... +def svdvals(x: _ArrayLikeInt_co | _ArrayLikeFloat_co | _ArrayLikeComplex_co) -> NDArray[np.floating]: ... # TODO: Returns a scalar for 2D arrays and # a `(x.ndim - 2)`` dimensionl array otherwise @@ -294,19 +224,19 @@ def pinv( a: _ArrayLikeInt_co, rcond: _ArrayLikeFloat_co = ..., hermitian: bool = ..., -) -> NDArray[float64]: ... +) -> NDArray[np.float64]: ... @overload def pinv( a: _ArrayLikeFloat_co, rcond: _ArrayLikeFloat_co = ..., hermitian: bool = ..., -) -> NDArray[floating[Any]]: ... +) -> NDArray[np.floating]: ... @overload def pinv( a: _ArrayLikeComplex_co, rcond: _ArrayLikeFloat_co = ..., hermitian: bool = ..., -) -> NDArray[complexfloating[Any, Any]]: ... +) -> NDArray[np.complexfloating]: ... # TODO: Returns a 2-tuple of scalars for 2D arrays and # a 2-tuple of `(a.ndim - 2)`` dimensionl arrays otherwise @@ -317,30 +247,36 @@ def slogdet(a: _ArrayLikeComplex_co) -> SlogdetResult: ... def det(a: _ArrayLikeComplex_co) -> Any: ... @overload def lstsq( - a: _ArrayLikeInt_co, b: _ArrayLikeInt_co, rcond: float | None = ... + a: _ArrayLikeInt_co, + b: _ArrayLikeInt_co, + rcond: float | None = ..., ) -> tuple[ - NDArray[float64], - NDArray[float64], - int32, - NDArray[float64], + NDArray[np.float64], + NDArray[np.float64], + np.int32, + NDArray[np.float64], ]: ... @overload def lstsq( - a: _ArrayLikeFloat_co, b: _ArrayLikeFloat_co, rcond: float | None = ... + a: _ArrayLikeFloat_co, + b: _ArrayLikeFloat_co, + rcond: float | None = ..., ) -> tuple[ - NDArray[floating[Any]], - NDArray[floating[Any]], - int32, - NDArray[floating[Any]], + NDArray[np.floating], + NDArray[np.floating], + np.int32, + NDArray[np.floating], ]: ... @overload def lstsq( - a: _ArrayLikeComplex_co, b: _ArrayLikeComplex_co, rcond: float | None = ... + a: _ArrayLikeComplex_co, + b: _ArrayLikeComplex_co, + rcond: float | None = ..., ) -> tuple[ - NDArray[complexfloating[Any, Any]], - NDArray[floating[Any]], - int32, - NDArray[floating[Any]], + NDArray[np.complexfloating], + NDArray[np.floating], + np.int32, + NDArray[np.floating], ]: ... @overload def norm( @@ -348,7 +284,7 @@ def norm( ord: float | L["fro", "nuc"] | None = ..., axis: None = ..., keepdims: bool = ..., -) -> floating[Any]: ... +) -> np.floating: ... @overload def norm( x: ArrayLike, @@ -361,7 +297,7 @@ def matrix_norm( x: ArrayLike, ord: float | L["fro", "nuc"] | None = ..., keepdims: bool = ..., -) -> floating[Any]: ... +) -> np.floating: ... @overload def matrix_norm( x: ArrayLike, @@ -374,7 +310,7 @@ def vector_norm( axis: None = ..., ord: float | None = ..., keepdims: bool = ..., -) -> floating[Any]: ... +) -> np.floating: ... @overload def vector_norm( x: ArrayLike, @@ -403,42 +339,42 @@ def cross( a: _ArrayLikeUInt_co, b: _ArrayLikeUInt_co, axis: int = ..., -) -> NDArray[unsignedinteger[Any]]: ... +) -> NDArray[np.unsignedinteger]: ... @overload def cross( a: _ArrayLikeInt_co, b: _ArrayLikeInt_co, axis: int = ..., -) -> NDArray[signedinteger[Any]]: ... +) -> NDArray[np.signedinteger]: ... @overload def cross( a: _ArrayLikeFloat_co, b: _ArrayLikeFloat_co, axis: int = ..., -) -> NDArray[floating[Any]]: ... +) -> NDArray[np.floating]: ... @overload def cross( a: _ArrayLikeComplex_co, b: _ArrayLikeComplex_co, axis: int = ..., -) -> NDArray[complexfloating[Any, Any]]: ... +) -> NDArray[np.complexfloating]: ... @overload def matmul( x1: _ArrayLikeInt_co, x2: _ArrayLikeInt_co, -) -> NDArray[signedinteger[Any]]: ... +) -> NDArray[np.signedinteger]: ... @overload def matmul( x1: _ArrayLikeUInt_co, x2: _ArrayLikeUInt_co, -) -> NDArray[unsignedinteger[Any]]: ... +) -> NDArray[np.unsignedinteger]: ... @overload def matmul( x1: _ArrayLikeFloat_co, x2: _ArrayLikeFloat_co, -) -> NDArray[floating[Any]]: ... +) -> NDArray[np.floating]: ... @overload def matmul( x1: _ArrayLikeComplex_co, x2: _ArrayLikeComplex_co, -) -> NDArray[complexfloating[Any, Any]]: ... +) -> NDArray[np.complexfloating]: ... diff --git a/src/numpy-stubs/ma/core.pyi b/src/numpy-stubs/ma/core.pyi index b6e29919..40e8a1ae 100644 --- a/src/numpy-stubs/ma/core.pyi +++ b/src/numpy-stubs/ma/core.pyi @@ -3,19 +3,8 @@ from collections.abc import Callable from typing import Any, TypeVar from typing_extensions import Self -from numpy import ( - amax, - amin, - angle, - bool_, - clip, - dtype, - expand_dims, - float64, - indices, - ndarray, - squeeze, -) +import numpy as np +from numpy import amax, amin, angle, bool_, clip, expand_dims, indices, squeeze # noqa: ICN003 __all__ = [ "MAError", @@ -199,7 +188,7 @@ __all__ = [ ] _ShapeType_co = TypeVar("_ShapeType_co", bound=tuple[int, ...], covariant=True) -_DType_co = TypeVar("_DType_co", bound=dtype[Any], covariant=True) +_DType_co = TypeVar("_DType_co", bound=np.dtype[Any], covariant=True) MaskType = bool nomask: bool @@ -353,7 +342,7 @@ class MaskedIterator: def __setitem__(self, index: Incomplete, value: Incomplete) -> None: ... def __next__(self) -> Incomplete: ... -class MaskedArray(ndarray[_ShapeType_co, _DType_co]): +class MaskedArray(np.ndarray[_ShapeType_co, _DType_co]): __array_priority__: Any def __new__( cls, @@ -610,7 +599,7 @@ isarray = isMaskedArray isMA = isMaskedArray # 0D float64 array -class MaskedConstant(MaskedArray[Any, dtype[float64]]): +class MaskedConstant(MaskedArray[Any, np.dtype[np.float64]]): def __new__(cls) -> Incomplete: ... __class__: Any def __array_finalize__(self, obj: Incomplete) -> Incomplete: ... diff --git a/src/numpy-stubs/ma/mrecords.pyi b/src/numpy-stubs/ma/mrecords.pyi index 61caad66..282cefa2 100644 --- a/src/numpy-stubs/ma/mrecords.pyi +++ b/src/numpy-stubs/ma/mrecords.pyi @@ -1,21 +1,14 @@ from _typeshed import Incomplete from typing import Any, TypeVar -from numpy import dtype +import numpy as np from . import MaskedArray -__all__ = [ - "MaskedRecords", - "addfield", - "fromarrays", - "fromrecords", - "fromtextfile", - "mrecarray", -] +__all__ = ["MaskedRecords", "addfield", "fromarrays", "fromrecords", "fromtextfile", "mrecarray"] _ShapeType_co = TypeVar("_ShapeType_co", covariant=True, bound=tuple[int, ...]) -_DType_co = TypeVar("_DType_co", bound=dtype[Any], covariant=True) +_DType_co = TypeVar("_DType_co", bound=np.dtype[Any], covariant=True) class MaskedRecords(MaskedArray[_ShapeType_co, _DType_co]): def __new__( diff --git a/src/numpy-stubs/matrixlib/__init__.pyi b/src/numpy-stubs/matrixlib/__init__.pyi index 3ebee6ea..75055f50 100644 --- a/src/numpy-stubs/matrixlib/__init__.pyi +++ b/src/numpy-stubs/matrixlib/__init__.pyi @@ -1,5 +1,3 @@ -from numpy import matrix - -from .defmatrix import asmatrix, bmat +from .defmatrix import asmatrix, bmat, matrix __all__ = ["asmatrix", "bmat", "matrix"] diff --git a/src/numpy-stubs/matrixlib/defmatrix.pyi b/src/numpy-stubs/matrixlib/defmatrix.pyi index b09c526c..dceafc2d 100644 --- a/src/numpy-stubs/matrixlib/defmatrix.pyi +++ b/src/numpy-stubs/matrixlib/defmatrix.pyi @@ -1,7 +1,8 @@ from collections.abc import Mapping, Sequence from typing import Any -from numpy import matrix +import numpy as np +from numpy import matrix # noqa: ICN003 from numpy._typing import ArrayLike, DTypeLike, NDArray __all__ = ["asmatrix", "bmat", "matrix"] @@ -10,7 +11,7 @@ def bmat( obj: str | Sequence[ArrayLike] | NDArray[Any], ldict: Mapping[str, Any] | None = ..., gdict: Mapping[str, Any] | None = ..., -) -> matrix[tuple[int, int], Any]: ... +) -> np.matrix[tuple[int, int], Any]: ... def asmatrix(data: ArrayLike, dtype: DTypeLike = ...) -> matrix[tuple[int, int], Any]: ... mat = asmatrix diff --git a/src/numpy-stubs/random/_generator.pyi b/src/numpy-stubs/random/_generator.pyi index 4a910d35..55519814 100644 --- a/src/numpy-stubs/random/_generator.pyi +++ b/src/numpy-stubs/random/_generator.pyi @@ -1,27 +1,13 @@ from collections.abc import Callable -from typing import Any, Literal, TypeAlias, TypeVar, overload +from typing import Any, Literal, TypeAlias, overload import numpy as np -from numpy import ( - dtype, - float32, - float64, - int8, - int16, - int32, - int64, - int_, - uint, - uint8, - uint16, - uint32, - uint64, -) from numpy._typing import ( ArrayLike, NDArray, _ArrayLikeFloat_co, _ArrayLikeInt_co, + _DTypeLike, _DTypeLikeBool, _DoubleCodes, _Float32Codes, @@ -43,13 +29,8 @@ from numpy._typing import ( ) from numpy.random import BitGenerator, RandomState, SeedSequence -_ArrayType = TypeVar("_ArrayType", bound=NDArray[Any]) - -_DTypeLikeFloat32: TypeAlias = dtype[float32] | _SupportsDType[dtype[float32]] | type[float32] | _Float32Codes | _SingleCodes - -_DTypeLikeFloat64: TypeAlias = ( - dtype[float64] | _SupportsDType[dtype[float64]] | type[float] | type[float64] | _Float64Codes | _DoubleCodes -) +_DTypeLikeFloat32: TypeAlias = _DTypeLike[np.float32] | _Float32Codes | _SingleCodes +_DTypeLikeFloat64: TypeAlias = _DTypeLike[np.float64] | type[float] | _Float64Codes | _DoubleCodes class Generator: def __init__(self, bit_generator: BitGenerator) -> None: ... @@ -71,29 +52,29 @@ class Generator: def standard_normal( # type: ignore[misc] self, size: _ShapeLike = ..., - ) -> NDArray[float64]: ... + ) -> NDArray[np.float64]: ... @overload def standard_normal( # type: ignore[misc] self, *, - out: NDArray[float64] = ..., - ) -> NDArray[float64]: ... + out: NDArray[np.float64] = ..., + ) -> NDArray[np.float64]: ... @overload def standard_normal( # type: ignore[misc] self, size: _ShapeLike = ..., dtype: _DTypeLikeFloat32 = ..., - out: NDArray[float32] | None = ..., - ) -> NDArray[float32]: ... + out: NDArray[np.float32] | None = ..., + ) -> NDArray[np.float32]: ... @overload def standard_normal( # type: ignore[misc] self, size: _ShapeLike = ..., dtype: _DTypeLikeFloat64 = ..., - out: NDArray[float64] | None = ..., - ) -> NDArray[float64]: ... + out: NDArray[np.float64] | None = ..., + ) -> NDArray[np.float64]: ... @overload - def permutation(self, x: int, axis: int = ...) -> NDArray[int64]: ... + def permutation(self, x: int, axis: int = ...) -> NDArray[np.int64]: ... @overload def permutation(self, x: ArrayLike, axis: int = ...) -> NDArray[Any]: ... @overload @@ -108,37 +89,37 @@ class Generator: def standard_exponential( self, size: _ShapeLike = ..., - ) -> NDArray[float64]: ... + ) -> NDArray[np.float64]: ... @overload def standard_exponential( self, *, - out: NDArray[float64] = ..., - ) -> NDArray[float64]: ... + out: NDArray[np.float64] = ..., + ) -> NDArray[np.float64]: ... @overload def standard_exponential( self, size: _ShapeLike = ..., *, method: Literal["zig", "inv"] = ..., - out: NDArray[float64] | None = ..., - ) -> NDArray[float64]: ... + out: NDArray[np.float64] | None = ..., + ) -> NDArray[np.float64]: ... @overload def standard_exponential( self, size: _ShapeLike = ..., dtype: _DTypeLikeFloat32 = ..., method: Literal["zig", "inv"] = ..., - out: NDArray[float32] | None = ..., - ) -> NDArray[float32]: ... + out: NDArray[np.float32] | None = ..., + ) -> NDArray[np.float32]: ... @overload def standard_exponential( self, size: _ShapeLike = ..., dtype: _DTypeLikeFloat64 = ..., method: Literal["zig", "inv"] = ..., - out: NDArray[float64] | None = ..., - ) -> NDArray[float64]: ... + out: NDArray[np.float64] | None = ..., + ) -> NDArray[np.float64]: ... @overload def random( # type: ignore[misc] self, @@ -150,29 +131,29 @@ class Generator: def random( self, *, - out: NDArray[float64] = ..., - ) -> NDArray[float64]: ... + out: NDArray[np.float64] = ..., + ) -> NDArray[np.float64]: ... @overload def random( self, size: _ShapeLike = ..., *, - out: NDArray[float64] | None = ..., - ) -> NDArray[float64]: ... + out: NDArray[np.float64] | None = ..., + ) -> NDArray[np.float64]: ... @overload def random( self, size: _ShapeLike = ..., dtype: _DTypeLikeFloat32 = ..., - out: NDArray[float32] | None = ..., - ) -> NDArray[float32]: ... + out: NDArray[np.float32] | None = ..., + ) -> NDArray[np.float32]: ... @overload def random( self, size: _ShapeLike = ..., dtype: _DTypeLikeFloat64 = ..., - out: NDArray[float64] | None = ..., - ) -> NDArray[float64]: ... + out: NDArray[np.float64] | None = ..., + ) -> NDArray[np.float64]: ... @overload def beta( self, @@ -181,11 +162,11 @@ class Generator: size: None = ..., ) -> float: ... # type: ignore[misc] @overload - def beta(self, a: _ArrayLikeFloat_co, b: _ArrayLikeFloat_co, size: _ShapeLike | None = ...) -> NDArray[float64]: ... + def beta(self, a: _ArrayLikeFloat_co, b: _ArrayLikeFloat_co, size: _ShapeLike | None = ...) -> NDArray[np.float64]: ... @overload def exponential(self, scale: _FloatLike_co = ..., size: None = ...) -> float: ... # type: ignore[misc] @overload - def exponential(self, scale: _ArrayLikeFloat_co = ..., size: _ShapeLike | None = ...) -> NDArray[float64]: ... + def exponential(self, scale: _ArrayLikeFloat_co = ..., size: _ShapeLike | None = ...) -> NDArray[np.float64]: ... @overload def integers( # type: ignore[misc] self, @@ -228,94 +209,94 @@ class Generator: low: int, high: int | None = ..., size: None = ..., - dtype: dtype[uint8] | type[uint8] | _UInt8Codes | _SupportsDType[dtype[uint8]] = ..., + dtype: np.dtype[np.uint8] | type[np.uint8] | _UInt8Codes | _SupportsDType[np.dtype[np.uint8]] = ..., endpoint: bool = ..., - ) -> uint8: ... + ) -> np.uint8: ... @overload def integers( # type: ignore[misc] self, low: int, high: int | None = ..., size: None = ..., - dtype: dtype[uint16] | type[uint16] | _UInt16Codes | _SupportsDType[dtype[uint16]] = ..., + dtype: np.dtype[np.uint16] | type[np.uint16] | _UInt16Codes | _SupportsDType[np.dtype[np.uint16]] = ..., endpoint: bool = ..., - ) -> uint16: ... + ) -> np.uint16: ... @overload def integers( # type: ignore[misc] self, low: int, high: int | None = ..., size: None = ..., - dtype: dtype[uint32] | type[uint32] | _UInt32Codes | _SupportsDType[dtype[uint32]] = ..., + dtype: np.dtype[np.uint32] | type[np.uint32] | _UInt32Codes | _SupportsDType[np.dtype[np.uint32]] = ..., endpoint: bool = ..., - ) -> uint32: ... + ) -> np.uint32: ... @overload def integers( # type: ignore[misc] self, low: int, high: int | None = ..., size: None = ..., - dtype: dtype[uint] | type[uint] | _UIntCodes | _SupportsDType[dtype[uint]] = ..., + dtype: np.dtype[np.uint64] | type[np.uint64] | _UIntCodes | _SupportsDType[np.dtype[np.uint64]] = ..., endpoint: bool = ..., - ) -> uint: ... + ) -> np.uint64: ... @overload def integers( # type: ignore[misc] self, low: int, high: int | None = ..., size: None = ..., - dtype: dtype[uint64] | type[uint64] | _UInt64Codes | _SupportsDType[dtype[uint64]] = ..., + dtype: np.dtype[np.uint64] | type[np.uint64] | _UInt64Codes | _SupportsDType[np.dtype[np.uint64]] = ..., endpoint: bool = ..., - ) -> uint64: ... + ) -> np.uint64: ... @overload def integers( # type: ignore[misc] self, low: int, high: int | None = ..., size: None = ..., - dtype: dtype[int8] | type[int8] | _Int8Codes | _SupportsDType[dtype[int8]] = ..., + dtype: np.dtype[np.int8] | type[np.int8] | _Int8Codes | _SupportsDType[np.dtype[np.int8]] = ..., endpoint: bool = ..., - ) -> int8: ... + ) -> np.int8: ... @overload def integers( # type: ignore[misc] self, low: int, high: int | None = ..., size: None = ..., - dtype: dtype[int16] | type[int16] | _Int16Codes | _SupportsDType[dtype[int16]] = ..., + dtype: np.dtype[np.int16] | type[np.int16] | _Int16Codes | _SupportsDType[np.dtype[np.int16]] = ..., endpoint: bool = ..., - ) -> int16: ... + ) -> np.int16: ... @overload def integers( # type: ignore[misc] self, low: int, high: int | None = ..., size: None = ..., - dtype: dtype[int32] | type[int32] | _Int32Codes | _SupportsDType[dtype[int32]] = ..., + dtype: np.dtype[np.int32] | type[np.int32] | _Int32Codes | _SupportsDType[np.dtype[np.int32]] = ..., endpoint: bool = ..., - ) -> int32: ... + ) -> np.int32: ... @overload def integers( # type: ignore[misc] self, low: int, high: int | None = ..., size: None = ..., - dtype: type[int | int_] | dtype[int_] | _IntCodes | _SupportsDType[dtype[int_]] = ..., + dtype: type[int | np.int_] | np.dtype[np.int_] | _IntCodes | _SupportsDType[np.dtype[np.int_]] = ..., endpoint: bool = ..., - ) -> int_: ... + ) -> np.int_: ... @overload def integers( # type: ignore[misc] self, low: int, high: int | None = ..., size: None = ..., - dtype: dtype[int64] | type[int64] | _Int64Codes | _SupportsDType[dtype[int64]] = ..., + dtype: np.dtype[np.int64] | type[np.int64] | _Int64Codes | _SupportsDType[np.dtype[np.int64]] = ..., endpoint: bool = ..., - ) -> int64: ... + ) -> np.int64: ... @overload def integers( # type: ignore[misc] self, low: _ArrayLikeInt_co, high: _ArrayLikeInt_co | None = ..., size: _ShapeLike | None = ..., *, endpoint: bool = ... - ) -> NDArray[int64]: ... + ) -> NDArray[np.int64]: ... @overload def integers( # type: ignore[misc] self, @@ -331,92 +312,92 @@ class Generator: low: _ArrayLikeInt_co, high: _ArrayLikeInt_co | None = ..., size: _ShapeLike | None = ..., - dtype: dtype[int8] | type[int8] | _Int8Codes | _SupportsDType[dtype[int8]] = ..., + dtype: np.dtype[np.int8] | type[np.int8] | _Int8Codes | _SupportsDType[np.dtype[np.int8]] = ..., endpoint: bool = ..., - ) -> NDArray[int8]: ... + ) -> NDArray[np.int8]: ... @overload def integers( # type: ignore[misc] self, low: _ArrayLikeInt_co, high: _ArrayLikeInt_co | None = ..., size: _ShapeLike | None = ..., - dtype: dtype[int16] | type[int16] | _Int16Codes | _SupportsDType[dtype[int16]] = ..., + dtype: np.dtype[np.int16] | type[np.int16] | _Int16Codes | _SupportsDType[np.dtype[np.int16]] = ..., endpoint: bool = ..., - ) -> NDArray[int16]: ... + ) -> NDArray[np.int16]: ... @overload def integers( # type: ignore[misc] self, low: _ArrayLikeInt_co, high: _ArrayLikeInt_co | None = ..., size: _ShapeLike | None = ..., - dtype: dtype[int32] | type[int32] | _Int32Codes | _SupportsDType[dtype[int32]] = ..., + dtype: np.dtype[np.int32] | type[np.int32] | _Int32Codes | _SupportsDType[np.dtype[np.int32]] = ..., endpoint: bool = ..., - ) -> NDArray[int32]: ... + ) -> NDArray[np.int32]: ... @overload def integers( # type: ignore[misc] self, low: _ArrayLikeInt_co, high: _ArrayLikeInt_co | None = ..., size: _ShapeLike | None = ..., - dtype: dtype[int64] | type[int64] | _Int64Codes | _SupportsDType[dtype[int64]] | None = ..., + dtype: np.dtype[np.int64] | type[np.int64] | _Int64Codes | _SupportsDType[np.dtype[np.int64]] | None = ..., endpoint: bool = ..., - ) -> NDArray[int64]: ... + ) -> NDArray[np.int64]: ... @overload def integers( # type: ignore[misc] self, low: _ArrayLikeInt_co, high: _ArrayLikeInt_co | None = ..., size: _ShapeLike | None = ..., - dtype: dtype[uint8] | type[uint8] | _UInt8Codes | _SupportsDType[dtype[uint8]] = ..., + dtype: np.dtype[np.uint8] | type[np.uint8] | _UInt8Codes | _SupportsDType[np.dtype[np.uint8]] = ..., endpoint: bool = ..., - ) -> NDArray[uint8]: ... + ) -> NDArray[np.uint8]: ... @overload def integers( # type: ignore[misc] self, low: _ArrayLikeInt_co, high: _ArrayLikeInt_co | None = ..., size: _ShapeLike | None = ..., - dtype: dtype[uint16] | type[uint16] | _UInt16Codes | _SupportsDType[dtype[uint16]] = ..., + dtype: np.dtype[np.uint16] | type[np.uint16] | _UInt16Codes | _SupportsDType[np.dtype[np.uint16]] = ..., endpoint: bool = ..., - ) -> NDArray[uint16]: ... + ) -> NDArray[np.uint16]: ... @overload def integers( # type: ignore[misc] self, low: _ArrayLikeInt_co, high: _ArrayLikeInt_co | None = ..., size: _ShapeLike | None = ..., - dtype: dtype[uint32] | type[uint32] | _UInt32Codes | _SupportsDType[dtype[uint32]] = ..., + dtype: np.dtype[np.uint32] | type[np.uint32] | _UInt32Codes | _SupportsDType[np.dtype[np.uint32]] = ..., endpoint: bool = ..., - ) -> NDArray[uint32]: ... + ) -> NDArray[np.uint32]: ... @overload def integers( # type: ignore[misc] self, low: _ArrayLikeInt_co, high: _ArrayLikeInt_co | None = ..., size: _ShapeLike | None = ..., - dtype: dtype[uint64] | type[uint64] | _UInt64Codes | _SupportsDType[dtype[uint64]] = ..., + dtype: np.dtype[np.uint64] | type[np.uint64] | _UInt64Codes | _SupportsDType[np.dtype[np.uint64]] = ..., endpoint: bool = ..., - ) -> NDArray[uint64]: ... + ) -> NDArray[np.uint64]: ... @overload def integers( # type: ignore[misc] self, low: _ArrayLikeInt_co, high: _ArrayLikeInt_co | None = ..., size: _ShapeLike | None = ..., - dtype: type[int | int_] | dtype[int_] | _IntCodes | _SupportsDType[dtype[int_]] = ..., + dtype: type[int | np.int_] | np.dtype[np.int_] | _IntCodes | _SupportsDType[np.dtype[np.int_]] = ..., endpoint: bool = ..., - ) -> NDArray[int_]: ... + ) -> NDArray[np.int_]: ... @overload def integers( # type: ignore[misc] self, low: _ArrayLikeInt_co, high: _ArrayLikeInt_co | None = ..., size: _ShapeLike | None = ..., - dtype: dtype[uint] | type[uint] | _UIntCodes | _SupportsDType[dtype[uint]] = ..., + dtype: np.dtype[np.uint64] | type[np.uint64] | _UIntCodes | _SupportsDType[np.dtype[np.uint64]] = ..., endpoint: bool = ..., - ) -> NDArray[uint]: ... + ) -> NDArray[np.uint64]: ... # TODO: Use a TypeVar _T here to get away from Any output? - # Should be int->NDArray[int64], ArrayLike[_T] -> _T | NDArray[Any] + # Should be int->NDArray[np.int64], ArrayLike[_T] -> _T | NDArray[Any] @overload def choice( self, @@ -436,7 +417,7 @@ class Generator: p: _ArrayLikeFloat_co | None = ..., axis: int = ..., shuffle: bool = ..., - ) -> NDArray[int64]: ... + ) -> NDArray[np.int64]: ... @overload def choice( self, @@ -470,7 +451,7 @@ class Generator: low: _ArrayLikeFloat_co = ..., high: _ArrayLikeFloat_co = ..., size: _ShapeLike | None = ..., - ) -> NDArray[float64]: ... + ) -> NDArray[np.float64]: ... @overload def normal( self, @@ -484,7 +465,7 @@ class Generator: loc: _ArrayLikeFloat_co = ..., scale: _ArrayLikeFloat_co = ..., size: _ShapeLike | None = ..., - ) -> NDArray[float64]: ... + ) -> NDArray[np.float64]: ... @overload def standard_gamma( # type: ignore[misc] self, @@ -498,30 +479,30 @@ class Generator: self, shape: _ArrayLikeFloat_co, size: _ShapeLike | None = ..., - ) -> NDArray[float64]: ... + ) -> NDArray[np.float64]: ... @overload def standard_gamma( self, shape: _ArrayLikeFloat_co, *, - out: NDArray[float64] = ..., - ) -> NDArray[float64]: ... + out: NDArray[np.float64] = ..., + ) -> NDArray[np.float64]: ... @overload def standard_gamma( self, shape: _ArrayLikeFloat_co, size: _ShapeLike | None = ..., dtype: _DTypeLikeFloat32 = ..., - out: NDArray[float32] | None = ..., - ) -> NDArray[float32]: ... + out: NDArray[np.float32] | None = ..., + ) -> NDArray[np.float32]: ... @overload def standard_gamma( self, shape: _ArrayLikeFloat_co, size: _ShapeLike | None = ..., dtype: _DTypeLikeFloat64 = ..., - out: NDArray[float64] | None = ..., - ) -> NDArray[float64]: ... + out: NDArray[np.float64] | None = ..., + ) -> NDArray[np.float64]: ... @overload def gamma(self, shape: _FloatLike_co, scale: _FloatLike_co = ..., size: None = ...) -> float: ... # type: ignore[misc] @overload @@ -530,11 +511,11 @@ class Generator: shape: _ArrayLikeFloat_co, scale: _ArrayLikeFloat_co = ..., size: _ShapeLike | None = ..., - ) -> NDArray[float64]: ... + ) -> NDArray[np.float64]: ... @overload def f(self, dfnum: _FloatLike_co, dfden: _FloatLike_co, size: None = ...) -> float: ... # type: ignore[misc] @overload - def f(self, dfnum: _ArrayLikeFloat_co, dfden: _ArrayLikeFloat_co, size: _ShapeLike | None = ...) -> NDArray[float64]: ... + def f(self, dfnum: _ArrayLikeFloat_co, dfden: _ArrayLikeFloat_co, size: _ShapeLike | None = ...) -> NDArray[np.float64]: ... @overload def noncentral_f(self, dfnum: _FloatLike_co, dfden: _FloatLike_co, nonc: _FloatLike_co, size: None = ...) -> float: ... # type: ignore[misc] @overload @@ -544,43 +525,51 @@ class Generator: dfden: _ArrayLikeFloat_co, nonc: _ArrayLikeFloat_co, size: _ShapeLike | None = ..., - ) -> NDArray[float64]: ... + ) -> NDArray[np.float64]: ... @overload def chisquare(self, df: _FloatLike_co, size: None = ...) -> float: ... # type: ignore[misc] @overload - def chisquare(self, df: _ArrayLikeFloat_co, size: _ShapeLike | None = ...) -> NDArray[float64]: ... + def chisquare(self, df: _ArrayLikeFloat_co, size: _ShapeLike | None = ...) -> NDArray[np.float64]: ... @overload def noncentral_chisquare(self, df: _FloatLike_co, nonc: _FloatLike_co, size: None = ...) -> float: ... # type: ignore[misc] @overload def noncentral_chisquare( - self, df: _ArrayLikeFloat_co, nonc: _ArrayLikeFloat_co, size: _ShapeLike | None = ... - ) -> NDArray[float64]: ... + self, + df: _ArrayLikeFloat_co, + nonc: _ArrayLikeFloat_co, + size: _ShapeLike | None = ..., + ) -> NDArray[np.float64]: ... @overload def standard_t(self, df: _FloatLike_co, size: None = ...) -> float: ... # type: ignore[misc] @overload - def standard_t(self, df: _ArrayLikeFloat_co, size: None = ...) -> NDArray[float64]: ... + def standard_t(self, df: _ArrayLikeFloat_co, size: None = ...) -> NDArray[np.float64]: ... @overload - def standard_t(self, df: _ArrayLikeFloat_co, size: _ShapeLike = ...) -> NDArray[float64]: ... + def standard_t(self, df: _ArrayLikeFloat_co, size: _ShapeLike = ...) -> NDArray[np.float64]: ... @overload def vonmises(self, mu: _FloatLike_co, kappa: _FloatLike_co, size: None = ...) -> float: ... # type: ignore[misc] @overload - def vonmises(self, mu: _ArrayLikeFloat_co, kappa: _ArrayLikeFloat_co, size: _ShapeLike | None = ...) -> NDArray[float64]: ... + def vonmises( + self, + mu: _ArrayLikeFloat_co, + kappa: _ArrayLikeFloat_co, + size: _ShapeLike | None = ..., + ) -> NDArray[np.float64]: ... @overload def pareto(self, a: _FloatLike_co, size: None = ...) -> float: ... # type: ignore[misc] @overload - def pareto(self, a: _ArrayLikeFloat_co, size: _ShapeLike | None = ...) -> NDArray[float64]: ... + def pareto(self, a: _ArrayLikeFloat_co, size: _ShapeLike | None = ...) -> NDArray[np.float64]: ... @overload def weibull(self, a: _FloatLike_co, size: None = ...) -> float: ... # type: ignore[misc] @overload - def weibull(self, a: _ArrayLikeFloat_co, size: _ShapeLike | None = ...) -> NDArray[float64]: ... + def weibull(self, a: _ArrayLikeFloat_co, size: _ShapeLike | None = ...) -> NDArray[np.float64]: ... @overload def power(self, a: _FloatLike_co, size: None = ...) -> float: ... # type: ignore[misc] @overload - def power(self, a: _ArrayLikeFloat_co, size: _ShapeLike | None = ...) -> NDArray[float64]: ... + def power(self, a: _ArrayLikeFloat_co, size: _ShapeLike | None = ...) -> NDArray[np.float64]: ... @overload def standard_cauchy(self, size: None = ...) -> float: ... # type: ignore[misc] @overload - def standard_cauchy(self, size: _ShapeLike = ...) -> NDArray[float64]: ... + def standard_cauchy(self, size: _ShapeLike = ...) -> NDArray[np.float64]: ... @overload def laplace( self, @@ -594,7 +583,7 @@ class Generator: loc: _ArrayLikeFloat_co = ..., scale: _ArrayLikeFloat_co = ..., size: _ShapeLike | None = ..., - ) -> NDArray[float64]: ... + ) -> NDArray[np.float64]: ... @overload def gumbel( self, @@ -608,7 +597,7 @@ class Generator: loc: _ArrayLikeFloat_co = ..., scale: _ArrayLikeFloat_co = ..., size: _ShapeLike | None = ..., - ) -> NDArray[float64]: ... + ) -> NDArray[np.float64]: ... @overload def logistic( self, @@ -622,7 +611,7 @@ class Generator: loc: _ArrayLikeFloat_co = ..., scale: _ArrayLikeFloat_co = ..., size: _ShapeLike | None = ..., - ) -> NDArray[float64]: ... + ) -> NDArray[np.float64]: ... @overload def lognormal( self, @@ -636,15 +625,15 @@ class Generator: mean: _ArrayLikeFloat_co = ..., sigma: _ArrayLikeFloat_co = ..., size: _ShapeLike | None = ..., - ) -> NDArray[float64]: ... + ) -> NDArray[np.float64]: ... @overload def rayleigh(self, scale: _FloatLike_co = ..., size: None = ...) -> float: ... # type: ignore[misc] @overload - def rayleigh(self, scale: _ArrayLikeFloat_co = ..., size: _ShapeLike | None = ...) -> NDArray[float64]: ... + def rayleigh(self, scale: _ArrayLikeFloat_co = ..., size: _ShapeLike | None = ...) -> NDArray[np.float64]: ... @overload def wald(self, mean: _FloatLike_co, scale: _FloatLike_co, size: None = ...) -> float: ... # type: ignore[misc] @overload - def wald(self, mean: _ArrayLikeFloat_co, scale: _ArrayLikeFloat_co, size: _ShapeLike | None = ...) -> NDArray[float64]: ... + def wald(self, mean: _ArrayLikeFloat_co, scale: _ArrayLikeFloat_co, size: _ShapeLike | None = ...) -> NDArray[np.float64]: ... @overload def triangular( self, @@ -660,29 +649,32 @@ class Generator: mode: _ArrayLikeFloat_co, right: _ArrayLikeFloat_co, size: _ShapeLike | None = ..., - ) -> NDArray[float64]: ... + ) -> NDArray[np.float64]: ... @overload def binomial(self, n: int, p: _FloatLike_co, size: None = ...) -> int: ... # type: ignore[misc] @overload - def binomial(self, n: _ArrayLikeInt_co, p: _ArrayLikeFloat_co, size: _ShapeLike | None = ...) -> NDArray[int64]: ... + def binomial(self, n: _ArrayLikeInt_co, p: _ArrayLikeFloat_co, size: _ShapeLike | None = ...) -> NDArray[np.int64]: ... @overload def negative_binomial(self, n: _FloatLike_co, p: _FloatLike_co, size: None = ...) -> int: ... # type: ignore[misc] @overload def negative_binomial( - self, n: _ArrayLikeFloat_co, p: _ArrayLikeFloat_co, size: _ShapeLike | None = ... - ) -> NDArray[int64]: ... + self, + n: _ArrayLikeFloat_co, + p: _ArrayLikeFloat_co, + size: _ShapeLike | None = ..., + ) -> NDArray[np.int64]: ... @overload def poisson(self, lam: _FloatLike_co = ..., size: None = ...) -> int: ... # type: ignore[misc] @overload - def poisson(self, lam: _ArrayLikeFloat_co = ..., size: _ShapeLike | None = ...) -> NDArray[int64]: ... + def poisson(self, lam: _ArrayLikeFloat_co = ..., size: _ShapeLike | None = ...) -> NDArray[np.int64]: ... @overload def zipf(self, a: _FloatLike_co, size: None = ...) -> int: ... # type: ignore[misc] @overload - def zipf(self, a: _ArrayLikeFloat_co, size: _ShapeLike | None = ...) -> NDArray[int64]: ... + def zipf(self, a: _ArrayLikeFloat_co, size: _ShapeLike | None = ...) -> NDArray[np.int64]: ... @overload def geometric(self, p: _FloatLike_co, size: None = ...) -> int: ... # type: ignore[misc] @overload - def geometric(self, p: _ArrayLikeFloat_co, size: _ShapeLike | None = ...) -> NDArray[int64]: ... + def geometric(self, p: _ArrayLikeFloat_co, size: _ShapeLike | None = ...) -> NDArray[np.int64]: ... @overload def hypergeometric(self, ngood: int, nbad: int, nsample: int, size: None = ...) -> int: ... # type: ignore[misc] @overload @@ -692,11 +684,11 @@ class Generator: nbad: _ArrayLikeInt_co, nsample: _ArrayLikeInt_co, size: _ShapeLike | None = ..., - ) -> NDArray[int64]: ... + ) -> NDArray[np.int64]: ... @overload def logseries(self, p: _FloatLike_co, size: None = ...) -> int: ... # type: ignore[misc] @overload - def logseries(self, p: _ArrayLikeFloat_co, size: _ShapeLike | None = ...) -> NDArray[int64]: ... + def logseries(self, p: _ArrayLikeFloat_co, size: _ShapeLike | None = ...) -> NDArray[np.int64]: ... def multivariate_normal( self, mean: _ArrayLikeFloat_co, @@ -706,16 +698,16 @@ class Generator: tol: float = ..., *, method: Literal["svd", "eigh", "cholesky"] = ..., - ) -> NDArray[float64]: ... - def multinomial(self, n: _ArrayLikeInt_co, pvals: _ArrayLikeFloat_co, size: _ShapeLike | None = ...) -> NDArray[int64]: ... + ) -> NDArray[np.float64]: ... + def multinomial(self, n: _ArrayLikeInt_co, pvals: _ArrayLikeFloat_co, size: _ShapeLike | None = ...) -> NDArray[np.int64]: ... def multivariate_hypergeometric( self, colors: _ArrayLikeInt_co, nsample: int, size: _ShapeLike | None = ..., method: Literal["marginals", "count"] = ..., - ) -> NDArray[int64]: ... - def dirichlet(self, alpha: _ArrayLikeFloat_co, size: _ShapeLike | None = ...) -> NDArray[float64]: ... + ) -> NDArray[np.int64]: ... + def dirichlet(self, alpha: _ArrayLikeFloat_co, size: _ShapeLike | None = ...) -> NDArray[np.float64]: ... def permuted(self, x: ArrayLike, *, axis: int | None = ..., out: NDArray[Any] | None = ...) -> NDArray[Any]: ... def shuffle(self, x: ArrayLike, axis: int = ...) -> None: ... diff --git a/src/numpy-stubs/random/_mt19937.pyi b/src/numpy-stubs/random/_mt19937.pyi index 70b2506d..10277b40 100644 --- a/src/numpy-stubs/random/_mt19937.pyi +++ b/src/numpy-stubs/random/_mt19937.pyi @@ -1,13 +1,13 @@ from typing import TypedDict, type_check_only -from numpy import uint32 +import numpy as np +import numpy.typing as npt from numpy._typing import _ArrayLikeInt_co from numpy.random.bit_generator import BitGenerator, SeedSequence -from numpy.typing import NDArray @type_check_only class _MT19937Internal(TypedDict): - key: NDArray[uint32] + key: npt.NDArray[np.uint32] pos: int @type_check_only @@ -22,4 +22,4 @@ class MT19937(BitGenerator): @property def state(self) -> _MT19937State: ... @state.setter - def state(self, value: _MT19937State) -> None: ... + def state(self, value: _MT19937State, /) -> None: ... diff --git a/src/numpy-stubs/random/_philox.pyi b/src/numpy-stubs/random/_philox.pyi index d8895bba..bdda72fc 100644 --- a/src/numpy-stubs/random/_philox.pyi +++ b/src/numpy-stubs/random/_philox.pyi @@ -1,20 +1,20 @@ from typing import TypedDict, type_check_only -from numpy import uint64 +import numpy as np +import numpy.typing as npt from numpy._typing import _ArrayLikeInt_co from numpy.random.bit_generator import BitGenerator, SeedSequence -from numpy.typing import NDArray @type_check_only class _PhiloxInternal(TypedDict): - counter: NDArray[uint64] - key: NDArray[uint64] + counter: npt.NDArray[np.uint64] + key: npt.NDArray[np.uint64] @type_check_only class _PhiloxState(TypedDict): bit_generator: str state: _PhiloxInternal - buffer: NDArray[uint64] + buffer: npt.NDArray[np.uint64] buffer_pos: int has_uint32: int uinteger: int @@ -27,13 +27,8 @@ class Philox(BitGenerator): key: _ArrayLikeInt_co | None = ..., ) -> None: ... @property - def state( - self, - ) -> _PhiloxState: ... + def state(self) -> _PhiloxState: ... @state.setter - def state( - self, - value: _PhiloxState, - ) -> None: ... + def state(self, value: _PhiloxState, /) -> None: ... def jumped(self, jumps: int = ...) -> Philox: ... def advance(self, delta: int) -> Philox: ... diff --git a/src/numpy-stubs/random/_sfc64.pyi b/src/numpy-stubs/random/_sfc64.pyi index a6f0d844..c7e69ee1 100644 --- a/src/numpy-stubs/random/_sfc64.pyi +++ b/src/numpy-stubs/random/_sfc64.pyi @@ -1,12 +1,12 @@ from typing import TypedDict, type_check_only -from numpy import uint64 +import numpy as np from numpy._typing import NDArray, _ArrayLikeInt_co from numpy.random.bit_generator import BitGenerator, SeedSequence @type_check_only class _SFC64Internal(TypedDict): - state: NDArray[uint64] + state: NDArray[np.uint64] @type_check_only class _SFC64State(TypedDict): @@ -18,11 +18,6 @@ class _SFC64State(TypedDict): class SFC64(BitGenerator): def __init__(self, seed: _ArrayLikeInt_co | SeedSequence | None = ...) -> None: ... @property - def state( - self, - ) -> _SFC64State: ... + def state(self) -> _SFC64State: ... @state.setter - def state( - self, - value: _SFC64State, - ) -> None: ... + def state(self, state: _SFC64State, /) -> None: ... diff --git a/src/numpy-stubs/random/bit_generator.pyi b/src/numpy-stubs/random/bit_generator.pyi index e49b0697..d9e42c20 100644 --- a/src/numpy-stubs/random/bit_generator.pyi +++ b/src/numpy-stubs/random/bit_generator.pyi @@ -12,20 +12,13 @@ from typing import ( type_check_only, ) -from numpy import dtype, uint32, uint64 -from numpy._typing import ( - NDArray, - _ArrayLikeInt_co, - _ShapeLike, - _SupportsDType, - _UInt32Codes, - _UInt64Codes, -) +import numpy as np +from numpy._typing import NDArray, _ArrayLikeInt_co, _DTypeLike, _ShapeLike, _UInt32Codes, _UInt64Codes _T = TypeVar("_T") -_DTypeLikeUint32: TypeAlias = dtype[uint32] | _SupportsDType[dtype[uint32]] | type[uint32] | _UInt32Codes -_DTypeLikeUint64: TypeAlias = dtype[uint64] | _SupportsDType[dtype[uint64]] | type[uint64] | _UInt64Codes +_DTypeLikeUint32: TypeAlias = _DTypeLike[np.uint32] | _UInt32Codes +_DTypeLikeUint64: TypeAlias = _DTypeLike[np.uint64] | _UInt64Codes @type_check_only class _SeedSeqState(TypedDict): @@ -45,14 +38,18 @@ class _Interface(NamedTuple): class ISeedSequence(abc.ABC): @abc.abstractmethod - def generate_state(self, n_words: int, dtype: _DTypeLikeUint32 | _DTypeLikeUint64 = ...) -> NDArray[uint32 | uint64]: ... + def generate_state( + self, n_words: int, dtype: _DTypeLikeUint32 | _DTypeLikeUint64 = ... + ) -> NDArray[np.uint32 | np.uint64]: ... class ISpawnableSeedSequence(ISeedSequence): @abc.abstractmethod def spawn(self: _T, n_children: int) -> list[_T]: ... class SeedlessSeedSequence(ISpawnableSeedSequence): - def generate_state(self, n_words: int, dtype: _DTypeLikeUint32 | _DTypeLikeUint64 = ...) -> NDArray[uint32 | uint64]: ... + def generate_state( + self, n_words: int, dtype: _DTypeLikeUint32 | _DTypeLikeUint64 = ... + ) -> NDArray[np.uint32 | np.uint64]: ... def spawn(self: _T, n_children: int) -> list[_T]: ... class SeedSequence(ISpawnableSeedSequence): @@ -60,7 +57,7 @@ class SeedSequence(ISpawnableSeedSequence): spawn_key: tuple[int, ...] pool_size: int n_children_spawned: int - pool: NDArray[uint32] + pool: NDArray[np.uint32] def __init__( self, entropy: int | Sequence[int] | _ArrayLikeInt_co | None = ..., @@ -70,10 +67,10 @@ class SeedSequence(ISpawnableSeedSequence): n_children_spawned: int = ..., ) -> None: ... @property - def state( - self, - ) -> _SeedSeqState: ... - def generate_state(self, n_words: int, dtype: _DTypeLikeUint32 | _DTypeLikeUint64 = ...) -> NDArray[uint32 | uint64]: ... + def state(self) -> _SeedSeqState: ... + def generate_state( + self, n_words: int, dtype: _DTypeLikeUint32 | _DTypeLikeUint64 = ... + ) -> NDArray[np.uint32 | np.uint64]: ... def spawn(self, n_children: int) -> list[SeedSequence]: ... class BitGenerator(abc.ABC): @@ -81,23 +78,21 @@ class BitGenerator(abc.ABC): def __init__(self, seed: _ArrayLikeInt_co | SeedSequence | None = ...) -> None: ... def __getstate__(self) -> tuple[dict[str, Any], ISeedSequence]: ... def __setstate__(self, state_seed_seq: dict[str, Any] | tuple[dict[str, Any], ISeedSequence]) -> None: ... - def __reduce__( - self, - ) -> tuple[Callable[[str], BitGenerator], tuple[str], tuple[dict[str, Any], ISeedSequence]]: ... + def __reduce__(self) -> tuple[Callable[[str], BitGenerator], tuple[str], tuple[dict[str, Any], ISeedSequence]]: ... @abc.abstractmethod @property def state(self) -> Mapping[str, Any]: ... @state.setter - def state(self, value: Mapping[str, Any]) -> None: ... + def state(self, value: Mapping[str, Any], /) -> None: ... @property def seed_seq(self) -> ISeedSequence: ... def spawn(self, n_children: int) -> list[BitGenerator]: ... @overload - def random_raw(self, size: None = ..., output: Literal[True] = ...) -> int: ... # type: ignore[misc] + def random_raw(self, size: None = ..., output: Literal[True] = ...) -> int: ... @overload - def random_raw(self, size: _ShapeLike = ..., output: Literal[True] = ...) -> NDArray[uint64]: ... # type: ignore[misc] + def random_raw(self, size: _ShapeLike = ..., output: Literal[True] = ...) -> NDArray[np.uint64]: ... @overload - def random_raw(self, size: _ShapeLike | None = ..., output: Literal[False] = ...) -> None: ... # type: ignore[misc] + def random_raw(self, size: _ShapeLike | None = ..., output: Literal[False] = ...) -> None: ... def _benchmark(self, cnt: int, method: str = ...) -> None: ... @property def ctypes(self) -> _Interface: ... diff --git a/src/numpy-stubs/random/mtrand.pyi b/src/numpy-stubs/random/mtrand.pyi index 841bd6c6..1a42f570 100644 --- a/src/numpy-stubs/random/mtrand.pyi +++ b/src/numpy-stubs/random/mtrand.pyi @@ -3,22 +3,6 @@ from collections.abc import Callable from typing import Any, Literal, overload import numpy as np -from numpy import ( - dtype, - float64, - int8, - int16, - int32, - int64, - int_, - long, - uint, - uint8, - uint16, - uint32, - uint64, - ulong, -) from numpy._typing import ( ArrayLike, NDArray, @@ -52,33 +36,33 @@ class RandomState: @overload def get_state(self, legacy: Literal[False] = ...) -> dict[str, Any]: ... @overload - def get_state(self, legacy: Literal[True] = ...) -> dict[str, Any] | tuple[str, NDArray[uint32], int, int, float]: ... - def set_state(self, state: dict[str, Any] | tuple[str, NDArray[uint32], int, int, float]) -> None: ... + def get_state(self, legacy: Literal[True] = ...) -> dict[str, Any] | tuple[str, NDArray[np.uint32], int, int, float]: ... + def set_state(self, state: dict[str, Any] | tuple[str, NDArray[np.uint32], int, int, float]) -> None: ... @overload def random_sample(self, size: None = ...) -> float: ... # type: ignore[misc] @overload - def random_sample(self, size: _ShapeLike) -> NDArray[float64]: ... + def random_sample(self, size: _ShapeLike) -> NDArray[np.float64]: ... @overload def random(self, size: None = ...) -> float: ... # type: ignore[misc] @overload - def random(self, size: _ShapeLike) -> NDArray[float64]: ... + def random(self, size: _ShapeLike) -> NDArray[np.float64]: ... @overload def beta(self, a: float, b: float, size: None = ...) -> float: ... # type: ignore[misc] @overload - def beta(self, a: _ArrayLikeFloat_co, b: _ArrayLikeFloat_co, size: _ShapeLike | None = ...) -> NDArray[float64]: ... + def beta(self, a: _ArrayLikeFloat_co, b: _ArrayLikeFloat_co, size: _ShapeLike | None = ...) -> NDArray[np.float64]: ... @overload def exponential(self, scale: float = ..., size: None = ...) -> float: ... # type: ignore[misc] @overload - def exponential(self, scale: _ArrayLikeFloat_co = ..., size: _ShapeLike | None = ...) -> NDArray[float64]: ... + def exponential(self, scale: _ArrayLikeFloat_co = ..., size: _ShapeLike | None = ...) -> NDArray[np.float64]: ... @overload def standard_exponential(self, size: None = ...) -> float: ... # type: ignore[misc] @overload - def standard_exponential(self, size: _ShapeLike) -> NDArray[float64]: ... + def standard_exponential(self, size: _ShapeLike) -> NDArray[np.float64]: ... @overload def tomaxint(self, size: None = ...) -> int: ... # type: ignore[misc] @overload # Generates long values, but stores it in a 64bit int: - def tomaxint(self, size: _ShapeLike) -> NDArray[int64]: ... + def tomaxint(self, size: _ShapeLike) -> NDArray[np.int64]: ... @overload def randint( # type: ignore[misc] self, @@ -116,103 +100,103 @@ class RandomState: low: int, high: int | None = ..., size: None = ..., - dtype: dtype[uint8] | type[uint8] | _UInt8Codes | _SupportsDType[dtype[uint8]] = ..., - ) -> uint8: ... + dtype: np.dtype[np.uint8] | type[np.uint8] | _UInt8Codes | _SupportsDType[np.dtype[np.uint8]] = ..., + ) -> np.uint8: ... @overload def randint( # type: ignore[misc] self, low: int, high: int | None = ..., size: None = ..., - dtype: dtype[uint16] | type[uint16] | _UInt16Codes | _SupportsDType[dtype[uint16]] = ..., - ) -> uint16: ... + dtype: np.dtype[np.uint16] | type[np.uint16] | _UInt16Codes | _SupportsDType[np.dtype[np.uint16]] = ..., + ) -> np.uint16: ... @overload def randint( # type: ignore[misc] self, low: int, high: int | None = ..., size: None = ..., - dtype: dtype[uint32] | type[uint32] | _UInt32Codes | _SupportsDType[dtype[uint32]] = ..., - ) -> uint32: ... + dtype: np.dtype[np.uint32] | type[np.uint32] | _UInt32Codes | _SupportsDType[np.dtype[np.uint32]] = ..., + ) -> np.uint32: ... @overload def randint( # type: ignore[misc] self, low: int, high: int | None = ..., size: None = ..., - dtype: dtype[uint] | type[uint] | _UIntCodes | _SupportsDType[dtype[uint]] = ..., - ) -> uint: ... + dtype: np.dtype[np.uint64] | type[np.uint64] | _UIntCodes | _SupportsDType[np.dtype[np.uint64]] = ..., + ) -> np.uint64: ... @overload def randint( # type: ignore[misc] self, low: int, high: int | None = ..., size: None = ..., - dtype: dtype[ulong] | type[ulong] | _ULongCodes | _SupportsDType[dtype[ulong]] = ..., - ) -> ulong: ... + dtype: np.dtype[np.ulong] | type[np.ulong] | _ULongCodes | _SupportsDType[np.dtype[np.ulong]] = ..., + ) -> np.ulong: ... @overload def randint( # type: ignore[misc] self, low: int, high: int | None = ..., size: None = ..., - dtype: dtype[uint64] | type[uint64] | _UInt64Codes | _SupportsDType[dtype[uint64]] = ..., - ) -> uint64: ... + dtype: np.dtype[np.uint64] | type[np.uint64] | _UInt64Codes | _SupportsDType[np.dtype[np.uint64]] = ..., + ) -> np.uint64: ... @overload def randint( # type: ignore[misc] self, low: int, high: int | None = ..., size: None = ..., - dtype: dtype[int8] | type[int8] | _Int8Codes | _SupportsDType[dtype[int8]] = ..., - ) -> int8: ... + dtype: np.dtype[np.int8] | type[np.int8] | _Int8Codes | _SupportsDType[np.dtype[np.int8]] = ..., + ) -> np.int8: ... @overload def randint( # type: ignore[misc] self, low: int, high: int | None = ..., size: None = ..., - dtype: dtype[int16] | type[int16] | _Int16Codes | _SupportsDType[dtype[int16]] = ..., - ) -> int16: ... + dtype: np.dtype[np.int16] | type[np.int16] | _Int16Codes | _SupportsDType[np.dtype[np.int16]] = ..., + ) -> np.int16: ... @overload def randint( # type: ignore[misc] self, low: int, high: int | None = ..., size: None = ..., - dtype: dtype[int32] | type[int32] | _Int32Codes | _SupportsDType[dtype[int32]] = ..., - ) -> int32: ... + dtype: np.dtype[np.int32] | type[np.int32] | _Int32Codes | _SupportsDType[np.dtype[np.int32]] = ..., + ) -> np.int32: ... @overload def randint( # type: ignore[misc] self, low: int, high: int | None = ..., size: None = ..., - dtype: dtype[int_] | type[int_] | _IntCodes | _SupportsDType[dtype[int_]] = ..., - ) -> int_: ... + dtype: np.dtype[np.int_] | type[np.int_] | _IntCodes | _SupportsDType[np.dtype[np.int_]] = ..., + ) -> np.int_: ... @overload def randint( # type: ignore[misc] self, low: int, high: int | None = ..., size: None = ..., - dtype: dtype[long] | type[long] | _LongCodes | _SupportsDType[dtype[long]] = ..., - ) -> long: ... + dtype: np.dtype[np.long] | type[np.long] | _LongCodes | _SupportsDType[np.dtype[np.long]] = ..., + ) -> np.long: ... @overload def randint( # type: ignore[misc] self, low: int, high: int | None = ..., size: None = ..., - dtype: dtype[int64] | type[int64] | _Int64Codes | _SupportsDType[dtype[int64]] = ..., - ) -> int64: ... + dtype: np.dtype[np.int64] | type[np.int64] | _Int64Codes | _SupportsDType[np.dtype[np.int64]] = ..., + ) -> np.int64: ... @overload def randint( # type: ignore[misc] self, low: _ArrayLikeInt_co, high: _ArrayLikeInt_co | None = ..., size: _ShapeLike | None = ..., - ) -> NDArray[long]: ... + ) -> NDArray[np.long]: ... @overload def randint( # type: ignore[misc] self, @@ -227,80 +211,80 @@ class RandomState: low: _ArrayLikeInt_co, high: _ArrayLikeInt_co | None = ..., size: _ShapeLike | None = ..., - dtype: dtype[int8] | type[int8] | _Int8Codes | _SupportsDType[dtype[int8]] = ..., - ) -> NDArray[int8]: ... + dtype: np.dtype[np.int8] | type[np.int8] | _Int8Codes | _SupportsDType[np.dtype[np.int8]] = ..., + ) -> NDArray[np.int8]: ... @overload def randint( # type: ignore[misc] self, low: _ArrayLikeInt_co, high: _ArrayLikeInt_co | None = ..., size: _ShapeLike | None = ..., - dtype: dtype[int16] | type[int16] | _Int16Codes | _SupportsDType[dtype[int16]] = ..., - ) -> NDArray[int16]: ... + dtype: np.dtype[np.int16] | type[np.int16] | _Int16Codes | _SupportsDType[np.dtype[np.int16]] = ..., + ) -> NDArray[np.int16]: ... @overload def randint( # type: ignore[misc] self, low: _ArrayLikeInt_co, high: _ArrayLikeInt_co | None = ..., size: _ShapeLike | None = ..., - dtype: dtype[int32] | type[int32] | _Int32Codes | _SupportsDType[dtype[int32]] = ..., - ) -> NDArray[int32]: ... + dtype: np.dtype[np.int32] | type[np.int32] | _Int32Codes | _SupportsDType[np.dtype[np.int32]] = ..., + ) -> NDArray[np.int32]: ... @overload def randint( # type: ignore[misc] self, low: _ArrayLikeInt_co, high: _ArrayLikeInt_co | None = ..., size: _ShapeLike | None = ..., - dtype: dtype[int64] | type[int64] | _Int64Codes | _SupportsDType[dtype[int64]] | None = ..., - ) -> NDArray[int64]: ... + dtype: np.dtype[np.int64] | type[np.int64] | _Int64Codes | _SupportsDType[np.dtype[np.int64]] | None = ..., + ) -> NDArray[np.int64]: ... @overload def randint( # type: ignore[misc] self, low: _ArrayLikeInt_co, high: _ArrayLikeInt_co | None = ..., size: _ShapeLike | None = ..., - dtype: dtype[uint8] | type[uint8] | _UInt8Codes | _SupportsDType[dtype[uint8]] = ..., - ) -> NDArray[uint8]: ... + dtype: np.dtype[np.uint8] | type[np.uint8] | _UInt8Codes | _SupportsDType[np.dtype[np.uint8]] = ..., + ) -> NDArray[np.uint8]: ... @overload def randint( # type: ignore[misc] self, low: _ArrayLikeInt_co, high: _ArrayLikeInt_co | None = ..., size: _ShapeLike | None = ..., - dtype: dtype[uint16] | type[uint16] | _UInt16Codes | _SupportsDType[dtype[uint16]] = ..., - ) -> NDArray[uint16]: ... + dtype: np.dtype[np.uint16] | type[np.uint16] | _UInt16Codes | _SupportsDType[np.dtype[np.uint16]] = ..., + ) -> NDArray[np.uint16]: ... @overload def randint( # type: ignore[misc] self, low: _ArrayLikeInt_co, high: _ArrayLikeInt_co | None = ..., size: _ShapeLike | None = ..., - dtype: dtype[uint32] | type[uint32] | _UInt32Codes | _SupportsDType[dtype[uint32]] = ..., - ) -> NDArray[uint32]: ... + dtype: np.dtype[np.uint32] | type[np.uint32] | _UInt32Codes | _SupportsDType[np.dtype[np.uint32]] = ..., + ) -> NDArray[np.uint32]: ... @overload def randint( # type: ignore[misc] self, low: _ArrayLikeInt_co, high: _ArrayLikeInt_co | None = ..., size: _ShapeLike | None = ..., - dtype: dtype[uint64] | type[uint64] | _UInt64Codes | _SupportsDType[dtype[uint64]] = ..., - ) -> NDArray[uint64]: ... + dtype: np.dtype[np.uint64] | type[np.uint64] | _UInt64Codes | _SupportsDType[np.dtype[np.uint64]] = ..., + ) -> NDArray[np.uint64]: ... @overload def randint( # type: ignore[misc] self, low: _ArrayLikeInt_co, high: _ArrayLikeInt_co | None = ..., size: _ShapeLike | None = ..., - dtype: type[int | long] | dtype[long] | _LongCodes | _SupportsDType[dtype[long]] = ..., - ) -> NDArray[long]: ... + dtype: type[int | np.long] | np.dtype[np.long] | _LongCodes | _SupportsDType[np.dtype[np.long]] = ..., + ) -> NDArray[np.long]: ... @overload def randint( # type: ignore[misc] self, low: _ArrayLikeInt_co, high: _ArrayLikeInt_co | None = ..., size: _ShapeLike | None = ..., - dtype: dtype[ulong] | type[ulong] | _ULongCodes | _SupportsDType[dtype[ulong]] = ..., - ) -> NDArray[ulong]: ... + dtype: np.dtype[np.ulong] | type[np.ulong] | _ULongCodes | _SupportsDType[np.dtype[np.ulong]] = ..., + ) -> NDArray[np.ulong]: ... def bytes(self, length: int) -> builtins.bytes: ... @overload def choice( @@ -317,7 +301,7 @@ class RandomState: size: _ShapeLike = ..., replace: bool = ..., p: _ArrayLikeFloat_co | None = ..., - ) -> NDArray[long]: ... + ) -> NDArray[np.long]: ... @overload def choice( self, @@ -342,15 +326,15 @@ class RandomState: low: _ArrayLikeFloat_co = ..., high: _ArrayLikeFloat_co = ..., size: _ShapeLike | None = ..., - ) -> NDArray[float64]: ... + ) -> NDArray[np.float64]: ... @overload def rand(self) -> float: ... @overload - def rand(self, *args: int) -> NDArray[float64]: ... + def rand(self, *args: int) -> NDArray[np.float64]: ... @overload def randn(self) -> float: ... @overload - def randn(self, *args: int) -> NDArray[float64]: ... + def randn(self, *args: int) -> NDArray[np.float64]: ... @overload def random_integers(self, low: int, high: int | None = ..., size: None = ...) -> int: ... # type: ignore[misc] @overload @@ -359,13 +343,13 @@ class RandomState: low: _ArrayLikeInt_co, high: _ArrayLikeInt_co | None = ..., size: _ShapeLike | None = ..., - ) -> NDArray[long]: ... + ) -> NDArray[np.long]: ... @overload def standard_normal(self, size: None = ...) -> float: ... # type: ignore[misc] @overload def standard_normal( # type: ignore[misc] self, size: _ShapeLike = ... - ) -> NDArray[float64]: ... + ) -> NDArray[np.float64]: ... @overload def normal(self, loc: float = ..., scale: float = ..., size: None = ...) -> float: ... # type: ignore[misc] @overload @@ -374,7 +358,7 @@ class RandomState: loc: _ArrayLikeFloat_co = ..., scale: _ArrayLikeFloat_co = ..., size: _ShapeLike | None = ..., - ) -> NDArray[float64]: ... + ) -> NDArray[np.float64]: ... @overload def standard_gamma( # type: ignore[misc] self, @@ -386,7 +370,7 @@ class RandomState: self, shape: _ArrayLikeFloat_co, size: _ShapeLike | None = ..., - ) -> NDArray[float64]: ... + ) -> NDArray[np.float64]: ... @overload def gamma(self, shape: float, scale: float = ..., size: None = ...) -> float: ... # type: ignore[misc] @overload @@ -395,11 +379,11 @@ class RandomState: shape: _ArrayLikeFloat_co, scale: _ArrayLikeFloat_co = ..., size: _ShapeLike | None = ..., - ) -> NDArray[float64]: ... + ) -> NDArray[np.float64]: ... @overload def f(self, dfnum: float, dfden: float, size: None = ...) -> float: ... # type: ignore[misc] @overload - def f(self, dfnum: _ArrayLikeFloat_co, dfden: _ArrayLikeFloat_co, size: _ShapeLike | None = ...) -> NDArray[float64]: ... + def f(self, dfnum: _ArrayLikeFloat_co, dfden: _ArrayLikeFloat_co, size: _ShapeLike | None = ...) -> NDArray[np.float64]: ... @overload def noncentral_f(self, dfnum: float, dfden: float, nonc: float, size: None = ...) -> float: ... # type: ignore[misc] @overload @@ -409,43 +393,45 @@ class RandomState: dfden: _ArrayLikeFloat_co, nonc: _ArrayLikeFloat_co, size: _ShapeLike | None = ..., - ) -> NDArray[float64]: ... + ) -> NDArray[np.float64]: ... @overload def chisquare(self, df: float, size: None = ...) -> float: ... # type: ignore[misc] @overload - def chisquare(self, df: _ArrayLikeFloat_co, size: _ShapeLike | None = ...) -> NDArray[float64]: ... + def chisquare(self, df: _ArrayLikeFloat_co, size: _ShapeLike | None = ...) -> NDArray[np.float64]: ... @overload def noncentral_chisquare(self, df: float, nonc: float, size: None = ...) -> float: ... # type: ignore[misc] @overload def noncentral_chisquare( self, df: _ArrayLikeFloat_co, nonc: _ArrayLikeFloat_co, size: _ShapeLike | None = ... - ) -> NDArray[float64]: ... + ) -> NDArray[np.float64]: ... @overload def standard_t(self, df: float, size: None = ...) -> float: ... # type: ignore[misc] @overload - def standard_t(self, df: _ArrayLikeFloat_co, size: None = ...) -> NDArray[float64]: ... + def standard_t(self, df: _ArrayLikeFloat_co, size: None = ...) -> NDArray[np.float64]: ... @overload - def standard_t(self, df: _ArrayLikeFloat_co, size: _ShapeLike = ...) -> NDArray[float64]: ... + def standard_t(self, df: _ArrayLikeFloat_co, size: _ShapeLike = ...) -> NDArray[np.float64]: ... @overload def vonmises(self, mu: float, kappa: float, size: None = ...) -> float: ... # type: ignore[misc] @overload - def vonmises(self, mu: _ArrayLikeFloat_co, kappa: _ArrayLikeFloat_co, size: _ShapeLike | None = ...) -> NDArray[float64]: ... + def vonmises( + self, mu: _ArrayLikeFloat_co, kappa: _ArrayLikeFloat_co, size: _ShapeLike | None = ... + ) -> NDArray[np.float64]: ... @overload def pareto(self, a: float, size: None = ...) -> float: ... # type: ignore[misc] @overload - def pareto(self, a: _ArrayLikeFloat_co, size: _ShapeLike | None = ...) -> NDArray[float64]: ... + def pareto(self, a: _ArrayLikeFloat_co, size: _ShapeLike | None = ...) -> NDArray[np.float64]: ... @overload def weibull(self, a: float, size: None = ...) -> float: ... # type: ignore[misc] @overload - def weibull(self, a: _ArrayLikeFloat_co, size: _ShapeLike | None = ...) -> NDArray[float64]: ... + def weibull(self, a: _ArrayLikeFloat_co, size: _ShapeLike | None = ...) -> NDArray[np.float64]: ... @overload def power(self, a: float, size: None = ...) -> float: ... # type: ignore[misc] @overload - def power(self, a: _ArrayLikeFloat_co, size: _ShapeLike | None = ...) -> NDArray[float64]: ... + def power(self, a: _ArrayLikeFloat_co, size: _ShapeLike | None = ...) -> NDArray[np.float64]: ... @overload def standard_cauchy(self, size: None = ...) -> float: ... # type: ignore[misc] @overload - def standard_cauchy(self, size: _ShapeLike = ...) -> NDArray[float64]: ... + def standard_cauchy(self, size: _ShapeLike = ...) -> NDArray[np.float64]: ... @overload def laplace(self, loc: float = ..., scale: float = ..., size: None = ...) -> float: ... # type: ignore[misc] @overload @@ -454,7 +440,7 @@ class RandomState: loc: _ArrayLikeFloat_co = ..., scale: _ArrayLikeFloat_co = ..., size: _ShapeLike | None = ..., - ) -> NDArray[float64]: ... + ) -> NDArray[np.float64]: ... @overload def gumbel(self, loc: float = ..., scale: float = ..., size: None = ...) -> float: ... # type: ignore[misc] @overload @@ -463,7 +449,7 @@ class RandomState: loc: _ArrayLikeFloat_co = ..., scale: _ArrayLikeFloat_co = ..., size: _ShapeLike | None = ..., - ) -> NDArray[float64]: ... + ) -> NDArray[np.float64]: ... @overload def logistic(self, loc: float = ..., scale: float = ..., size: None = ...) -> float: ... # type: ignore[misc] @overload @@ -472,7 +458,7 @@ class RandomState: loc: _ArrayLikeFloat_co = ..., scale: _ArrayLikeFloat_co = ..., size: _ShapeLike | None = ..., - ) -> NDArray[float64]: ... + ) -> NDArray[np.float64]: ... @overload def lognormal(self, mean: float = ..., sigma: float = ..., size: None = ...) -> float: ... # type: ignore[misc] @overload @@ -481,15 +467,15 @@ class RandomState: mean: _ArrayLikeFloat_co = ..., sigma: _ArrayLikeFloat_co = ..., size: _ShapeLike | None = ..., - ) -> NDArray[float64]: ... + ) -> NDArray[np.float64]: ... @overload def rayleigh(self, scale: float = ..., size: None = ...) -> float: ... # type: ignore[misc] @overload - def rayleigh(self, scale: _ArrayLikeFloat_co = ..., size: _ShapeLike | None = ...) -> NDArray[float64]: ... + def rayleigh(self, scale: _ArrayLikeFloat_co = ..., size: _ShapeLike | None = ...) -> NDArray[np.float64]: ... @overload def wald(self, mean: float, scale: float, size: None = ...) -> float: ... # type: ignore[misc] @overload - def wald(self, mean: _ArrayLikeFloat_co, scale: _ArrayLikeFloat_co, size: _ShapeLike | None = ...) -> NDArray[float64]: ... + def wald(self, mean: _ArrayLikeFloat_co, scale: _ArrayLikeFloat_co, size: _ShapeLike | None = ...) -> NDArray[np.float64]: ... @overload def triangular(self, left: float, mode: float, right: float, size: None = ...) -> float: ... # type: ignore[misc] @overload @@ -499,27 +485,29 @@ class RandomState: mode: _ArrayLikeFloat_co, right: _ArrayLikeFloat_co, size: _ShapeLike | None = ..., - ) -> NDArray[float64]: ... + ) -> NDArray[np.float64]: ... @overload def binomial(self, n: int, p: float, size: None = ...) -> int: ... # type: ignore[misc] @overload - def binomial(self, n: _ArrayLikeInt_co, p: _ArrayLikeFloat_co, size: _ShapeLike | None = ...) -> NDArray[long]: ... + def binomial(self, n: _ArrayLikeInt_co, p: _ArrayLikeFloat_co, size: _ShapeLike | None = ...) -> NDArray[np.long]: ... @overload def negative_binomial(self, n: float, p: float, size: None = ...) -> int: ... # type: ignore[misc] @overload - def negative_binomial(self, n: _ArrayLikeFloat_co, p: _ArrayLikeFloat_co, size: _ShapeLike | None = ...) -> NDArray[long]: ... + def negative_binomial( + self, n: _ArrayLikeFloat_co, p: _ArrayLikeFloat_co, size: _ShapeLike | None = ... + ) -> NDArray[np.long]: ... @overload def poisson(self, lam: float = ..., size: None = ...) -> int: ... # type: ignore[misc] @overload - def poisson(self, lam: _ArrayLikeFloat_co = ..., size: _ShapeLike | None = ...) -> NDArray[long]: ... + def poisson(self, lam: _ArrayLikeFloat_co = ..., size: _ShapeLike | None = ...) -> NDArray[np.long]: ... @overload def zipf(self, a: float, size: None = ...) -> int: ... # type: ignore[misc] @overload - def zipf(self, a: _ArrayLikeFloat_co, size: _ShapeLike | None = ...) -> NDArray[long]: ... + def zipf(self, a: _ArrayLikeFloat_co, size: _ShapeLike | None = ...) -> NDArray[np.long]: ... @overload def geometric(self, p: float, size: None = ...) -> int: ... # type: ignore[misc] @overload - def geometric(self, p: _ArrayLikeFloat_co, size: _ShapeLike | None = ...) -> NDArray[long]: ... + def geometric(self, p: _ArrayLikeFloat_co, size: _ShapeLike | None = ...) -> NDArray[np.long]: ... @overload def hypergeometric(self, ngood: int, nbad: int, nsample: int, size: None = ...) -> int: ... # type: ignore[misc] @overload @@ -529,11 +517,11 @@ class RandomState: nbad: _ArrayLikeInt_co, nsample: _ArrayLikeInt_co, size: _ShapeLike | None = ..., - ) -> NDArray[long]: ... + ) -> NDArray[np.long]: ... @overload def logseries(self, p: float, size: None = ...) -> int: ... # type: ignore[misc] @overload - def logseries(self, p: _ArrayLikeFloat_co, size: _ShapeLike | None = ...) -> NDArray[long]: ... + def logseries(self, p: _ArrayLikeFloat_co, size: _ShapeLike | None = ...) -> NDArray[np.long]: ... def multivariate_normal( self, mean: _ArrayLikeFloat_co, @@ -541,12 +529,12 @@ class RandomState: size: _ShapeLike | None = ..., check_valid: Literal["warn", "raise", "ignore"] = ..., tol: float = ..., - ) -> NDArray[float64]: ... - def multinomial(self, n: _ArrayLikeInt_co, pvals: _ArrayLikeFloat_co, size: _ShapeLike | None = ...) -> NDArray[long]: ... - def dirichlet(self, alpha: _ArrayLikeFloat_co, size: _ShapeLike | None = ...) -> NDArray[float64]: ... + ) -> NDArray[np.float64]: ... + def multinomial(self, n: _ArrayLikeInt_co, pvals: _ArrayLikeFloat_co, size: _ShapeLike | None = ...) -> NDArray[np.long]: ... + def dirichlet(self, alpha: _ArrayLikeFloat_co, size: _ShapeLike | None = ...) -> NDArray[np.float64]: ... def shuffle(self, x: ArrayLike) -> None: ... @overload - def permutation(self, x: int) -> NDArray[long]: ... + def permutation(self, x: int) -> NDArray[np.long]: ... @overload def permutation(self, x: ArrayLike) -> NDArray[Any]: ... diff --git a/src/numpy-stubs/testing/_private/utils.pyi b/src/numpy-stubs/testing/_private/utils.pyi index 5b575f99..615137a6 100644 --- a/src/numpy-stubs/testing/_private/utils.pyi +++ b/src/numpy-stubs/testing/_private/utils.pyi @@ -3,7 +3,7 @@ import sys import types import unittest import warnings -from _typeshed import GenericPath, StrOrBytesPath, StrPath +from _typeshed import ConvertibleToFloat, GenericPath, StrOrBytesPath, StrPath from collections.abc import Callable, Iterable, Sequence from contextlib import _GeneratorContextManager from re import Pattern @@ -15,17 +15,16 @@ from typing import ( Literal as L, NoReturn, ParamSpec, - Self, SupportsIndex, TypeAlias, TypeVar, overload, type_check_only, ) +from typing_extensions import Self from unittest.case import SkipTest import numpy as np -from numpy import _ConvertibleToFloat, number, object_ from numpy._typing import ( ArrayLike, DTypeLike, @@ -91,7 +90,7 @@ _FT = TypeVar("_FT", bound=Callable[..., Any]) # Must return a bool or an ndarray/generic type # that is supported by `np.logical_and.reduce` _ComparisonFunc: TypeAlias = Callable[ - [NDArray[Any], NDArray[Any]], (bool | np.bool | number[Any] | NDArray[np.bool | number[Any] | object_]) + [NDArray[Any], NDArray[Any]], (bool | np.bool | np.number | NDArray[np.bool | np.number | np.object_]) ] class KnownFailureException(Exception): ... @@ -121,9 +120,10 @@ class clear_and_catch_warnings(warnings.catch_warnings[list[warnings.WarningMess def __enter__(self) -> list[warnings.WarningMessage] | None: ... def __exit__( self, - __exc_type: type[BaseException] | None = ..., - __exc_val: BaseException | None = ..., - __exc_tb: types.TracebackType | None = ..., + exc_type: type[BaseException] | None = ..., + exc_val: BaseException | None = ..., + exc_tb: types.TracebackType | None = ..., + /, ) -> None: ... # Type-check only `clear_and_catch_warnings` subclasses for both values of the @@ -158,9 +158,10 @@ class suppress_warnings: def __enter__(self) -> Self: ... def __exit__( self, - __exc_type: type[BaseException] | None = ..., - __exc_val: BaseException | None = ..., - __exc_tb: types.TracebackType | None = ..., + exc_type: type[BaseException] | None = ..., + exc_val: BaseException | None = ..., + exc_tb: types.TracebackType | None = ..., + /, ) -> None: ... def __call__(self, func: _FT) -> _FT: ... @@ -220,8 +221,8 @@ def assert_almost_equal( # Anything that can be coerced into `builtins.float` def assert_approx_equal( - actual: _ConvertibleToFloat, - desired: _ConvertibleToFloat, + actual: ConvertibleToFloat, + desired: ConvertibleToFloat, significant: int = ..., err_msg: object = ..., verbose: bool = ..., @@ -276,10 +277,10 @@ def rundocs( filename: StrPath | None = ..., raise_on_error: bool = ..., ) -> None: ... -def check_support_sve(__cache: list[_T]) -> _T: ... +def check_support_sve(cache: list[_T], /) -> _T: ... def raises(*args: type[BaseException]) -> Callable[[_FT], _FT]: ... @overload -def assert_raises( # type: ignore +def assert_raises( expected_exception: type[BaseException] | tuple[type[BaseException], ...], callable: Callable[_P, Any], /, diff --git a/tests/data/misc/extended_precision.pyi b/tests/data/misc/extended_precision.pyi index 2f69f430..3f27edfe 100644 --- a/tests/data/misc/extended_precision.pyi +++ b/tests/data/misc/extended_precision.pyi @@ -1,4 +1,4 @@ -from typing import assert_type +from typing_extensions import assert_type import numpy as np from numpy._typing import _80Bit, _96Bit, _128Bit, _256Bit diff --git a/tests/data/reveal/arrayterator.pyi b/tests/data/reveal/arrayterator.pyi index d7761940..79a1d93a 100644 --- a/tests/data/reveal/arrayterator.pyi +++ b/tests/data/reveal/arrayterator.pyi @@ -1,5 +1,5 @@ from collections.abc import Generator -from typing import assert_type +from typing_extensions import assert_type import numpy as np import numpy.typing as npt diff --git a/tests/data/reveal/chararray.pyi b/tests/data/reveal/chararray.pyi index 45532f6f..dd0428c4 100644 --- a/tests/data/reveal/chararray.pyi +++ b/tests/data/reveal/chararray.pyi @@ -1,4 +1,4 @@ -from typing import assert_type +from typing_extensions import assert_type import numpy as np import numpy.typing as npt diff --git a/tests/data/reveal/comparisons.pyi b/tests/data/reveal/comparisons.pyi index 1106b25f..6630628f 100644 --- a/tests/data/reveal/comparisons.pyi +++ b/tests/data/reveal/comparisons.pyi @@ -1,6 +1,6 @@ import decimal import fractions -from typing import assert_type +from typing_extensions import assert_type import numpy as np import numpy.typing as npt diff --git a/tests/data/reveal/ctypeslib.pyi b/tests/data/reveal/ctypeslib.pyi index 10ef143d..23d4f1e4 100644 --- a/tests/data/reveal/ctypeslib.pyi +++ b/tests/data/reveal/ctypeslib.pyi @@ -1,10 +1,10 @@ import ctypes as ct import sys -from typing import Any, assert_type +from typing import Any +from typing_extensions import assert_type import numpy as np import numpy.typing as npt -from numpy import ctypeslib AR_bool: npt.NDArray[np.bool] AR_ubyte: npt.NDArray[np.ubyte] @@ -24,13 +24,13 @@ AR_void: npt.NDArray[np.void] pointer: ct._Pointer[Any] -assert_type(np.ctypeslib.c_intp(), ctypeslib.c_intp) +assert_type(np.ctypeslib.c_intp(), np.ctypeslib.c_intp) -assert_type(np.ctypeslib.ndpointer(), type[ctypeslib._ndptr[None]]) -assert_type(np.ctypeslib.ndpointer(dtype=np.float64), type[ctypeslib._ndptr[np.dtype[np.float64]]]) -assert_type(np.ctypeslib.ndpointer(dtype=float), type[ctypeslib._ndptr[np.dtype[Any]]]) -assert_type(np.ctypeslib.ndpointer(shape=(10, 3)), type[ctypeslib._ndptr[None]]) -assert_type(np.ctypeslib.ndpointer(np.int64, shape=(10, 3)), type[ctypeslib._concrete_ndptr[np.dtype[np.int64]]]) +assert_type(np.ctypeslib.ndpointer(), type[np.ctypeslib._ndptr[None]]) +assert_type(np.ctypeslib.ndpointer(dtype=np.float64), type[np.ctypeslib._ndptr[np.dtype[np.float64]]]) +assert_type(np.ctypeslib.ndpointer(dtype=float), type[np.ctypeslib._ndptr[np.dtype[Any]]]) +assert_type(np.ctypeslib.ndpointer(shape=(10, 3)), type[np.ctypeslib._ndptr[None]]) +assert_type(np.ctypeslib.ndpointer(np.int64, shape=(10, 3)), type[np.ctypeslib._concrete_ndptr[np.dtype[np.int64]]]) assert_type(np.ctypeslib.ndpointer(int, shape=(1,)), type[np.ctypeslib._concrete_ndptr[np.dtype[Any]]]) assert_type(np.ctypeslib.as_ctypes_type(np.bool), type[ct.c_bool]) diff --git a/tests/data/reveal/lib_utils.pyi b/tests/data/reveal/lib_utils.pyi index 95ff711f..f797df00 100644 --- a/tests/data/reveal/lib_utils.pyi +++ b/tests/data/reveal/lib_utils.pyi @@ -1,5 +1,5 @@ from io import StringIO -from typing import assert_type +from typing_extensions import assert_type import numpy as np import numpy.typing as npt diff --git a/tests/data/reveal/lib_version.pyi b/tests/data/reveal/lib_version.pyi index 03735375..e117d776 100644 --- a/tests/data/reveal/lib_version.pyi +++ b/tests/data/reveal/lib_version.pyi @@ -1,4 +1,4 @@ -from typing import assert_type +from typing_extensions import assert_type from numpy.lib import NumpyVersion diff --git a/tests/data/reveal/mod.pyi b/tests/data/reveal/mod.pyi index f92c20b4..b14b54c5 100644 --- a/tests/data/reveal/mod.pyi +++ b/tests/data/reveal/mod.pyi @@ -1,5 +1,5 @@ import datetime as dt -from typing import assert_type +from typing_extensions import assert_type import numpy as np import numpy.typing as npt diff --git a/tests/data/reveal/modules.pyi b/tests/data/reveal/modules.pyi index 628fb500..62fcda5c 100644 --- a/tests/data/reveal/modules.pyi +++ b/tests/data/reveal/modules.pyi @@ -1,8 +1,7 @@ import types -from typing import assert_type +from typing_extensions import assert_type import numpy as np -from numpy import f2py assert_type(np, types.ModuleType) @@ -48,4 +47,4 @@ assert_type(np.ma.__all__, list[str]) assert_type(np.random.__all__, list[str]) assert_type(np.rec.__all__, list[str]) assert_type(np.testing.__all__, list[str]) -assert_type(f2py.__all__, list[str]) +assert_type(np.f2py.__all__, list[str]) diff --git a/tests/data/reveal/ndarray_shape_manipulation.pyi b/tests/data/reveal/ndarray_shape_manipulation.pyi index c6774e14..ddbe2bfd 100644 --- a/tests/data/reveal/ndarray_shape_manipulation.pyi +++ b/tests/data/reveal/ndarray_shape_manipulation.pyi @@ -1,4 +1,4 @@ -from typing import assert_type +from typing_extensions import assert_type import numpy as np import numpy.typing as npt diff --git a/tests/data/reveal/warnings_and_errors.pyi b/tests/data/reveal/warnings_and_errors.pyi index f756a8e4..60327616 100644 --- a/tests/data/reveal/warnings_and_errors.pyi +++ b/tests/data/reveal/warnings_and_errors.pyi @@ -1,4 +1,4 @@ -from typing import assert_type +from typing_extensions import assert_type import numpy.exceptions as ex diff --git a/tools/__init__.py b/tools/__init__.py index e69de29b..740e2fe2 100644 --- a/tools/__init__.py +++ b/tools/__init__.py @@ -0,0 +1 @@ +"""Development tools."""