Skip to content

🐛 fix import-related mypy errors #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 27, 2025
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
377 changes: 192 additions & 185 deletions src/numpy-stubs/__init__.pyi

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions src/numpy-stubs/_typing/_array_like.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import sys
from collections.abc import Callable, Collection, Sequence
from typing import Any, Never as _UnknownType, Protocol, TypeAlias, runtime_checkable
from typing_extensions import TypeVar
from typing import Any, Protocol, TypeAlias, runtime_checkable
from typing_extensions import Never, TypeVar

import numpy as np
from numpy.dtypes import StringDType
Expand All @@ -23,6 +23,7 @@ _DType = TypeVar("_DType", bound=np.dtype[Any])
_DType_co = TypeVar("_DType_co", covariant=True, bound=np.dtype[Any])

NDArray: TypeAlias = np.ndarray[_Shape, np.dtype[_ScalarType_co]]
_UnknownType: TypeAlias = Never

# The `_SupportsArray` protocol only cares about the default dtype
# (i.e. `dtype=None` or no `dtype` parameter at all) of the to-be returned
Expand Down
2 changes: 1 addition & 1 deletion src/numpy-stubs/_typing/_callable.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class _IntTrueDiv(Protocol[_NBit1]):
@overload
def __call__(self, other: float, /) -> np.floating[_NBit1] | np.float64: ...
@overload
def __call__(self, other: complex, /) -> np.complexnp.floating[_NBit1] | np.complex128: ...
def __call__(self, other: complex, /) -> np.complexfloating[_NBit1] | np.complex128: ...
@overload
def __call__(self, other: np.integer[_NBit2], /) -> np.floating[_NBit1] | np.floating[_NBit2]: ...

Expand Down
38 changes: 0 additions & 38 deletions src/numpy-stubs/lib/_format_impl.pyi

This file was deleted.

