Skip to content

Commit f537627

Browse files
authored
Merge pull request #280 from numpy/fix-ma
🏷️ fix stubtest error in `numpy.ma`
2 parents c0c5bf7 + de23b27 commit f537627

File tree

4 files changed

+67
-66
lines changed

4 files changed

+67
-66
lines changed

src/numpy-stubs/ma/core.pyi

Lines changed: 59 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
from _typeshed import Incomplete
2-
from collections.abc import Callable
3-
from typing import Any, ClassVar, Final, Generic, Literal as L, type_check_only
4-
from typing_extensions import Never, Self, TypeVar, overload
2+
from typing import Any, ClassVar, Final, Generic, Literal as L, SupportsIndex as CanIndex, TypeAlias, type_check_only
3+
from typing_extensions import Never, Self, TypeVar, deprecated, overload
54

65
import numpy as np
76
from _numtype import Array, ToGeneric_0d, ToGeneric_1nd, ToGeneric_nd
8-
from numpy import _OrderACF, _OrderKACF, amax, amin, angle, bool_, clip, expand_dims, indices, squeeze # noqa: ICN003
7+
from numpy import _OrderACF, _OrderKACF, amax, amin, bool_, expand_dims # noqa: ICN003
8+
from numpy._typing import _BoolCodes
99

