Skip to content

Commit 6bfe742

Browse files
committed
TST: test cases for numpygh-23081
1 parent 986f5c5 commit 6bfe742

2 files changed

Lines changed: 52 additions & 0 deletions

File tree

‎numpy/typing/tests/data/pass/array_like.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,9 @@ def __array__(self, dtype: None | np.dtype[Any] = None) -> np.ndarray:
3939
# array.
4040
object_array_scalar: Any = (i for i in range(10))
4141
np.array(object_array_scalar)
42+
43+
# Test that a Sequence[Union[type, np.dtype]] counts as ArrayLike per gh-23081
44+
Number_or_float = np.number | float
45+
num_or_float_1: Number_or_float = 1
46+
num_or_float_2: Number_or_float = 2
47+
tuple_of_num_or_float: np.typing.ArrayLike= (num_or_float_1, num_or_float_1)

‎numpy/typing/tests/data/pass/ufuncs.py‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,49 @@
1515
np.sin.__doc__
1616

1717
np.abs(np.array([1]))
18+
19+
# Test gh-23081 issue is resolved: mypy will not give a type error if ufuncs are
20+
# called a python Sequence of Union[<python type>, <np.dtype>]
21+
Scalar = np.number | float
22+
23+
def nin1_nout1(
24+
x: Scalar = 1,
25+
y: Scalar = 2
26+
):
27+
return np.isfinite((x, y))
28+
29+
def nin2_nout1(
30+
w: Scalar = 0,
31+
x: Scalar = 1,
32+
y: Scalar = 2,
33+
z: Scalar = 3
34+
):
35+
return np.add((w, x), (y, z))
36+
37+
def nin1_nout2(
38+
x: Scalar = 1,
39+
y: Scalar = 2
40+
):
41+
return np.frexp((x, y))
42+
43+
def nin2_nout2(
44+
w: Scalar = 0,
45+
x: Scalar = 1,
46+
y: Scalar = 2,
47+
z: Scalar = 3
48+
):
49+
return np.divmod((w, x), (y, z))
50+
51+
def gufunc_nin2_nout1(
52+
w: Scalar = 0,
53+
x: Scalar = 1,
54+
y: Scalar = 2,
55+
z: Scalar = 3
56+
):
57+
return np.matmul((w, x), (y, z))
58+
59+
nin1_nout1()
60+
nin2_nout1()
61+
nin1_nout2()
62+
nin2_nout2()
63+
gufunc_nin2_nout1()

0 commit comments

Comments
 (0)