Skip to content

Commit fda5e0d

Browse files
committed
TYP: fix stubtest error in numpy.ma
Ported from numpy/numtype#280
1 parent fcc32f0 commit fda5e0d

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",
@@ -256,6 +250,7 @@ cosh: _MaskedUnaryOperation
256250
tanh: _MaskedUnaryOperation
257251
abs: _MaskedUnaryOperation
258252
absolute: _MaskedUnaryOperation
253+
angle: _MaskedUnaryOperation
259254
fabs: _MaskedUnaryOperation
260255
negative: _MaskedUnaryOperation
261256
floor: _MaskedUnaryOperation
@@ -283,20 +278,21 @@ greater_equal: _MaskedBinaryOperation
283278
less: _MaskedBinaryOperation
284279
greater: _MaskedBinaryOperation
285280
logical_and: _MaskedBinaryOperation
286-
alltrue: _MaskedBinaryOperation
281+
def alltrue(target: ArrayLike, axis: SupportsIndex | None = 0, dtype: _DTypeLikeBool | None = None) -> Incomplete: ...
287282
logical_or: _MaskedBinaryOperation
288-
sometrue: Callable[..., Any]
283+
def sometrue(target: ArrayLike, axis: SupportsIndex | None = 0, dtype: _DTypeLikeBool | None = None) -> Incomplete: ...
289284
logical_xor: _MaskedBinaryOperation
290285
bitwise_and: _MaskedBinaryOperation
291286
bitwise_or: _MaskedBinaryOperation
292287
bitwise_xor: _MaskedBinaryOperation
293288
hypot: _MaskedBinaryOperation
294-
divide: _MaskedBinaryOperation
295-
true_divide: _MaskedBinaryOperation
296-
floor_divide: _MaskedBinaryOperation
297-
remainder: _MaskedBinaryOperation
298-
fmod: _MaskedBinaryOperation
299-
mod: _MaskedBinaryOperation
289+
290+
divide: _DomainedBinaryOperation
291+
true_divide: _DomainedBinaryOperation
292+
floor_divide: _DomainedBinaryOperation
293+
remainder: _DomainedBinaryOperation
294+
fmod: _DomainedBinaryOperation
295+
mod: _DomainedBinaryOperation
300296

301297
def make_mask_descr(ndtype): ...
302298
def getmask(a): ...
@@ -447,16 +443,17 @@ class MaskedArray(ndarray[_ShapeType_co, _DType_co]):
447443
def var(self, axis=..., dtype=..., out=..., ddof=..., keepdims=...): ...
448444
def std(self, axis=..., dtype=..., out=..., ddof=..., keepdims=...): ...
449445
def round(self, decimals=..., out=...): ...
450-
def argsort(self, axis=..., kind=..., order=..., endwith=..., fill_value=..., stable=...): ...
446+
def argsort(self, axis=..., kind=..., order=..., endwith=..., fill_value=..., *, stable=...): ...
451447
def argmin(self, axis=..., fill_value=..., out=..., *, keepdims=...): ...
452448
def argmax(self, axis=..., fill_value=..., out=..., *, keepdims=...): ...
453-
def sort(self, axis=..., kind=..., order=..., endwith=..., fill_value=..., stable=...): ...
449+
def sort(self, axis=..., kind=..., order=..., endwith=..., fill_value=..., *, stable=...): ...
454450
def min(self, axis=..., out=..., fill_value=..., keepdims=...): ...
455451
def max(self, axis=..., out=..., fill_value=..., keepdims=...): ...
456452
def ptp(self, axis=..., out=..., fill_value=..., keepdims=...): ...
457453
def partition(self, *args, **kwargs): ...
458454
def argpartition(self, *args, **kwargs): ...
459455
def take(self, indices, axis=..., out=..., mode=...): ...
456+
460457
copy: Any
461458
diagonal: Any
462459
flatten: Any
@@ -465,19 +462,26 @@ class MaskedArray(ndarray[_ShapeType_co, _DType_co]):
465462
swapaxes: Any
466463
T: Any
467464
transpose: Any
465+
468466
@property # type: ignore[misc]
469467
def mT(self): ...
470-
def tolist(self, fill_value=...): ...
471-
def tobytes(self, fill_value=..., order=...): ...
472-
def tofile(self, fid, sep=..., format=...): ...
473-
def toflex(self): ...
474-
torecords: Any
468+
469+
#
470+
def toflex(self) -> Incomplete: ...
471+
def torecords(self) -> Incomplete: ...
472+
def tolist(self, fill_value: Incomplete | None = None) -> Incomplete: ...
473+
@deprecated("tostring() is deprecated. Use tobytes() instead.")
474+
def tostring(self, /, fill_value: Incomplete | None = None, order: _OrderKACF = "C") -> bytes: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
475+
def tobytes(self, /, fill_value: Incomplete | None = None, order: _OrderKACF = "C") -> bytes: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
476+
def tofile(self, /, fid: Incomplete, sep: str = "", format: str = "%s") -> Incomplete: ...
477+
478+
#
475479
def __reduce__(self): ...
476480
def __deepcopy__(self, memo=...): ...
477481

478482
class mvoid(MaskedArray[_ShapeType_co, _DType_co]):
479483
def __new__(
480-
self,
484+
self, # pyright: ignore[reportSelfClsParameterName]
481485
data,
482486
mask=...,
483487
dtype=...,
@@ -590,8 +594,8 @@ maximum: _extrema_operation
590594

591595
def take(a, indices, axis=..., out=..., mode=...): ...
592596
def power(a, b, third=...): ...
593-
def argsort(a, axis=..., kind=..., order=..., endwith=..., fill_value=..., stable=...): ...
594-
def sort(a, axis=..., kind=..., order=..., endwith=..., fill_value=..., stable=...): ...
597+
def argsort(a, axis=..., kind=..., order=..., endwith=..., fill_value=..., *, stable=...): ...
598+
def sort(a, axis=..., kind=..., order=..., endwith=..., fill_value=..., *, stable=...): ...
595599
def compressed(x): ...
596600
def concatenate(arrays, axis=...): ...
597601
def diag(v, k=...): ...
@@ -626,19 +630,21 @@ def asanyarray(a, dtype=...): ...
626630
def fromflex(fxarray): ...
627631

628632
class _convert2ma:
629-
__doc__: Any
630-
def __init__(self, funcname, params=...): ...
631-
def getdoc(self): ...
632-
def __call__(self, *args, **params): ...
633+
def __init__(self, /, funcname: str, np_ret: str, np_ma_ret: str, params: dict[str, Any] | None = None) -> None: ...
634+
def __call__(self, /, *args: object, **params: object) -> Any: ... # noqa: ANN401
635+
def getdoc(self, /, np_ret: str, np_ma_ret: str) -> str | None: ...
633636

634637
arange: _convert2ma
638+
clip: _convert2ma
635639
empty: _convert2ma
636640
empty_like: _convert2ma
637641
frombuffer: _convert2ma
638642
fromfunction: _convert2ma
639643
identity: _convert2ma
644+
indices: _convert2ma
640645
ones: _convert2ma
641646
ones_like: _convert2ma
647+
squeeze: _convert2ma
642648
zeros: _convert2ma
643649
zeros_like: _convert2ma
644650

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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy