8000 TYP: fix stubtest error in ``numpy.ma`` (#28541) · numpy/numpy@18795c2 · GitHub
[go: up one dir, main page]

Skip to content

Commit 18795c2

Browse files
jorenhamcharris
authored andcommitted
TYP: fix stubtest error in numpy.ma (#28541)
Ported from numpy/numtype#280
1 parent 110bb8e commit 18795c2

File tree

2 files changed

+61
-51
lines changed

2 files changed

+61
-51
lines changed

numpy/ma/core.pyi

Lines changed: 45 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,13 @@
1-
from collections.abc import Callable
2-
from typing import Any, TypeVar
3-
4-
from numpy import (
5-
amax,
6-
amin,
7-
bool_,
8-
expand_dims,
9-
clip,
10-
indices,
11-
squeeze,
12-
angle,
13-
ndarray,
14-
dtype,
15-
float64,
16-
)
1+
# pyright: reportIncompatibleMethodOverride=false
2+
# ruff: noqa: ANN001, ANN002, ANN003, ANN201, ANN202 ANN204
3+
4+
from typing import Any, SupportsIndex, TypeVar
5+
6+
from _typeshed import Incomplete
7+
from typing_extensions import deprecated
8+
9+
from numpy import _OrderKACF, amax, amin, bool_, dtype, expand_dims, float64, ndarray
10+
from numpy._typing import ArrayLike, _DTypeLikeBool
1711

1812
__all__ = [
1913
"MAError",
@@ -111,8 +105,8 @@ __all__ = [
111105
"less",
112106
"less_equal",
113107
"log",
114-
"log10",
115108
"log2",
109+
"log10",
116110
"logical_and",
117111
"logical_not",
118112
"logical_or",
@@ -257,6 +251,7 @@ cosh: _MaskedUnaryOperation
257251
tanh: _MaskedUnaryOperation
258252
abs: _MaskedUnaryOperation
259253
absolute: _MaskedUnaryOperation
254+
angle: _MaskedUnaryOperation
260255
fabs: _MaskedUnaryOperation
261256
negative: _MaskedUnaryOperation
262257
floor: _MaskedUnaryOperation
@@ -284,20 +279,21 @@ greater_equal: _MaskedBinaryOperation
284279
less: _MaskedBinaryOperation
285280
greater: _MaskedBinaryOperation
286281
logical_and: _MaskedBinaryOperation
287-
alltrue: _MaskedBinaryOperation
282+
def alltrue(target: ArrayLike, axis: SupportsIndex | None = 0, dtype: _DTypeLikeBool | None = None) -> Incomplete: ...
288283
logical_or: _MaskedBinaryOperation
289-
sometrue: Callable[..., Any]
284+
def sometrue(target: ArrayLike, axis: SupportsIndex | None = 0, dtype: _DTypeLikeBool | None = None) -> Incomplete: ...
290285
logical_xor: _MaskedBinaryOperation
291286
bitwise_and: _MaskedBinaryOperation
292287
bitwise_or: _MaskedBinaryOperation
293288
bitwise_xor: _MaskedBinaryOperation
294289
hypot: _MaskedBinaryOperation
295-
divide: _MaskedBinaryOperation
296-
true_divide: _MaskedBinaryOperation
297-
floor_divide: _MaskedBinaryOperation
298-
remainder: _MaskedBinaryOperation
299-
fmod: _MaskedBinaryOperation
300-
mod: _MaskedBinaryOperation
290+
291+
divide: _DomainedBinaryOperation
292+
true_divide: _DomainedBinaryOperation
293+
floor_divide: _DomainedBinaryOperation
294+
remainder: _DomainedBinaryOperation
295+
fmod: _DomainedBinaryOperation
296+
mod: _DomainedBinaryOperation
301297

302298
def make_mask_descr(ndtype): ...
303299
def getmask(a): ...
@@ -448,10 +444,10 @@ class MaskedArray(ndarray[_ShapeType_co, _DType_co]):
448444
def var(self, axis=..., dtype=..., out=..., ddof=..., keepdims=...): ...
449445
def std(self, axis=..., dtype=..., out=..., ddof=..., keepdims=...): ...
450446
def round(self, decimals=..., out=...): ...
451-
def argsort(self, axis=..., kind=..., order=..., endwith=..., fill_value=..., stable=...): ...
447+
def argsort(self, axis=..., kind=..., order=..., endwith=..., fill_value=..., *, stable=...): ...
452448
def argmin(self, axis=..., fill_value=..., out=..., *, keepdims=...): ...
453449
def argmax(self, axis=..., fill_value=..., out=..., *, keepdims=...): ...
454-
def sort(self, axis=..., kind=..., order=..., endwith=..., fill_value=..., stable=...): ...
450+
def sort(self, axis=..., kind=..., order=..., endwith=..., fill_value=..., *, stable=...): ...
455451
def min(self, axis=..., out=..., fill_value=..., keepdims=...): ...
456452
# NOTE: deprecated
457453
# def tostring(self, fill_value=..., order=...): ...
@@ -460,6 +456,7 @@ class MaskedArray(ndarray[_ShapeType_co, _DType_co]):
460456
def partition(self, *args, **kwargs): ...
461457
def argpartition(self, *args, **kwargs): ...
462458
def take(self, indices, axis=..., out=..., mode=...): ...
459+
463460
copy: Any
464461
diagonal: Any
465462
flatten: Any
@@ -468,19 +465,26 @@ class MaskedArray(ndarray[_ShapeType_co, _DType_co]):
468465
swapaxes: Any
469466
T: Any
470467
transpose: Any
468+
471469
@property # type: ignore[misc]
472470
def mT(self): ...
473-
def tolist(self, fill_value=...): ...
474-
def tobytes(self, fill_value=..., order=...): ...
475-
def tofile(self, fid, sep=..., format=...): ...
476-
def toflex(self): ...
477-
torecords: Any
471+
472+
#
473+
def toflex(self) -> Incomplete: ...
474+
def torecords(self) -> Incomplete: ...
475+
def tolist(self, fill_value: Incomplete | None = None) -> Incomplete: ...
476+
@deprecated("tostring() is deprecated. Use tobytes() instead.")
477+
def tostring(self, /, fill_value: Incomplete | None = None, order: _OrderKACF = "C") -> bytes: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
478+
def tobytes(self, /, fill_value: Incomplete | None = None, order: _OrderKACF = "C") -> bytes: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
479+
def tofile(self, /, fid: Incomplete, sep: str = "", format: str = "%s") -> Incomplete: ...
480+
481+
#
478482
def __reduce__(self): ...
479483
def __deepcopy__(self, memo=...): ...
480484

481485
class mvoid(MaskedArray[_ShapeType_co, _DType_co]):
482486
def __new__(
483-
self,
487+
self, # pyright: ignore[reportSelfClsParameterName]
484488
data,
485489
mask=...,
486490
dtype=...,
@@ -593,8 +597,8 @@ maximum: _extrema_operation
593597

594598
def take(a, indices, axis=..., out=..., mode=...): ...
595599
def power(a, b, third=...): ...
596-
def argsort(a, axis=..., kind=..., order=..., endwith=..., fill_value=..., stable=...): ...
597-
def sort(a, axis=..., kind=..., order=..., endwith=..., fill_value=..., stable=...): ...
600+
def argsort(a, axis=..., kind=..., order=..., endwith=..., fill_value=..., *, stable=...): ...
601+
def sort(a, axis=..., kind=..., order=..., endwith=..., fill_value=..., *, stable=...): ...
598602
def compressed(x): ...
599603
def concatenate(arrays, axis=...): ...
600604
def diag(v, k=...): ...
@@ -629,19 +633,21 @@ def asanyarray(a, dtype=...): ...
629633
def fromflex(fxarray): ...
630634

631635
class _convert2ma:
632-
__doc__: Any
633-
def __init__(self, funcname, params=...): ...
634-
def getdoc(self): ...
635-
def __call__(self, *args, **params): ...
636+
def __init__(self, /, funcname: str, np_ret: str, np_ma_ret: str, params: dict[str, Any] | None = None) -> None: ...
637+
def __call__(self, /, *args: object, **params: object) -> Any: ... # noqa: ANN401
638+
def getdoc(self, /, np_ret: str, np_ma_ret: str) -> str | None: ...
636639

637640
arange: _convert2ma
641+
clip: _convert2ma
638642
empty: _convert2ma
639643
empty_like: _convert2ma
640644
frombuffer: _convert2ma
641645
fromfunction: _convert2ma
642646
identity: _convert2ma
647+
indices: _convert2ma
643648
ones: _convert2ma
644649
ones_like: _convert2ma
650+
squeeze: _convert2ma
645651
zeros: _convert2ma
646652
zeros_like: _convert2ma
647653

numpy/ma/extras.pyi

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
from typing import Any
1+
from _typeshed import Incomplete
22

3+
import numpy as np
34
from numpy.lib._function_base_impl import average
45
from numpy.lib._index_tricks_impl import AxisConcatenator
56

6-
from .core import dot, mask_rowcols
7+
from .core import MaskedArray, dot
78

89
__all__ = [
910
"apply_along_axis",
@@ -19,8 +20,8 @@ __all__ = [
1920
"compress_nd",
2021
"compress_rowcols",
2122
"compress_rows",
22-
"count_masked",
2323
"corrcoef",
24+
"count_masked",
2425
"cov",
2526
"diagflat",
2627
"dot",
@@ -30,9 +31,9 @@ __all__ = [
3031
"flatnotmasked_edges",
3132
"hsplit",
3233
"hstack",
33-
"isin",
3434
"in1d",
3535
"intersect1d",
36+
"isin",
3637
"mask_cols",
3738
"mask_rowcols",
3839
"mask_rows",
@@ -48,8 +49,8 @@ __all__ = [
4849
"setdiff1d",
4950
"setxor1d",
5051
"stack",
51-
"unique",
5252
"union1d",
53+
"unique",
5354
"vander",
5455
"vstack",
5556
]
@@ -59,9 +60,9 @@ def masked_all(shape, dtype = ...): ...
5960
def masked_all_like(arr): ...
6061

6162
class _fromnxfunction:
62-
__name__: Any
63-
__doc__: Any
64-
def __init__(self, funcname): ...
63+
__name__: Incomplete
64+
__doc__: Incomplete
65+
def __init__(self, funcname) -> None: ...
6566
def getdoc(self): ...
6667
def __call__(self, *args, **params): ...
6768

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

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

117118
class mr_class(MAxisConcatenator):
118-
def __init__(self): ...
119+
def __init__(self) -> None: ...
119120

120121
mr_: mr_class
121122

@@ -128,3 +129,6 @@ def clump_unmasked(a): ...
128129
def clump_masked(a): ...
129130
def vander(x, n=...): ...
130131
def polyfit(x, y, deg, rcond=..., full=..., w=..., cov=...): ...
132+
133+
#
134+
def mask_rowcols(a: Incomplete, axis: Incomplete | None = None) -> MaskedArray[Incomplete, np.dtype[Incomplete]]: ...

0 commit comments

Comments
 (0)
0