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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/numpy-stubs/@test/static/reject/comparisons.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ AR_c > b"" # type: ignore[operator] # pyright: ignore[reportOperatorIssue]

AR_m > AR_f # type: ignore[operator] # pyright: ignore[reportOperatorIssue]
AR_m > AR_c # type: ignore[operator] # pyright: ignore[reportOperatorIssue]
AR_m > AR_M # type: ignore[operator] # pyright: ignore[reportOperatorIssue]
AR_m > AR_M # type: ignore[operator]
AR_m > "" # type: ignore[operator] # pyright: ignore[reportOperatorIssue]
AR_m > b"" # type: ignore[operator] # pyright: ignore[reportOperatorIssue]

Expand All @@ -34,6 +34,6 @@ AR_m > b"" # type: ignore[operator] # pyright: ignore[reportOperatorIssue]
AR_M > AR_i # type: ignore[operator] # pyright: ignore[reportOperatorIssue]
AR_M > AR_f # type: ignore[operator] # pyright: ignore[reportOperatorIssue]
AR_M > AR_c # type: ignore[operator] # pyright: ignore[reportOperatorIssue]
AR_M > AR_m # type: ignore[operator] # pyright: ignore[reportOperatorIssue]
AR_M > AR_m # type: ignore[operator]
AR_M > "" # type: ignore[operator] # pyright: ignore[reportOperatorIssue]
AR_M > b"" # type: ignore[operator] # pyright: ignore[reportOperatorIssue]
2 changes: 1 addition & 1 deletion src/numpy-stubs/@test/static/reject/rec.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ np.rec.fromarrays( # type: ignore[call-overload] # pyright: ignore[reportCallI
formats=["f8", "f8"], # pyright: ignore[reportArgumentType]
)

