8000 TYP: Backport typing fixes from main (4) by charris · Pull Request #28542 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

TYP: Backport typing fixes from main (4) #28542

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 7 commits into from
Mar 16, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
TYP: fix stubtest error in numpy.ma (#28541)
Ported from numpy/numtype#280
  • Loading branch information
jorenham authored and charris committed Mar 16, 2025
commit 18795c221083c69bd4950e570c8b849f45d7ce03
84 changes: 45 additions & 39 deletions numpy/ma/core.pyi
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
from collections.abc import Callable
from typing import Any, TypeVar

from numpy import (
amax,
amin,
bool_,
expand_dims,
clip,
indices,
squeeze,
angle,
ndarray,
dtype,
float64,
)
# pyright: reportIncompatibleMethodOverride=false
# ruff: noqa: ANN001, ANN002, ANN003, ANN201, ANN202 ANN204

from typing import Any, SupportsIndex, TypeVar

from _typeshed import Incomplete
from typing_extensions import deprecated

from numpy import _OrderKACF, amax, amin, bool_, dtype, expand_dims, float64, ndarray
from numpy._typing import ArrayLike, _DTypeLikeBool

__all__ = [
"MAError",
Expand Down Expand Up @@ -111,8 +105,8 @@ __all__ = [
"less",
"less_equal",
"log",
"log10",
"log2",
"log10",
"logical_and",
"logical_not",
"logical_or",
Expand Down Expand Up @@ -257,6 +251,7 @@ cosh: _MaskedUnaryOperation
tanh: _MaskedUnaryOperation
abs: _MaskedUnaryOperation
absolute: _MaskedUnaryOperation
angle: _MaskedUnaryOperation
fabs: _MaskedUnaryOperation
negative: _MaskedUnaryOperation
floor: _MaskedUnaryOperation
Expand Down Expand Up @@ -284,20 +279,21 @@ greater_equal: _MaskedBinaryOperation
less: _MaskedBinaryOperation
greater: _MaskedBinaryOperation
logical_and: _MaskedBinaryOperation
alltrue: _MaskedBinaryOperation
def alltrue(target: ArrayLike, axis: SupportsIndex | None = 0, dtype: _DTypeLikeBool | None = None) -> Incomplete: ...
logical_or: _MaskedBinaryOperation
sometrue: Callable[..., Any]
def sometrue(target: ArrayLike, axis: SupportsIndex | None = 0, dtype: _DTypeLikeBool | None = None) -> Incomplete: ...
logical_xor: _MaskedBinaryOperation
bitwise_and: _MaskedBinaryOperation
bitwise_or: _MaskedBinaryOperation
bitwise_xor: _MaskedBinaryOperation
hypot: _MaskedBinaryOperation
divide: _MaskedBinaryOperation
true_divide: _MaskedBinaryOperation
floor_divide: _MaskedBinaryOperation
remainder: _MaskedBinaryOperation
fmod: _MaskedBinaryOperation
mod: _MaskedBinaryOperation

divide: _DomainedBinaryOperation
true_divide: _DomainedBinaryOperation
floor_divide: _DomainedBinaryOperation
remainder: _DomainedBinaryOperation
fmod: _DomainedBinaryOperation
mod: _DomainedBinaryOperation

def make_mask_descr(ndtype): ...
def getmask(a): ...
Expand Down Expand Up @@ -448,10 +444,10 @@ class MaskedArray(ndarray[_ShapeType_co, _DType_co]):
def var(self, axis=..., dtype=..., out=..., ddof=..., keepdims=...): ...
def std(self, axis=..., dtype=..., out=..., ddof=..., keepdims=...): ...
def round(self, decimals=..., out=...): ...
def argsort(self, axis=..., kind=..., order=..., endwith=..., fill_value=..., stable=...): ...
def argsort(self, axis=..., kind=..., order=..., endwith=..., fill_value=..., *, stable=...): ...
def argmin(self, axis=..., fill_value=..., out=..., *, keepdims=...): ...
def argmax(self, axis=..., fill_value=..., out=..., *, keepdims=...): ...
def sort(self, axis=..., kind=..., order=..., endwith=..., fill_value=..., stable=...): ...
def sort(self, axis=..., kind=..., order=..., endwith=..., fill_value=..., *, stable=...): ...
def min(self, axis=..., out=..., fill_value=..., keepdims=...): ...
# NOTE: deprecated
# def tostring(self, fill_value=..., order=...): ...
Expand All @@ -460,6 +456,7 @@ class MaskedArray(ndarray[_ShapeType_co, _DType_co]):
def partition(self, *args, **kwargs): ...
def argpartition(self, *args, **kwargs): ...
def take(self, indices, axis=..., out=..., mode=...): ...

copy: Any
diagonal: Any
flatten: Any
Expand All @@ -468,19 +465,26 @@ class MaskedArray(ndar 8000 ray[_ShapeType_co, _DType_co]):
swapaxes: Any
T: Any
transpose: Any

@property # type: ignore[misc]
def mT(self): ...
def tolist(self, fill_value=...): ...
def tobytes(self, fill_value=..., order=...): ...
def tofile(self, fid, sep=..., format=...): ...
def toflex(self): ...
torecords: Any

#
def toflex(self) -> Incomplete: ...
def torecords(self) -> Incomplete: ...
def tolist(self, fill_value: Incomplete | None = None) -> Incomplete: ...
@deprecated("tostring() is deprecated. Use tobytes() instead.")
def tostring(self, /, fill_value: Incomplete | None = None, order: _OrderKACF = "C") -> bytes: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
def tobytes(self, /, fill_value: Incomplete | None = None, order: _OrderKACF = "C") -> bytes: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
def tofile(self, /, fid: Incomplete, sep: str = "", format: str = "%s") -> Incomplete: ...

#
def __reduce__(self): ...
def __deepcopy__(self, memo=...): ...

class mvoid(MaskedArray[_ShapeType_co, _DType_co]):
def __new__(
self,
self, # pyright: ignore[reportSelfClsParameterName]
data,
mask=...,
dtype=...,
Expand Down Expand Up @@ -593,8 +597,8 @@ maximum: _extrema_operation

def take(a, indices, axis=..., out=..., mode=...): ...
def power(a, b, third=...): ...
def argsort(a, axis=..., kind=..., order=..., endwith=..., fill_value=..., stable=...): ...
def sort(a, axis=..., kind=..., order=..., endwith=..., fill_value=..., stable=...): ...
def argsort(a, axis=..., kind=..., order=..., endwith=..., fill_value=..., *, stable=...): ...
def sort(a, axis=..., kind=..., order=..., endwith=..., fill_value=..., *, stable=...): ...
def compressed(x): ...
def concatenate(arrays, axis=...): ...
def diag(v, k=...): ...
Expand Down Expand Up @@ -629,19 +633,21 @@ def asanyarray(a, dtype=...): ...
def fromflex(fxarray): ...

class _convert2ma:
__doc__: Any
def __init__(self, funcname, params=...): ...
def getdoc(self): ...
def __call__(self, *args, **params): ...
def __init__(self, /, funcname: str, np_ret: str, np_ma_ret: str, params: dict[str, Any] | None = None) -> None: ...
def __call__(self, /, *args: object, **params: object) -> Any: ... # noqa: ANN401
def getdoc(self, /, np_ret: str, np_ma_ret: str) -> str | None: ...

arange: _convert2ma
clip: _convert2ma
empty: _convert2ma
empty_like: _convert2ma
frombuffer: _convert2ma
fromfunction: _convert2ma
identity: _convert2ma
indices: _convert2ma
ones: _convert2ma
ones_like: _convert2ma
squeeze: _convert2ma
zeros: _convert2ma
zeros_like: _convert2ma

Expand Down
28 changes: 16 additions & 12 deletions numpy/ma/extras.pyi
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from typing import Any
from _typeshed import Incomplete

import numpy as np
from numpy.lib._function_base_impl import average
from numpy.lib._index_tricks_impl import AxisConcatenator

from .core import dot, mask_rowcols
from .core import MaskedArray, dot

__all__ = [
"apply_along_axis",
Expand All @@ -19,8 +20,8 @@ __all__ = [
"compress_nd",
"compress_rowcols",
"compress_rows",
"count_masked",
"corrcoef",
"count_masked",
"cov",
"diagflat",
"dot",
Expand All @@ -30,9 +31,9 @@ __all__ = [
"flatnotmasked_edges",
"hsplit",
"hstack",
"isin",
"in1d",
"intersect1d",
"isin",
"mask_cols",
"mask_rowcols",
"mask_rows",
Expand All @@ -48,8 +49,8 @@ __all__ = [
"setdiff1d",
"setxor1d",
"stack",
"unique",
"union1d",
"unique",
"vander",
"vstack",
]
Expand All @@ -59,9 +60,9 @@ def masked_all(shape, dtype = ...): ...
def masked_all_like(arr): ...

class _fromnxfunction:
__name__: Any
__doc__: Any
def __init__(self, funcname): ...
__name__: Incomplete
__doc__: Incomplete
def __init__(self, funcname) -> None: ...
def getdoc(self): ...
def __call__(self, *args, **params): ...

Expand Down Expand Up @@ -109,13 +110,13 @@ def cov(x, y=..., rowvar=..., bias=..., allow_masked=..., ddof=...): ...
def corrcoef(x, y=..., rowvar=..., bias = ..., allow_masked=..., ddof = ...): ...

class MAxisConcatenator(AxisConcatenator):
concatenate: Any
@staticmethod
def concatenate(arrays: Incomplete, axis: int = 0) -> Incomplete: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
@classmethod
def makemat(cls, arr): ...
def __getitem__(self, key): ...
def makemat(cls, arr: Incomplete) -> Incomplete: ... # type: ignore[override] # pyright: ignore[reportIncompatibleVariableOverride]

class mr_class(MAxisConcatenator):
def __init__(self): ...
def __init__(self) -> None: ...

mr_: mr_class

Expand All @@ -128,3 +129,6 @@ def clump_unmasked(a): ...
def clump_masked(a): ...
def vander(x, n=...): ...
def polyfit(x, y, deg, rcond=..., full=..., w=..., cov=...): ...

#
def mask_rowcols(a: Incomplete, axis: Incomplete | None = None) -> MaskedArray[Incomplete, np.dtype[Incomplete]]: ...
Loading
0