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
3 changes: 3 additions & 0 deletions .mypyignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ numpy\._core\.numeric\.__all__
numpy\._core\.numerictypes\.__all__
numpy\.matlib\.__all__

# requires numpy/_core/code_generators to be on the PYTHONPATH when running stubtest
numpy\._core\.cversions

# workaround mypy's lack of Python 3.13 support for `NamedTuple` types (mypy <= 1.15.0)
numpy\._core\.overrides\.ArgSpec\.__replace__
numpy\._utils\._pep440\._Version\.__replace__
Expand Down
6 changes: 1 addition & 5 deletions .mypyignore-todo
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,11 @@ numpy(\..+)?\.complexfloating.__complex__
numpy(\.lib\._nanfunctions_impl|\.matlib)?\.nan(median|percentile)
numpy(\.lib\._twodim_base_impl)?\.tri(l|u)

numpy\._core(\._multiarray_umath|\.multiarray)\.error
numpy(\._core(\.memmap)?|\.matlib)?\.memmap\.__new__
numpy(\.matrixlib(\.defmatrix)?|\.matlib)?\.matrix\.__new__
numpy(\.lib\._polynomial_impl|\.matlib)?\.poly1d\.integ

numpy._core.cversions
numpy._core.printoptions

numpy\._core(\._multiarray_umath|\.multiarray)\.error

numpy._core._type_aliases.is_complex
numpy._core._type_aliases.full_name
numpy._core._type_aliases.abstract_type
Expand Down
3 changes: 3 additions & 0 deletions src/numpy-stubs/_core/_add_newdocs.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from numpy._core.overrides import get_array_function_like_doc as get_array_function_like_doc

def refer_to_array_attribute(attr: str, method: bool = True) -> tuple[str, str]: ...
16 changes: 16 additions & 0 deletions src/numpy-stubs/_core/_add_newdocs_scalars.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from collections.abc import Iterable
from typing import Final

import numpy as np

possible_aliases: Final[list[tuple[type[np.number], str, str]]] = ...
_system: Final[str] = ...
_machine: Final[str] = ...
_doc_alias_string: Final[str] = ...
_bool_docstring: Final[str] = ...
int_name: str = ...
float_name: str = ...

def numeric_type_aliases(aliases: list[tuple[str, str]]) -> list[tuple[type[np.number], str, str]]: ...
def add_newdoc_for_scalar_type(obj: str, fixed_aliases: Iterable[str], doc: str) -> None: ...
def _get_platform_and_machine() -> tuple[str, str]: ...
72 changes: 72 additions & 0 deletions src/numpy-stubs/_core/_exceptions.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
from collections.abc import Iterable
from typing import Any, Final, overload
from typing_extensions import TypeVar, Unpack

import numpy as np
from numpy import _CastingKind # noqa: ICN003
from numpy._utils import set_module as set_module

###

_T = TypeVar("_T")
_TupleT = TypeVar("_TupleT", bound=tuple[()] | tuple[Any, Any, Unpack[tuple[Any, ...]]])
_ExceptionT = TypeVar("_ExceptionT", bound=Exception)

###

class UFuncTypeError(TypeError):
ufunc: Final[np.ufunc]
def __init__(self, /, ufunc: np.ufunc) -> None: ...

class _UFuncNoLoopError(UFuncTypeError):
dtypes: tuple[np.dtype[Any], ...]
def __init__(self, /, ufunc: np.ufunc, dtypes: Iterable[np.dtype[Any]]) -> None: ...

class _UFuncBinaryResolutionError(_UFuncNoLoopError):
dtypes: tuple[np.dtype[Any], np.dtype[Any]]
def __init__(self, /, ufunc: np.ufunc, dtypes: Iterable[np.dtype[Any]]) -> None: ...

class _UFuncCastingError(UFuncTypeError):
casting: Final[_CastingKind]
from_: Final[np.dtype[Any]]
to: Final[np.dtype[Any]]
def __init__(self, /, ufunc: np.ufunc, casting: _CastingKind, from_: np.dtype[Any], to: np.dtype[Any]) -> None: ...

class _UFuncInputCastingError(_UFuncCastingError):
in_i: Final[int]
def __init__(
self,
/,
ufunc: np.ufunc,
casting: _CastingKind,
from_: np.dtype[Any],
to: np.dtype[Any],
i: int,
) -> None: ...

class _UFuncOutputCastingError(_UFuncCastingError):
out_i: Final[int]
def __init__(
self,
/,
ufunc: np.ufunc,
casting: _CastingKind,
from_: np.dtype[Any],
to: np.dtype[Any],
i: int,
) -> None: ...

class _ArrayMemoryError(MemoryError):
shape: tuple[int, ...]
dtype: np.dtype[Any]
def __init__(self, /, shape: tuple[int, ...], dtype: np.dtype[Any]) -> None: ...
@property
def _total_size(self) -> int: ...
@staticmethod
def _size_to_string(num_bytes: int) -> str: ...

@overload
def _unpack_tuple(tup: tuple[_T]) -> _T: ...
@overload
def _unpack_tuple(tup: _TupleT) -> _TupleT: ...
def _display_as_base(cls: type[_ExceptionT]) -> type[_ExceptionT]: ...
38 changes: 38 additions & 0 deletions src/numpy-stubs/_core/_machar.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from collections.abc import Callable
from typing_extensions import deprecated

__all__ = ["MachAr"]

@deprecated("deprecated in numpy 1.22")
class MachAr:
ibeta: int
it: int
machep: int
eps: float
negep: int
epsneg: float
iexp: int
minexp: int
xmin: float
maxexp: int
xmax: float
irnd: int
ngrd: int
epsilon: float
tiny: float
huge: float
precision: float
resolution: float
smallest_normal: float
smallest_subnormal: float
title: str | None

def __init__(
self,
/,
float_conv: Callable[[int], float] = ...,
int_conv: Callable[[float], int] = ...,
float_to_float: Callable[[float], float] = ...,
float_to_str: Callable[[float], str] = ...,
title: str = "Python floating point number",
) -> None: ...
14 changes: 14 additions & 0 deletions src/numpy-stubs/_core/_methods.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import numpy as np
from numpy._typing._ufunc import _Reduce2

from . import _exceptions as _exceptions, umath as um

bool_dt: np.dtype[np.bool] = ...
umr_maximum: _Reduce2 = ...
umr_minimum: _Reduce2 = ...
umr_sum: _Reduce2 = ...
umr_prod: _Reduce2 = ...
umr_bitwise_count = um.bitwise_count
umr_any: _Reduce2 = ...
umr_all: _Reduce2 = ...
_complex_to_float: dict[np.dtype[np.complexfloating], np.dtype[np.floating]] = ...
14 changes: 14 additions & 0 deletions src/numpy-stubs/_core/_simd.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from types import ModuleType

SSE42: ModuleType | None = ...
AVX2: ModuleType | None = ...
FMA3: ModuleType | None = ...
AVX512F: ModuleType | None = ...
AVX512_SKX: ModuleType | None = ...
baseline: ModuleType | None = ...

# TODO(jorenham): TypedDict
targets: dict[str, ModuleType | None] = ...

def clear_floatstatus() -> None: ...
def get_floatstatus() -> int: ...
12 changes: 12 additions & 0 deletions src/numpy-stubs/_core/_string_helpers.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from typing import Final

_all_chars: Final[tuple[str, ...]] = ...
_ascii_upper: Final[tuple[str, ...]] = ...
_ascii_lower: Final[tuple[str, ...]] = ...

LOWER_TABLE: Final[tuple[str, ...]] = ...
UPPER_TABLE: Final[tuple[str, ...]] = ...

def english_lower(s: str) -> str: ...
def english_upper(s: str) -> str: ...
def english_capitalize(s: str) -> str: ...
28 changes: 28 additions & 0 deletions src/numpy-stubs/_core/printoptions.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from collections.abc import Callable
from contextvars import ContextVar
from typing import Any, Final, TypedDict

from .arrayprint import _FormatDict

__all__ = ["format_options"]

###

class _FormatOptionsDict(TypedDict):
edgeitems: int
threshold: int
floatmode: str
precision: int
suppress: bool
linewidth: int
nanstr: str
infstr: str
sign: str
formatter: _FormatDict | None
legacy: int
override_repr: Callable[[Any], str] | None

###

default_format_options_dict: Final[_FormatOptionsDict] = ...
format_options: ContextVar[_FormatOptionsDict]