1010
__all__ = [
1111
"MAError",
@@ -194,6 +194,8 @@ _ShapeT_co = TypeVar("_ShapeT_co", bound=tuple[int, ...], default=tuple[int, ...
194194
_DTypeT = TypeVar("_DTypeT", bound=np.dtype[Any])
195195
_DTypeT_co = TypeVar("_DTypeT_co", bound=np.dtype[Any], default=np.dtype[Any], covariant=True)
196196

197+
_DTypeLikeBool: TypeAlias = type[bool | np.bool] | np.dtype[np.bool] | _BoolCodes
198+
197199
###
198200

199201
MaskType: Final[type[np.bool]] = ...
@@ -241,7 +243,6 @@ class _DomainSafeDivide:
241243

242244
class _MaskedUFunc(Generic[_UFuncT_co]):
243245
f: _UFuncT_co
244-
__doc__: str
245246
__name__: str
246247
__qualname__: str
247248
def __init__(self, /, ufunc: _UFuncT_co) -> None: ...
@@ -344,9 +345,7 @@ class MaskedArray(np.ndarray[_ShapeT_co, _DTypeT_co]):
344345

345346
#
346347
@property
347-
def data(self) -> Incomplete: ...
348-
@data.setter
349-
def data(self, value: Incomplete, /) -> Incomplete: ...
348+
def data(self) -> np.ndarray[_ShapeT_co, _DTypeT_co]: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
350349

351350
#
352351
def get_fill_value(self) -> Incomplete: ...
@@ -369,6 +368,8 @@ class MaskedArray(np.ndarray[_ShapeT_co, _DTypeT_co]):
369368
#
370369
@property
371370
def mT(self) -> Self: ...
371+
@property
372+
def T(self) -> Self: ...
372373

373374
#
374375
def __new__(
@@ -533,42 +534,50 @@ class MaskedArray(np.ndarray[_ShapeT_co, _DTypeT_co]):
533534
def anom(self, axis: Incomplete = ..., dtype: Incomplete = ...) -> Incomplete: ...
534535
def var( # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
535536
self,
537+
/,
536538
axis: Incomplete = ...,
537539
dtype: Incomplete = ...,
538540
out: Incomplete = ...,
539-
ddof: Incomplete = ...,
541+
ddof: float = 0,
540542
keepdims: Incomplete = ...,
543+
mean: Incomplete = ...,
541544
) -> Incomplete: ...
542545
def std( # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
543546
self,
547+
/,
544548
axis: Incomplete = ...,
545549
dtype: Incomplete = ...,
546550
out: Incomplete = ...,
547-
ddof: Incomplete = ...,
551+
ddof: float = 0,
548552
keepdims: Incomplete = ...,
553+
mean: Incomplete = ...,
549554
) -> Incomplete: ...
550555

551556
#
552557
def round(self, decimals: Incomplete = ..., out: Incomplete = ...) -> Incomplete: ... # pyright: ignore[reportIncompatibleMethodOverride]
553558

554559
#
555-
def sort( # pyright: ignore[reportIncompatibleMethodOverride]
560+
def sort( # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
556561
self,
557-
axis: Incomplete = ...,
558-
kind: Incomplete = ...,
559-
order: Incomplete = ...,
560-
endwith: Incomplete = ...,
561-
fill_value: Incomplete = ...,
562-
stable: Incomplete = ...,
562+
/,
563+
axis: Incomplete = -1,
564+
kind: Incomplete | None = None,
565+
order: Incomplete | None = None,
566+
endwith: bool = True,
567+
fill_value: Incomplete | None = None,
568+
*,
569+
stable: bool = False,
563570
) -> Incomplete: ...
564-
def argsort( # pyright: ignore[reportIncompatibleMethodOverride]
571+
def argsort( # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
565572
self,
573+
/,
566574
axis: Incomplete = ...,
567-
kind: Incomplete = ...,
568-
order: Incomplete = ...,
569-
endwith: Incomplete = ...,
570-
fill_value: Incomplete = ...,
571-
stable: Incomplete = ...,
575+
kind: Incomplete | None = None,
576+
order: Incomplete | None = None,
577+
endwith: bool = True,
578+
fill_value: Incomplete | None = None,
579+
*,
580+
stable: bool = False,
572581
) -> Incomplete: ...
573582

574583
#
@@ -637,15 +646,16 @@ class MaskedArray(np.ndarray[_ShapeT_co, _DTypeT_co]):
637646
repeat: Incomplete
638647
squeeze: Incomplete
639648
swapaxes: Incomplete
640-
T: Incomplete
641649
transpose: Incomplete
642650

643651
#
644652
def toflex(self) -> Incomplete: ...
645653
def torecords(self) -> Incomplete: ...
646-
def tolist(self, fill_value: Incomplete = ...) -> Incomplete: ...
647-
def tobytes(self, fill_value: Incomplete = ..., order: Incomplete = ...) -> Incomplete: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
648-
def tofile(self, fid: Incomplete, sep: Incomplete = ..., format: Incomplete = ...) -> Incomplete: ...
654+
def tolist(self, fill_value: Incomplete | None = None) -> Incomplete: ...
655+
@deprecated("tostring() is deprecated. Use tobytes() instead.")
656+
def tostring(self, /, fill_value: Incomplete | None = None, order: _OrderKACF = "C") -> bytes: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
657+
def tobytes(self, /, fill_value: Incomplete | None = None, order: _OrderKACF = "C") -> bytes: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
658+
def tofile(self, /, fid: Incomplete, sep: str = "", format: str = "%s") -> Incomplete: ...
649659

650660
class mvoid(MaskedArray[_ShapeT_co, _DTypeT_co]):
651661
def __new__(
@@ -680,7 +690,6 @@ class MaskedConstant(MaskedArray[tuple[()], np.dtype[np.float64]]):
680690
def __format__(self, format_spec: str, /) -> str: ...
681691

682692
#
683-
def __iop__(self, other: Incomplete, /) -> Self: ...
684693
def __iadd__(self, other: Incomplete, /) -> Self: ... # type: ignore[override]
685694
def __isub__(self, other: Incomplete, /) -> Self: ... # type: ignore[override]
686695
def __imul__(self, other: Incomplete, /) -> Self: ... # type: ignore[override]
@@ -703,10 +712,9 @@ class _frommethod:
703712
def getdoc(self) -> Incomplete: ...
704713

705714
class _convert2ma:
706-
__doc__: str
707-
def __init__(self, funcname: Incomplete, params: Incomplete = ...) -> None: ...
708-
def __call__(self, *args: Incomplete, **params: Incomplete) -> Incomplete: ...
709-
def getdoc(self) -> Incomplete: ...
715+
def __init__(self, /, funcname: str, np_ret: str, np_ma_ret: str, params: dict[str, Any] | None = None) -> None: ...
716+
def __call__(self, /, *args: object, **params: object) -> Any: ...
717+
def getdoc(self, /, np_ret: str, np_ma_ret: str) -> str | None: ...
710718

711719
#
712720
def array(
@@ -762,6 +770,7 @@ def argsort(
762770
order: Incomplete = ...,
763771
endwith: Incomplete = ...,
764772
fill_value: Incomplete = ...,
773+
*,
765774
stable: Incomplete = ...,
766775
) -> Incomplete: ...
767776
def sort(
@@ -771,6 +780,7 @@ def sort(
771780
order: Incomplete = ...,
772781
endwith: Incomplete = ...,
773782
fill_value: Incomplete = ...,
783+
*,
774784
stable: Incomplete = ...,
775785
) -> Incomplete: ...
776786
def compressed(x: Incomplete) -> Incomplete: ...
@@ -842,7 +852,6 @@ def masked_invalid(a: Incomplete, copy: Incomplete = ...) -> Incomplete: ...
842852
def flatten_structured_array(a: Incomplete) -> Incomplete: ...
843853
def append(a: Incomplete, b: Incomplete, axis: Incomplete = ...) -> Incomplete: ...
844854
def dot(a: Incomplete, b: Incomplete, strict: Incomplete = ..., out: Incomplete = ...) -> Incomplete: ...
845-
def mask_rowcols(a: Incomplete, axis: Incomplete = ...) -> Incomplete: ...
846855
def default_fill_value(obj: Incomplete) -> Incomplete: ...
847856
def minimum_fill_value(obj: Incomplete) -> Incomplete: ...
848857
def maximum_fill_value(obj: Incomplete) -> Incomplete: ...
@@ -879,6 +888,7 @@ cosh: _MaskedUnaryOperation
879888
tanh: _MaskedUnaryOperation
880889
abs: _MaskedUnaryOperation
881890
absolute: _MaskedUnaryOperation
891+
angle: _MaskedUnaryOperation
882892
fabs: _MaskedUnaryOperation
883893
negative: _MaskedUnaryOperation
884894
floor: _MaskedUnaryOperation
@@ -906,29 +916,37 @@ greater_equal: _MaskedBinaryOperation
906916
less: _MaskedBinaryOperation
907917
greater: _MaskedBinaryOperation
908918
logical_and: _MaskedBinaryOperation
909-
alltrue: _MaskedBinaryOperation
919+
920+
def alltrue(target: ToGeneric_nd, axis: CanIndex | None = 0, dtype: _DTypeLikeBool | None = None) -> Incomplete: ...
921+
910922
logical_or: _MaskedBinaryOperation
911-
sometrue: Callable[..., Incomplete]
923+
924+
def sometrue(target: ToGeneric_nd, axis: CanIndex | None = 0, dtype: _DTypeLikeBool | None = None) -> Incomplete: ...
925+
912926
logical_xor: _MaskedBinaryOperation
913927
bitwise_and: _MaskedBinaryOperation
914928
bitwise_or: _MaskedBinaryOperation
915929
bitwise_xor: _MaskedBinaryOperation
916930
hypot: _MaskedBinaryOperation
917-
divide: _MaskedBinaryOperation
918-
true_divide: _MaskedBinaryOperation
919-
floor_divide: _MaskedBinaryOperation
920-
remainder: _MaskedBinaryOperation
921-
fmod: _MaskedBinaryOperation
922-
mod: _MaskedBinaryOperation
931+
932+
divide: _DomainedBinaryOperation
933+
true_divide: _DomainedBinaryOperation
934+
floor_divide: _DomainedBinaryOperation
935+
remainder: _DomainedBinaryOperation
936+
fmod: _DomainedBinaryOperation
937+
mod: _DomainedBinaryOperation
923938

924939
arange: _convert2ma
940+
clip: _convert2ma
925941
empty: _convert2ma
926942
empty_like: _convert2ma
927943
frombuffer: _convert2ma
928944
fromfunction: _convert2ma
929945
identity: _convert2ma
946+
indices: _convert2ma
930947
ones: _convert2ma
931948
ones_like: _convert2ma
949+
squeeze: _convert2ma
932950
zeros: _convert2ma
933951
zeros_like: _convert2ma
934952

src/numpy-stubs/ma/extras.pyi

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
from _typeshed import Incomplete
22
from typing import Final
33

4+
import numpy as np
45
from numpy.lib._function_base_impl import average
56
from numpy.lib._index_tricks_impl import AxisConcatenator
67

7-
from .core import dot, mask_rowcols
8+
from .core import MaskedArray, dot
89

910
__all__ = [
1011
"apply_along_axis",
@@ -75,6 +76,8 @@ class _fromnxfunction_allargs(_fromnxfunction):
7576
def __call__(self, *args: Incomplete, **params: Incomplete) -> Incomplete: ...
7677

7778
class MAxisConcatenator(AxisConcatenator):
79+
@staticmethod
80+
def concatenate(arrays: Incomplete, axis: int = 0) -> Incomplete: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
7881
@classmethod
7982
def makemat(cls, arr: Incomplete) -> Incomplete: ... # type: ignore[override] # pyright: ignore[reportIncompatibleVariableOverride]
8083

@@ -167,3 +170,5 @@ stack: _fromnxfunction_seq
167170

168171
hsplit: _fromnxfunction_single
169172
diagflat: _fromnxfunction_single
173+
174+
def mask_rowcols(a: Incomplete, axis: Incomplete | None = None) -> MaskedArray[tuple[int, ...], np.dtype[Incomplete]]: ...

src/numpy-stubs/ma/mrecords.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ def fromtextfile(
8080
missingchar: Incomplete = ...,
8181
varnames: Incomplete = ...,
8282
vartypes: Incomplete = ...,
83+
*,
84+
delimitor: Incomplete = ...,
8385
) -> Incomplete: ...
8486
def addfield(mrecord: Incomplete, newfield: Incomplete, newfieldname: Incomplete = ...) -> Incomplete: ...
8587

tool/.mypyignore-todo.txt

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -22,27 +22,3 @@ numpy.f2py.symbolic
2222
numpy.f2py.((cb|common|f90mod|use)_)?rules
2323

2424
numpy.ma.testutils
25-
numpy.ma.core._convert2ma.__doc__
26-
numpy.ma.core._convert2ma.__init__
27-
numpy.ma.core._convert2ma.getdoc
28-
numpy.ma.core._MaskedUFunc.__doc__
29-
numpy.ma.core.MaskedConstant.__iop__
30-
numpy.ma(.core)?.(MaskedArray|masked_array).T
31-
numpy.ma(.core)?.(MaskedArray|masked_array).argsort
32-
numpy.ma(.core)?.(MaskedArray|masked_array).data
33-
numpy.ma(.core)?.(MaskedArray|masked_array).sort
34-
numpy.ma(.core)?.(MaskedArray|masked_array).std
35-
numpy.ma(.core)?.(MaskedArray|masked_array).tostring
36-
numpy.ma(.core)?.(MaskedArray|masked_array).var
37-
numpy.ma(.core)?.alltrue
38-
numpy.ma(.core)?.angle
39-
numpy.ma(.core)?.clip
40-
numpy.ma(.core)?.(arg)?sort
41-
numpy.ma(.core)?.((floor|true)_)?divide
42-
numpy.ma(.core)?.f?mod
43-
numpy.ma(.core)?.indices
44-
numpy.ma(.core)?.remainder
45-
numpy.ma(.core)?.squeeze
46-
numpy.ma.core.mask_rowcols
47-
numpy.ma.extras.MAxisConcatenator.concatenate
48-
numpy.ma.mrecords.fromtextfile

0 commit comments

Comments
 (0)