Skip to content
Merged
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
8 changes: 7 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,16 @@ jobs:
src/numpy-stubs/_core/__init__.pyi
src/numpy-stubs/_core/_asarray.pyi
src/numpy-stubs/_core/_internal.pyi
src/numpy-stubs/_core/_multiarray_umath.pyi
src/numpy-stubs/_core/_type_aliases.pyi
src/numpy-stubs/_core/_ufunc_config.pyi
src/numpy-stubs/_core/arrayprint.pyi
src/numpy-stubs/_core/multiarray.pyi
src/numpy-stubs/_core/numerictypes.pyi
src/numpy-stubs/_core/records.pyi
src/numpy-stubs/_core/shape_base.pyi
src/numpy-stubs/_core/strings.pyi
src/numpy-stubs/_core/umath.pyi
src/numpy-stubs/_typing
src/numpy-stubs/char
src/numpy-stubs/core
Expand Down Expand Up @@ -97,17 +100,20 @@ jobs:

- name: mypy (numpy-stubs)
run: >
uv run --no-editable mypy
uv run test/mypy.py
src/numpy-stubs/_core/__init__.pyi
src/numpy-stubs/_core/_asarray.pyi
src/numpy-stubs/_core/_internal.pyi
src/numpy-stubs/_core/_multiarray_umath.pyi
src/numpy-stubs/_core/_type_aliases.pyi
src/numpy-stubs/_core/_ufunc_config.pyi
src/numpy-stubs/_core/arrayprint.pyi
src/numpy-stubs/_core/multiarray.pyi
src/numpy-stubs/_core/numerictypes.pyi
src/numpy-stubs/_core/records.pyi
src/numpy-stubs/_core/shape_base.pyi
src/numpy-stubs/_core/strings.pyi
src/numpy-stubs/_core/umath.pyi
src/numpy-stubs/_typing
src/numpy-stubs/char
src/numpy-stubs/core
Expand Down
210 changes: 169 additions & 41 deletions src/numpy-stubs/_core/_multiarray_umath.pyi
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import _contextvars
import datetime as dt
from _typeshed import Incomplete, StrOrBytesPath, SupportsLenAndGetItem
from builtins import bool as py_bool
Expand All @@ -18,11 +19,112 @@ from typing import (
overload,
type_check_only,
)
from typing_extensions import CapsuleType, Self, TypeAliasType, TypeVar, Unpack
from typing_extensions import CapsuleType, Self, TypeAliasType, TypeVar, Unpack, deprecated

import numpy as np
import numpy.typing as npt
from numpy import _AnyShapeT, _CastingKind, _ModeKind, _OrderCF, _OrderKACF, _SupportsBuffer, _SupportsFileMethods # noqa: ICN003
from numpy import ( # noqa: ICN003
_AnyShapeT,
_CastingKind,
_ModeKind,
_OrderCF,
_OrderKACF,
_SupportsBuffer,
_SupportsFileMethods,
# NOTE: These implicitly re-exported ufuncs are defined in this ext-module at runtime
absolute as absolute,
add as add,
arccos as arccos,
arccosh as arccosh,
arcsin as arcsin,
arcsinh as arcsinh,
arctan as arctan,
arctan2 as arctan2,
arctanh as arctanh,
bitwise_and as bitwise_and,
bitwise_count as bitwise_count,
bitwise_or as bitwise_or,
bitwise_xor as bitwise_xor,
cbrt as cbrt,
ceil as ceil,
conj as conj,
conjugate as conjugate,
copysign as copysign,
cos as cos,
cosh as cosh,
deg2rad as deg2rad,
degrees as degrees,
divide as divide,
divmod as divmod,
equal as equal,
exp as exp,
exp2 as exp2,
expm1 as expm1,
fabs as fabs,
float_power as float_power,
floor as floor,
floor_divide as floor_divide,
fmax as fmax,
fmin as fmin,
fmod as fmod,
frexp as frexp,
gcd as gcd,
greater as greater,
greater_equal as greater_equal,
heaviside as heaviside,
hypot as hypot,
invert as invert,
isfinite as isfinite,
isinf as isinf,
isnan as isnan,
isnat as isnat,
lcm as lcm,
ldexp as ldexp,
left_shift as left_shift,
less as less,
less_equal as less_equal,
log as log,
log1p as log1p,
log2 as log2,
log10 as log10,
logaddexp as logaddexp,
logaddexp2 as logaddexp2,
logical_and as logical_and,
logical_not as logical_not,
logical_or as logical_or,
logical_xor as logical_xor,
matvec as matvec,
maximum as maximum,
minimum as minimum,
mod as mod,
modf as modf,
multiply as multiply,
negative as negative,
nextafter as nextafter,
not_equal as not_equal,
positive as positive,
power as power,
rad2deg as rad2deg,
radians as radians,
reciprocal as reciprocal,
remainder as remainder,
right_shift as right_shift,
rint as rint,
sign as sign,
signbit as signbit,
sin as sin,
sinh as sinh,
spacing as spacing,
sqrt as sqrt,
square as square,
subtract as subtract,
tan as tan,
tanh as tanh,
true_divide as true_divide,
trunc as trunc,
vecdot as vecdot,
vecmat as vecmat,
)
from numpy._globals import _CopyMode
from numpy._typing import (
_ArrayLike,
Expand Down Expand Up @@ -137,7 +239,9 @@ _Roll = TypeAliasType(
_TimeUnit: TypeAlias = L["Y", "M", "D", "h", "m", "s", "ms", "us", "μs", "ns", "ps", "fs", "as"]
_TimeZone: TypeAlias = L["naive", "UTC", "local"] | dt.tzinfo
_CorrMode: TypeAlias = L[0, "valid", 1, "same", 2, "full"]
_ExtObjValue: TypeAlias = L["ignore", "warn", "raise", "call", "print", "log"]

_Ignored: TypeAlias = object
_Copy: TypeAlias = py_bool | L[2] | _CopyMode
_WeekMask: TypeAlias = str | Sequence[L[0, 1] | py_bool | np.bool]

Expand Down Expand Up @@ -180,6 +284,10 @@ class _CanArray(Protocol[_ArrayT_co]):
class _CanDLPack(Protocol[_T_contra]):
def __dlpack__(self, /, *, stream: _T_contra | None = None) -> CapsuleType: ...

@type_check_only
class _CanWriteErr(Protocol):
def write(self, err: str, flag: int, /) -> _Ignored: ...

@type_check_only
class _HasDoc(Protocol):
__doc__: str | None
Expand Down Expand Up @@ -218,6 +326,15 @@ class _KwargsDCL(TypedDict, total=False):
copy: _Copy | None
like: _SupportsArrayFunc | None

@type_check_only
class _ExtObjDict(TypedDict):
divide: _ExtObjValue
over: _ExtObjValue
under: _ExtObjValue
invalid: _ExtObjValue
call: Callable[[str, int], _Ignored] | _CanWriteErr | None
bufsize: int

###

__version__: Final[str] = ...
Expand Down Expand Up @@ -267,20 +384,39 @@ NAN: Final[float] = ...
error: Final = Exception

tracemalloc_domain: Final[int] = ...
_extobj_contextvar: _contextvars.ContextVar[CapsuleType]

__cpu_baseline__: Final[list[str]] = ...
__cpu_dispatch__: Final[list[str]] = ...
__cpu_features__: Final[dict[str, bool]] = ...
__cpu_targets_info__: Final[dict[str, dict[str, dict[str, str]]]] = ...

_flagdict: Final[dict[str, int]] = ...
typeinfo: Final[dict[str, np.dtype[Any]]] = ...
_flagdict: Final[dict[str, int]] = ...

e: Final[float] = ...
euler_gamma: Final[float] = ...
pi: Final[float] = ...

#
clip: np.ufunc
count: np.ufunc
endswith: np.ufunc
find: np.ufunc
index: np.ufunc
isalnum: np.ufunc
isalpha: np.ufunc
isdecimal: np.ufunc
isdigit: np.ufunc
islower: np.ufunc
isnumeric: np.ufunc
isspace: np.ufunc
istitle: np.ufunc
isupper: np.ufunc
rfind: np.ufunc
rindex: np.ufunc
startswith: np.ufunc
str_len: np.ufunc

_arg: np.ufunc
_center: np.ufunc
_expandtabs: np.ufunc
Expand All @@ -300,25 +436,6 @@ _rstrip_whitespace: np.ufunc
_strip_chars: np.ufunc
_strip_whitespace: np.ufunc
_zfill: np.ufunc
#
clip: np.ufunc
count: np.ufunc
endswith: np.ufunc
find: np.ufunc
index: np.ufunc
isalnum: np.ufunc
isalpha: np.ufunc
isdecimal: np.ufunc
isdigit: np.ufunc
islower: np.ufunc
isnumeric: np.ufunc
isspace: np.ufunc
istitle: np.ufunc
isupper: np.ufunc
rfind: np.ufunc
rindex: np.ufunc
startswith: np.ufunc
str_len: np.ufunc

@final
class flagsobj:
Expand Down Expand Up @@ -1596,7 +1713,6 @@ def c_einsum(

###

#
@overload
def scalar(dtype: np.dtype[np.object_], obj: object) -> Any: ...
@overload
Expand All @@ -1606,7 +1722,8 @@ def scalar(dtype: np.dtype[_SafeScalarT]) -> _SafeScalarT: ...
@overload
def scalar(dtype: np.dtype[_SafeScalarT], obj: bytes) -> _SafeScalarT: ...

#
###

@overload
def compare_chararrays(
a1: _ArrayLikeStr_co,
Expand All @@ -1622,29 +1739,20 @@ def compare_chararrays(
rstrip: bool,
) -> _Array[np.bool]: ...

#
###

def add_docstring(obj: Callable[..., object] | _HasDoc, docstring: str, /) -> None: ...

#
@deprecated("_add_newdoc_ufunc is deprecated. Use `ufunc.__doc__ = newdoc` instead.")
def _add_newdoc_ufunc(ufunc: np.ufunc, new_docstring: str, /) -> None: ...

###

def dragon4_positional(*args: Incomplete, **kwargs: Incomplete) -> Incomplete: ...
def dragon4_scientific(*args: Incomplete, **kwargs: Incomplete) -> Incomplete: ...
def format_longfloat(*args: Incomplete, **kwargs: Incomplete) -> Incomplete: ...

#
def _get_madvise_hugepage() -> bool: ...
def _set_madvise_hugepage(enabled: bool, /) -> bool: ...
def _get_ndarray_c_version() -> int: ...

#
def _monotonicity(x: _ArrayLikeFloat_co) -> L[0, 1]: ...
def _place(input: npt.ArrayLike, mask: _ArrayLikeBool_co, vals: npt.ArrayLike) -> None: ...
def _reconstruct(
subtype: type[_Array],
shape: _AnyShapeT,
dtype: _DTypeT,
) -> np.ndarray[_AnyShapeT, _DTypeT]: ...
def _vec_string(a: _ArrayLikeAnyString_co, dtype: npt.DTypeLike, attr: str, /) -> _Array: ...

###

# NOTE: We can't use e.g. `Concatenate[Any, ...]`, as that causes mypy to reject every function...
Expand Down Expand Up @@ -1684,3 +1792,23 @@ def frompyfunc(
def frompyfunc(f: Callable[..., Any], /, nin: SupportsIndex, nout: SupportsIndex, *, identity: object = None) -> np.ufunc: ...

###

#
def _get_madvise_hugepage() -> bool: ...
def _set_madvise_hugepage(enabled: bool, /) -> bool: ...
def _get_ndarray_c_version() -> int: ...

#

def _get_extobj_dict() -> _ExtObjDict: ...
def _make_extobj() -> CapsuleType: ...

#
def _monotonicity(x: _ArrayLikeFloat_co) -> L[0, 1]: ...
def _place(input: npt.ArrayLike, mask: _ArrayLikeBool_co, vals: npt.ArrayLike) -> None: ...
def _reconstruct(
subtype: type[_Array],
shape: _AnyShapeT,
dtype: _DTypeT,
) -> np.ndarray[_AnyShapeT, _DTypeT]: ...
def _vec_string(a: _ArrayLikeAnyString_co, dtype: npt.DTypeLike, attr: str, /) -> _Array: ...
Loading
Loading