np.rec.fromrecords(AR_i8) # type: ignore[arg-type] # pyright: ignore[reportArgumentType]
np.rec.fromrecords(AR_i8) # type: ignore[arg-type]
np.rec.fromrecords( # type: ignore[call-overload] # pyright: ignore[reportCallIssue]
[(1.5,)],
dtype=[("f8", "f8")],
Expand Down
39 changes: 14 additions & 25 deletions src/numpy-stubs/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -335,18 +335,7 @@ from ._core.umath import (
from ._expired_attrs_2_0 import __expired_attributes__ as __expired_attributes__
from ._globals import _CopyMode as _CopyMode, _NoValue as _NoValue, _NoValueType
from ._pytesttester import PytestTester
from ._typing import (
ArrayLike,
DTypeLike,
_ArrayLikeDT64_co,
_ArrayLikeObject_co,
_ArrayLikeTD64_co,
_DTypeLike,
_NestedSequence,
_NumberLike_co,
_ScalarLike_co,
_TD64Like_co,
)
from ._typing import ArrayLike, DTypeLike, _DTypeLike, _NestedSequence, _NumberLike_co, _ScalarLike_co, _TD64Like_co
from .lib import scimath as emath
from .lib._arraypad_impl import pad
from .lib._arraysetops_impl import (
Expand Down Expand Up @@ -1867,49 +1856,49 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]):
@overload
def __lt__(self: _ArrayComplex_co, other: _nt.CoComplex_nd, /) -> _nt.Array[bool_]: ...
@overload
def __lt__(self: _ArrayTD64_co, other: _ArrayLikeTD64_co, /) -> _nt.Array[bool_]: ...
def __lt__(self: _ArrayTD64_co, other: _nt.CoTimeDelta_nd, /) -> _nt.Array[bool_]: ...
@overload
def __lt__(self: _nt.Array[datetime64], other: _ArrayLikeDT64_co, /) -> _nt.Array[bool_]: ...
def __lt__(self: _nt.Array[datetime64], other: _nt.CoDateTime_nd, /) -> _nt.Array[bool_]: ...
@overload
def __lt__(self: _nt.Array[object_], other: object, /) -> _nt.Array[bool_]: ...
@overload
def __lt__(self, other: _ArrayLikeObject_co, /) -> _nt.Array[bool_]: ...
def __lt__(self, other: _nt.ToObject_nd, /) -> _nt.Array[bool_]: ...

#
@overload
def __le__(self: _ArrayComplex_co, other: _nt.CoComplex_nd, /) -> _nt.Array[bool_]: ...
@overload
def __le__(self: _ArrayTD64_co, other: _ArrayLikeTD64_co, /) -> _nt.Array[bool_]: ...
def __le__(self: _ArrayTD64_co, other: _nt.CoTimeDelta_nd, /) -> _nt.Array[bool_]: ...
@overload
def __le__(self: _nt.Array[datetime64], other: _ArrayLikeDT64_co, /) -> _nt.Array[bool_]: ...
def __le__(self: _nt.Array[datetime64], other: _nt.CoDateTime_nd, /) -> _nt.Array[bool_]: ...
@overload
def __le__(self: _nt.Array[object_], other: object, /) -> _nt.Array[bool_]: ...
@overload
def __le__(self, other: _ArrayLikeObject_co, /) -> _nt.Array[bool_]: ...
def __le__(self, other: _nt.ToObject_nd, /) -> _nt.Array[bool_]: ...

#
@overload
def __gt__(self: _ArrayComplex_co, other: _nt.CoComplex_nd, /) -> _nt.Array[bool_]: ...
@overload
def __gt__(self: _ArrayTD64_co, other: _ArrayLikeTD64_co, /) -> _nt.Array[bool_]: ...
def __gt__(self: _ArrayTD64_co, other: _nt.CoTimeDelta_nd, /) -> _nt.Array[bool_]: ...
@overload
def __gt__(self: _nt.Array[datetime64], other: _ArrayLikeDT64_co, /) -> _nt.Array[bool_]: ...
def __gt__(self: _nt.Array[datetime64], other: _nt.CoDateTime_nd, /) -> _nt.Array[bool_]: ...
@overload
def __gt__(self: _nt.Array[object_], other: object, /) -> _nt.Array[bool_]: ...
@overload
def __gt__(self, other: _ArrayLikeObject_co, /) -> _nt.Array[bool_]: ...
def __gt__(self, other: _nt.ToObject_nd, /) -> _nt.Array[bool_]: ...

#
@overload
def __ge__(self: _ArrayComplex_co, other: _nt.CoComplex_nd, /) -> _nt.Array[bool_]: ...
@overload
def __ge__(self: _ArrayTD64_co, other: _ArrayLikeTD64_co, /) -> _nt.Array[bool_]: ...
def __ge__(self: _ArrayTD64_co, other: _nt.CoTimeDelta_nd, /) -> _nt.Array[bool_]: ...
@overload
def __ge__(self: _nt.Array[datetime64], other: _ArrayLikeDT64_co, /) -> _nt.Array[bool_]: ...
def __ge__(self: _nt.Array[datetime64], other: _nt.CoDateTime_nd, /) -> _nt.Array[bool_]: ...
@overload
def __ge__(self: _nt.Array[object_], other: object, /) -> _nt.Array[bool_]: ...
@overload
def __ge__(self, other: _ArrayLikeObject_co, /) -> _nt.Array[bool_]: ...
def __ge__(self, other: _nt.ToObject_nd, /) -> _nt.Array[bool_]: ...

#
def __abs__(
Expand Down Expand Up @@ -5045,7 +5034,7 @@ class void(flexible[bytes | tuple[Any, ...]]): # type: ignore[misc] # pyright:
def dtype(self) -> dtypes.VoidDType: ...

class datetime64(
_RealMixin, _CmpOpMixin[datetime64, _ArrayLikeDT64_co], generic[_DT64ItemT_co], Generic[_DT64ItemT_co]
_RealMixin, _CmpOpMixin[datetime64, _nt.CoDateTime_nd], generic[_DT64ItemT_co], Generic[_DT64ItemT_co]
):
@classmethod
def __class_getitem__(cls, type_arg: type | object, /) -> GenericAlias: ...
Expand Down
16 changes: 7 additions & 9 deletions src/numpy-stubs/_core/_multiarray_umath.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ from numpy import _AnyShapeT, _CanSeekTellFileNo, _CastingKind, _ModeKind, _Orde
from numpy._globals import _CopyMode
from numpy._typing import (
_ArrayLike,
_ArrayLikeAnyString_co,
_ArrayLikeNumber_co,
_DTypeLike,
_ScalarLike_co,
_SupportsArrayFunc as _CanArrayFunc,
Expand Down Expand Up @@ -1673,13 +1671,13 @@ def dot(a: npt.ArrayLike, b: npt.ArrayLike, out: _ArrayT) -> _ArrayT: ...

#
@overload
def vdot(a: _ArrayLike[_NumericT], b: _ArrayLike[_NumericT], /) -> _NumericT: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
def vdot(a: _ArrayLike[_NumericT], b: _ArrayLike[_NumericT], /) -> _NumericT: ... # type: ignore[overload-overlap]
@overload
def vdot(a: _nt.CoInteger_nd, b: _nt.CoInteger_nd, /) -> np.signedinteger: ...
@overload
def vdot(a: _nt.CoFloating_nd, b: _nt.CoFloating_nd, /) -> np.floating | np.signedinteger: ...
@overload
def vdot(a: _ArrayLikeNumber_co, b: _ArrayLikeNumber_co, /) -> np.inexact | np.signedinteger: ...
def vdot(a: _nt.CoComplex_nd, b: _nt.CoComplex_nd, /) -> np.inexact | np.signedinteger: ...

#
@overload
Expand Down Expand Up @@ -1728,31 +1726,31 @@ def interp(
def interp_complex(
x: _ToFloat,
xp: _nt.CoFloating_nd,
fp: _ArrayLikeNumber_co,
fp: _nt.CoComplex_nd,
left: _ToComplex | None = None,
right: _ToComplex | None = None,
) -> np.complex128: ...
@overload
def interp_complex(
x: _nt.Array[np.floating | np.integer, _ShapeT],
xp: _nt.CoFloating_nd,
fp: _ArrayLikeNumber_co,
fp: _nt.CoComplex_nd,
left: _ToComplex | None = None,
right: _ToComplex | None = None,
) -> _nt.Array[np.complex128, _ShapeT]: ...
@overload
def interp_complex(
x: _nt.Sequence1ND[_ToFloat],
xp: _nt.CoFloating_nd,
fp: _ArrayLikeNumber_co,
fp: _nt.CoComplex_nd,
left: _ToComplex | None = None,
right: _ToComplex | None = None,
) -> _nt.Array[np.complex128]: ...
@overload
def interp_complex(
x: _nt.CoFloating_nd,
xp: _nt.CoFloating_nd,
fp: _ArrayLikeNumber_co,
fp: _nt.CoComplex_nd,
left: _ToComplex | None = None,
right: _ToComplex | None = None,
) -> np.complex128 | _nt.Array[np.complex128]: ...
Expand Down Expand Up @@ -2021,4 +2019,4 @@ def _make_extobj() -> CapsuleType: ...
def _monotonicity(x: _nt.CoFloating_nd) -> L[0, 1]: ...
def _place(input: npt.ArrayLike, mask: _nt.ToBool_nd, vals: npt.ArrayLike) -> None: ...
def _reconstruct(subtype: type[_nt.Array], shape: _AnyShapeT, dtype: _DTypeT) -> np.ndarray[_AnyShapeT, _DTypeT]: ...
def _vec_string(a: _ArrayLikeAnyString_co, dtype: npt.DTypeLike | None, attr: str, /) -> _nt.Array[Incomplete]: ...
def _vec_string(a: _nt.ToCharacter_nd, dtype: npt.DTypeLike | None, attr: str, /) -> _nt.Array[Incomplete]: ...
52 changes: 22 additions & 30 deletions src/numpy-stubs/_core/einsumfunc.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,6 @@ from typing_extensions import TypeVar

import _numtype as _nt
from numpy import _OrderKACF # noqa: ICN003
from numpy._typing import (
_ArrayLikeBool_co,
_ArrayLikeComplex_co,
_ArrayLikeFloat_co,
_ArrayLikeInt_co,
_ArrayLikeObject_co,
_ArrayLikeUInt_co,
)

__all__ = ["einsum", "einsum_path"]

Expand All @@ -39,9 +31,9 @@ _ToDTypeComplex_co: TypeAlias = _nt.ToDTypeBool | _ToDTypeUInt | _ToDTypeInt | _
# Something like `is_scalar = bool(__subscripts.partition("->")[-1])`
@overload
def einsum(
subscripts: str | _ArrayLikeInt_co,
subscripts: str | _nt.CoInteger_nd,
/,
*operands: _ArrayLikeBool_co,
*operands: _nt.ToBool_nd,
out: None = None,
optimize: _OptimizeKind = False,
dtype: _nt.ToDTypeBool | None = None,
Expand All @@ -50,9 +42,9 @@ def einsum(
) -> Incomplete: ...
@overload
def einsum(
subscripts: str | _ArrayLikeInt_co,
subscripts: str | _nt.CoInteger_nd,
/,
*operands: _ArrayLikeUInt_co,
*operands: _nt.CoUInt64_nd,
out: None = None,
dtype: _ToDTypeUInt | None = None,
order: _OrderKACF = "K",
Expand All @@ -61,9 +53,9 @@ def einsum(
) -> Incomplete: ...
@overload
def einsum(
subscripts: str | _ArrayLikeInt_co,
subscripts: str | _nt.CoInteger_nd,
/,
*operands: _ArrayLikeInt_co,
*operands: _nt.CoInteger_nd,
out: None = None,
dtype: _ToDTypeInt | None = None,
order: _OrderKACF = "K",
Expand All @@ -72,9 +64,9 @@ def einsum(
) -> Incomplete: ...
@overload
def einsum(
subscripts: str | _ArrayLikeInt_co,
subscripts: str | _nt.CoInteger_nd,
/,
*operands: _ArrayLikeFloat_co,
*operands: _nt.CoFloating_nd,
out: None = None,
dtype: _ToDTypeFloat | None = None,
order: _OrderKACF = "K",
Expand All @@ -83,9 +75,9 @@ def einsum(
) -> Incomplete: ...
@overload
def einsum(
subscripts: str | _ArrayLikeInt_co,
subscripts: str | _nt.CoInteger_nd,
/,
*operands: _ArrayLikeComplex_co,
*operands: _nt.CoComplex_nd,
out: None = None,
dtype: _ToDTypeComplex | None = None,
order: _OrderKACF = "K",
Expand All @@ -94,7 +86,7 @@ def einsum(
) -> Incomplete: ...
@overload
def einsum(
subscripts: str | _ArrayLikeInt_co,
subscripts: str | _nt.CoInteger_nd,
/,
*operands: Any,
casting: _CastingUnsafe,
Expand All @@ -105,9 +97,9 @@ def einsum(
) -> Incomplete: ...
@overload
def einsum(
subscripts: str | _ArrayLikeInt_co,
subscripts: str | _nt.CoInteger_nd,
/,
*operands: _ArrayLikeComplex_co,
*operands: _nt.CoComplex_nd,
out: _ArrayT,
dtype: _ToDTypeComplex_co | None = None,
order: _OrderKACF = "K",
Expand All @@ -116,7 +108,7 @@ def einsum(
) -> _ArrayT: ...
@overload
def einsum(
subscripts: str | _ArrayLikeInt_co,
subscripts: str | _nt.CoInteger_nd,
/,
*operands: Any,
out: _ArrayT,
Expand All @@ -127,9 +119,9 @@ def einsum(
) -> _ArrayT: ...
@overload
def einsum(
subscripts: str | _ArrayLikeInt_co,
subscripts: str | _nt.CoInteger_nd,
/,
*operands: _ArrayLikeObject_co,
*operands: _nt.ToObject_nd,
out: None = None,
dtype: _nt.ToDTypeObject | None = None,
order: _OrderKACF = "K",
Expand All @@ -138,7 +130,7 @@ def einsum(
) -> Incomplete: ...
@overload
def einsum(
subscripts: str | _ArrayLikeInt_co,
subscripts: str | _nt.CoInteger_nd,
/,
*operands: Any,
casting: _CastingUnsafe,
Expand All @@ -149,9 +141,9 @@ def einsum(
) -> Incomplete: ...
@overload
def einsum(
subscripts: str | _ArrayLikeInt_co,
subscripts: str | _nt.CoInteger_nd,
/,
*operands: _ArrayLikeObject_co,
*operands: _nt.ToObject_nd,
out: _ArrayT,
dtype: _nt.ToDTypeObject | None = None,
order: _OrderKACF = "K",
Expand All @@ -160,7 +152,7 @@ def einsum(
) -> _ArrayT: ...
@overload
def einsum(
subscripts: str | _ArrayLikeInt_co,
subscripts: str | _nt.CoInteger_nd,
/,
*operands: Any,
out: _ArrayT,
Expand All @@ -174,9 +166,9 @@ def einsum(
# NOTE: `einsum_call` is a hidden kwarg unavailable for public use.
# It is therefore excluded from the signatures below.
def einsum_path(
subscripts: str | _ArrayLikeInt_co,
subscripts: str | _nt.CoInteger_nd,
/,
*operands: _ArrayLikeComplex_co | _nt.ToDTypeObject,
*operands: _nt.CoComplex_nd | _nt.ToDTypeObject,
optimize: _OptimizeKind = "greedy",
einsum_call: L[False] = False,
) -> tuple[list[str | tuple[int, ...]], str]: ...
6 changes: 3 additions & 3 deletions src/numpy-stubs/_core/records.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ from typing_extensions import Buffer, TypeVar, override
import _numtype as _nt
import numpy as np
from numpy import _ByteOrder, _OrderKACF # noqa: ICN003
from numpy._typing import ArrayLike, DTypeLike, _ArrayLikeVoid_co
from numpy._typing import ArrayLike, DTypeLike

__all__ = [
"array",
Expand Down Expand Up @@ -145,7 +145,7 @@ def fromarrays(
# exported in `numpy.rec`
@overload
def fromrecords(
recList: _ArrayLikeVoid_co | _nt.SequenceND[tuple[Incomplete, ...]],
recList: _nt.ToGeneric_nd | _nt.SequenceND[tuple[Incomplete, ...]],
dtype: DTypeLike | None = None,
shape: _nt.ToShape | None = None,
formats: None = None,
Expand All @@ -156,7 +156,7 @@ def fromrecords(
) -> _RecArray[record]: ...
@overload
def fromrecords(
recList: _ArrayLikeVoid_co | _nt.SequenceND[tuple[Incomplete, ...]],
recList: _nt.ToGeneric_nd | _nt.SequenceND[tuple[Incomplete, ...]],
dtype: None = None,
shape: _nt.ToShape | None = None,
*,
Expand Down
4 changes: 3 additions & 1 deletion src/numpy-stubs/_core/strings.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ from typing import TypeAlias, overload
import _numtype as _nt
import numpy as np
from numpy._globals import _NoValueType
from numpy._typing import _ArrayLikeAnyString_co as ToAnyStringND, _ArrayLikeInt_co as ToIntND

from .umath import (
add,
Expand All @@ -25,6 +24,9 @@ from .umath import (
str_len,
)

ToAnyStringND = _nt.ToCharacter_nd
ToIntND = _nt.CoInteger_nd

__all__ = [
"add",
"capitalize",
Expand Down
Loading
Loading