2 changes: 1 addition & 1 deletion src/numpy-stubs/lib/_function_base_impl.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ def interp(
def interp(
x: _FloatLike_co,
xp: _ArrayLikeFloat_co,
fp: Sequence[complex | np.ccomplexfloating],
fp: Sequence[complex | np.complexfloating],
left: _NumberLike_co | None = None,
right: _NumberLike_co | None = None,
period: _FloatLike_co | None = None,
Expand Down
36 changes: 14 additions & 22 deletions src/numpy-stubs/lib/_nanfunctions_impl.pyi
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
from numpy._core.fromnumeric import amax, amin, argmax, argmin, cumprod, cumsum, mean, prod, std, sum, var
from numpy.lib._function_base_impl import (
median,
percentile,
quantile,
# NOTE: In reality these functions are not aliases but distinct functions with identical signatures.
from numpy._core.fromnumeric import (
amax as nanmax,
amin as nanmin,
argmax as nanargmax,
argmin as nanargmin,
cumprod as nancumprod,
cumsum as nancumsum,
mean as nanmean,
prod as nanprod,
std as nanstd,
sum as nansum,
var as nanvar,
)
from numpy.lib._function_base_impl import median as nanmedian, percentile as nanpercentile, quantile as nanquantile

__all__ = [
"nanargmax",
Expand All @@ -21,20 +30,3 @@ __all__ = [
"nansum",
"nanvar",
]

# NOTE: In reality these functions are not aliases but distinct functions
# with identical signatures.
nanmin = amin
nanmax = amax
nanargmin = argmin
nanargmax = argmax
nansum = sum
nanprod = prod
nancumsum = cumsum
nancumprod = cumprod
nanmean = mean
nanvar = var
nanstd = std
nanmedian = median
nanpercentile = percentile
nanquantile = quantile
2 changes: 1 addition & 1 deletion src/numpy-stubs/lib/_polynomial_impl.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ from numpy._typing import (
_T = TypeVar("_T")

_2Tup: TypeAlias = tuple[_T, _T]
_5Tup: TypeAlias = tuple[_T, NDArray[np.np.float64], NDArray[np.int32], NDArray[np.float64], NDArray[np.float64]]
_5Tup: TypeAlias = tuple[_T, NDArray[np.float64], NDArray[np.int32], NDArray[np.float64], NDArray[np.float64]]

__all__ = ["poly", "poly1d", "polyadd", "polyder", "polydiv", "polyfit", "polyint", "polymul", "polysub", "polyval", "roots"]

Expand Down
6 changes: 3 additions & 3 deletions src/numpy-stubs/lib/_twodim_base_impl.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,9 @@ def vander(x: _ArrayLikeComplex_co, N: int | None = ..., increasing: bool = ...)
@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.np.number | np.bool
_Int_co: TypeAlias = np.integer | np.bool
_Float_co: TypeAlias = np.floating | _Int_co
_Number_co: TypeAlias = np.number | np.bool

_ArrayLike1D: TypeAlias = _SupportsArray[np.dtype[_SCT]] | Sequence[_SCT]
_ArrayLike2D: TypeAlias = _SupportsArray[np.dtype[_SCT]] | Sequence[_ArrayLike1D[_SCT]]
Expand Down
63 changes: 39 additions & 24 deletions src/numpy-stubs/lib/format.pyi
Original file line number Diff line number Diff line change
@@ -1,24 +1,39 @@
from ._format_impl import (
ARRAY_ALIGN as ARRAY_ALIGN,
BUFFER_SIZE as BUFFER_SIZE,
EXPECTED_KEYS as EXPECTED_KEYS,
GROWTH_AXIS_MAX_DIGITS as GROWTH_AXIS_MAX_DIGITS,
MAGIC_LEN as MAGIC_LEN,
MAGIC_PREFIX as MAGIC_PREFIX,
__all__ as __all__,
__doc__ as __doc__,
descr_to_dtype as descr_to_dtype,
drop_metadata as drop_metadata,
dtype_to_descr as dtype_to_descr,
header_data_from_array_1_0 as header_data_from_array_1_0,
isfileobj as isfileobj,
magic as magic,
open_memmap as open_memmap,
read_array as read_array,
read_array_header_1_0 as read_array_header_1_0,
read_array_header_2_0 as read_array_header_2_0,
read_magic as read_magic,
write_array as write_array,
write_array_header_1_0 as write_array_header_1_0,
write_array_header_2_0 as write_array_header_2_0,
)
from _typeshed import Incomplete
from typing import Final, Literal

__all__: list[str] = []

EXPECTED_KEYS: Final[set[str]]
MAGIC_PREFIX: Final[bytes]
MAGIC_LEN: Literal[8]
ARRAY_ALIGN: Literal[64]
BUFFER_SIZE: Literal[262144] # 2**18
GROWTH_AXIS_MAX_DIGITS: Literal[21]

def magic(major: Incomplete, minor: Incomplete) -> Incomplete: ...
def read_magic(fp: Incomplete) -> Incomplete: ...
def dtype_to_descr(dtype: Incomplete) -> Incomplete: ...
def descr_to_dtype(descr: Incomplete) -> Incomplete: ...
def header_data_from_array_1_0(array: Incomplete) -> Incomplete: ...
def write_array_header_1_0(fp: Incomplete, d: Incomplete) -> Incomplete: ...
def write_array_header_2_0(fp: Incomplete, d: Incomplete) -> Incomplete: ...
def read_array_header_1_0(fp: Incomplete) -> Incomplete: ...
def read_array_header_2_0(fp: Incomplete) -> Incomplete: ...
def write_array(
fp: Incomplete,
array: Incomplete,
version: Incomplete = ...,
allow_pickle: Incomplete = ...,
pickle_kwargs: Incomplete = ...,
) -> Incomplete: ...
def read_array(fp: Incomplete, allow_pickle: Incomplete = ..., pickle_kwargs: Incomplete = ...) -> Incomplete: ...
def open_memmap(
filename: Incomplete,
mode: Incomplete = ...,
dtype: Incomplete = ...,
shape: Incomplete = ...,
fortran_order: Incomplete = ...,
version: Incomplete = ...,
) -> Incomplete: ...
def isfileobj(f: Incomplete) -> Incomplete: ...
def drop_metadata(dtype: Incomplete, /) -> Incomplete: ...
Loading