Skip to content

Commit ec3ac3d

Browse files
TYP: Type MaskedArray.resize, wrap NoReturn tests in functions (#29401)
Co-authored-by: Joren Hammudoglu <jhammudoglu@gmail.com>
1 parent 5a031d9 commit ec3ac3d

File tree

4 files changed

+57
-23
lines changed

4 files changed

+57
-23
lines changed

numpy/ma/core.pyi

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,16 @@
33

44
from _typeshed import Incomplete
55
from collections.abc import Sequence
6-
from typing import Any, Literal, NoReturn, Self, SupportsIndex, TypeAlias, overload
6+
from typing import (
7+
Any,
8+
Literal,
9+
Never,
10+
NoReturn,
11+
Self,
12+
SupportsIndex,
13+
TypeAlias,
14+
overload,
15+
)
716
from typing_extensions import TypeIs, TypeVar
817

918
import numpy as np
@@ -1073,7 +1082,7 @@ class MaskedArray(ndarray[_ShapeT_co, _DTypeT_co]):
10731082

10741083
def ravel(self, order: _OrderKACF = "C") -> MaskedArray[tuple[int], _DTypeT_co]: ...
10751084
def reshape(self, *s, **kwargs): ...
1076-
def resize(self, newshape, refcheck=..., order=...): ...
1085+
def resize(self, newshape: Never, refcheck: bool = True, order: bool = False) -> NoReturn: ...
10771086
def put(self, indices: _ArrayLikeInt_co, values: ArrayLike, mode: _ModeKind = "raise") -> None: ...
10781087
def ids(self) -> tuple[int, int]: ...
10791088
def iscontiguous(self) -> bool: ...

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,10 @@ assert_type(np.polyadd(AR_O, AR_O), npt.NDArray[np.object_])
118118

119119
assert_type(np.polysub(poly_obj, AR_i8), np.poly1d)
120120
assert_type(np.polysub(AR_f8, poly_obj), np.poly1d)
121-
assert_type(np.polysub(AR_b, AR_b), NoReturn)
121+
122+
def test_invalid_polysub() -> None:
123+
assert_type(np.polysub(AR_b, AR_b), NoReturn)
124+
122125
assert_type(np.polysub(AR_u4, AR_b), npt.NDArray[np.unsignedinteger])
123126
assert_type(np.polysub(AR_i8, AR_i8), npt.NDArray[np.signedinteger])
124127
assert_type(np.polysub(AR_f8, AR_i8), npt.NDArray[np.floating])

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any, Literal, TypeAlias, TypeVar, assert_type
1+
from typing import Any, Literal, TypeAlias, TypeVar, assert_type, NoReturn
22

33
import numpy as np
44
from numpy import dtype, generic
@@ -405,6 +405,9 @@ assert_type(MAR_f8.cumprod(out=MAR_subclass), MaskedArraySubclass)
405405
assert_type(MAR_f8.cumsum(), MaskedArray[Any])
406406
assert_type(MAR_f8.cumsum(out=MAR_subclass), MaskedArraySubclass)
407407

408+
def invalid_resize() -> None:
409+
assert_type(MAR_f8.resize((1,1)), NoReturn) # type: ignore[arg-type]
410+
408411
# Masked Array addition
409412

410413
assert_type(MAR_b + AR_LIKE_u, MaskedArray[np.uint32])

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

Lines changed: 38 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -98,26 +98,45 @@ assert_type(np.bitwise_count.identity, None)
9898
assert_type(np.bitwise_count(i8), Any)
9999
assert_type(np.bitwise_count(AR_i8), npt.NDArray[Any])
100100

101-
assert_type(np.absolute.outer(), NoReturn)
102-
assert_type(np.frexp.outer(), NoReturn)
103-
assert_type(np.divmod.outer(), NoReturn)
104-
assert_type(np.matmul.outer(), NoReturn)
101+
def test_absolute_outer_invalid() -> None:
102+
assert_type(np.absolute.outer(), NoReturn)
103+
def test_frexp_outer_invalid() -> None:
104+
assert_type(np.frexp.outer(), NoReturn)
105+
def test_divmod_outer_invalid() -> None:
106+
assert_type(np.divmod.outer(), NoReturn)
107+
def test_matmul_outer_invalid() -> None:
108+
assert_type(np.matmul.outer(), NoReturn)
105109

106-
assert_type(np.absolute.reduceat(), NoReturn)
107-
assert_type(np.frexp.reduceat(), NoReturn)
108-
assert_type(np.divmod.reduceat(), NoReturn)
109-
assert_type(np.matmul.reduceat(), NoReturn)
110+
def test_absolute_reduceat_invalid() -> None:
111+
assert_type(np.absolute.reduceat(), NoReturn)
112+
def test_frexp_reduceat_invalid() -> None:
113+
assert_type(np.frexp.reduceat(), NoReturn)
114+
def test_divmod_reduceat_invalid() -> None:
115+
assert_type(np.divmod.reduceat(), NoReturn)
116+
def test_matmul_reduceat_invalid() -> None:
117+
assert_type(np.matmul.reduceat(), NoReturn)
110118

111-
assert_type(np.absolute.reduce(), NoReturn)
112-
assert_type(np.frexp.reduce(), NoReturn)
113-
assert_type(np.divmod.reduce(), NoReturn)
114-
assert_type(np.matmul.reduce(), NoReturn)
119+
def test_absolute_reduce_invalid() -> None:
120+
assert_type(np.absolute.reduce(), NoReturn)
121+
def test_frexp_reduce_invalid() -> None:
122+
assert_type(np.frexp.reduce(), NoReturn)
123+
def test_divmod_reduce_invalid() -> None:
124+
assert_type(np.divmod.reduce(), NoReturn)
125+
def test_matmul_reduce_invalid() -> None:
126+
assert_type(np.matmul.reduce(), NoReturn)
115127

116-
assert_type(np.absolute.accumulate(), NoReturn)
117-
assert_type(np.frexp.accumulate(), NoReturn)
118-
assert_type(np.divmod.accumulate(), NoReturn)
119-
assert_type(np.matmul.accumulate(), NoReturn)
128+
def test_absolute_accumulate_invalid() -> None:
129+
assert_type(np.absolute.accumulate(), NoReturn)
130+
def test_frexp_accumulate_invalid() -> None:
131+
assert_type(np.frexp.accumulate(), NoReturn)
132+
def test_divmod_accumulate_invalid() -> None:
133+
assert_type(np.divmod.accumulate(), NoReturn)
134+
def test_matmul_accumulate_invalid() -> None:
135+
assert_type(np.matmul.accumulate(), NoReturn)
120136

121-
assert_type(np.frexp.at(), NoReturn)
122-
assert_type(np.divmod.at(), NoReturn)
123-
assert_type(np.matmul.at(), NoReturn)
137+
def test_frexp_at_invalid() -> None:
138+
assert_type(np.frexp.at(), NoReturn)
139+
def test_divmod_at_invalid() -> None:
140+
assert_type(np.divmod.at(), NoReturn)
141+
def test_matmul_at_invalid() -> None:
142+
assert_type(np.matmul.at(), NoReturn)

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