Skip to content

Commit 0309890

Browse files
authored
TYP: Type np.ma.{is_masked,ndim,size,ids,is_contiguous} (numpy#28715)
1 parent d5fd966 commit 0309890

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

numpy/ma/core.pyi

+5-5
Original file line numberDiff line numberDiff line change
@@ -457,8 +457,8 @@ class MaskedArray(ndarray[_ShapeT_co, _DTypeT_co]):
457457
def reshape(self, *s, **kwargs): ...
458458
def resize(self, newshape, refcheck=..., order=...): ...
459459
def put(self, indices, values, mode=...): ...
460-
def ids(self): ...
461-
def iscontiguous(self): ...
460+
def ids(self) -> tuple[int, int]: ...
461+
def iscontiguous(self) -> bool: ...
462462
def all(self, axis=..., out=..., keepdims=...): ...
463463
def any(self, axis=..., out=..., keepdims=...): ...
464464
def nonzero(self): ...
@@ -804,7 +804,7 @@ def array(
804804
subok=...,
805805
ndmin=...,
806806
): ...
807-
def is_masked(x): ...
807+
def is_masked(x: object) -> bool: ...
808808

809809
class _extrema_operation(_MaskedUFunc):
810810
compare: Any
@@ -1113,9 +1113,9 @@ def putmask(a, mask, values): ...
11131113
def transpose(a, axes=...): ...
11141114
def reshape(a, new_shape, order=...): ...
11151115
def resize(x, new_shape): ...
1116-
def ndim(obj): ...
1116+
def ndim(obj: ArrayLike) -> int: ...
11171117
def shape(obj): ...
1118-
def size(obj, axis=...): ...
1118+
def size(obj: ArrayLike, axis: SupportsIndex | None = None) -> int: ...
11191119
def diff(a, /, n=..., axis=..., prepend=..., append=...): ...
11201120
def where(condition, x=..., y=...): ...
11211121
def choose(indices, choices, out=..., mode=...): ...

numpy/typing/tests/data/fail/ma.pyi

+4-1
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,14 @@ m.argpartition(kind='cabbage') # E: No overload variant
9393
m.argpartition(order=lambda: 'cabbage') # E: No overload variant
9494
m.argpartition(AR_b) # E: No overload variant
9595

96+
np.ma.ndim(lambda: 'lambda') # E: No overload variant
97+
98+
np.ma.size(AR_b, axis='0') # E: No overload variant
99+
96100
m >= (lambda x: 'mango') # E: No overload variant
97101

98102
m > (lambda x: 'mango') # E: No overload variant
99103

100104
m <= (lambda x: 'mango') # E: No overload variant
101105

102106
m < (lambda x: 'mango') # E: No overload variant
103-

numpy/typing/tests/data/reveal/ma.pyi

+15
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ MAR_subclass: MaskedNDArraySubclass
3030

3131
MAR_1d: np.ma.MaskedArray[tuple[int], np.dtype[Any]]
3232

33+
b: np.bool
3334
f4: np.float32
3435
f: float
3536

@@ -168,6 +169,20 @@ assert_type(MAR_f4.partition(1, axis=0, kind='introselect', order='K'), None)
168169
assert_type(MAR_f4.argpartition(1), MaskedNDArray[np.intp])
169170
assert_type(MAR_1d.argpartition(1, axis=0, kind='introselect', order='K'), MaskedNDArray[np.intp])
170171

172+
assert_type(np.ma.ndim(f4), int)
173+
assert_type(np.ma.ndim(MAR_b), int)
174+
assert_type(np.ma.ndim(AR_f4), int)
175+
176+
assert_type(np.ma.size(b), int)
177+
assert_type(np.ma.size(MAR_f4, axis=0), int)
178+
assert_type(np.ma.size(AR_f4), int)
179+
180+
assert_type(np.ma.is_masked(MAR_f4), bool)
181+
182+
assert_type(MAR_f4.ids(), tuple[int, int])
183+
184+
assert_type(MAR_f4.iscontiguous(), bool)
185+
171186
assert_type(MAR_f4 >= 3, MaskedNDArray[np.bool])
172187
assert_type(MAR_i8 >= AR_td64, MaskedNDArray[np.bool])
173188
assert_type(MAR_b >= AR_td64, MaskedNDArray[np.bool])

0 commit comments

Comments
 (0)