8000 TYP: Type ``np.ma.allclose`` and ``np.ma.allequal`` (#28793) · numpy/numpy@8362f53 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8362f53

Browse files
authored
TYP: Type np.ma.allclose and np.ma.allequal (#28793)
1 parent 1bc8764 commit 8362f53

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

numpy/ma/core.pyi

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1184,8 +1184,11 @@ outerproduct = outer
11841184

11851185
def correlate(a, v, mode=..., propagate_mask=...): ...
11861186
def convolve(a, v, mode=..., propagate_mask=...): ...
1187-
def allequal(a, b, fill_value=...): ...
1188-
def allclose(a, b, masked_equal=..., rtol=..., atol=...): ...
1187+
1188+
def allequal(a: ArrayLike, b: ArrayLike, fill_value: bool = True) -> bool: ...
1189+
1190+
def allclose(a: ArrayLike, b: ArrayLike, masked_equal: bool = True, rtol: float = 1e-5, atol: float = 1e-8) -> bool: ...
1191+
11891192
def asarray(a, dtype=..., order=...): ...
11901193
def asanyarray(a, dtype=...): ...
11911194
def fromflex(fxarray): ...

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,3 +116,9 @@ np.ma.put(m, 4, 999, mode='flip') # E: No overload variant
116116
np.ma.put([1,1,3], 0, 999) # E: No overload variant
117117

118118
np.ma.compressed(lambda: 'compress me') # E: No overload variant
119+
120+
np.ma.allequal(m, [1,2,3], fill_value=1.5) # E: No overload variant
121+
122+
np.ma.allclose(m, [1,2,3], masked_equal=4.5) # E: No overload variant
123+
np.ma.allclose(m, [1,2,3], rtol='.4') # E: No overload variant
124+
np.ma.allclose(m, [1,2,3], atol='.5') # E: No overload variant

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,3 +273,10 @@ assert_type(np.ma.filled([[1,2,3]]), NDArray[Any])
273273
# PyRight detects this one correctly, but mypy doesn't.
274274
# https://github.com/numpy/numpy/pull/28742#discussion_r2048968375
275275
assert_type(np.ma.filled(MAR_1d), np.ndarray[tuple[int], np.dtype]) # type: ignore[assert-type]
276+
277+
assert_type(np.ma.allequal(AR_f4, MAR_f4), bool)
278+
assert_type(np.ma.allequal(AR_f4, MAR_f4, fill_value=False), bool)
279+
280+
assert_type(np.ma.allclose(AR_f4, MAR_f4), bool)
281+
assert_type(np.ma.allclose(AR_f4, MAR_f4, masked_equal=False), bool)
282+
assert_type(np.ma.allclose(AR_f4, MAR_f4, rtol=.4, atol=.3), bool)

0 commit comments

Comments
 (0)
0