Skip to content

Commit e173bce

Browse files
committed
✅ fix type-tests for new the rank-types (bpr)
1 parent 6932710 commit e173bce

16 files changed

+738
-810
lines changed

src/numpy-stubs/@test/runtime/legacy/recfunctions.py

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def test_recursive_fill_fields() -> None:
1717
)
1818
b = np.zeros((int(3),), dtype=a.dtype)
1919
out = rfn.recursive_fill_fields(a, b)
20-
assert_type(out, "np.ndarray[_nt.Shape1, np.dtype[np.void]]")
20+
assert_type(out, "_nt.Array1D[np.void]")
2121

2222

2323
def test_get_names() -> None:
@@ -59,25 +59,22 @@ def test_merge_arrays() -> None:
5959
np.ones((int(2),), np.int_),
6060
np.ones((int(3),), np.float64),
6161
)),
62-
"np.recarray[_nt.Shape1, np.dtype[np.void]]",
62+
"np.recarray[_nt.Rank1, np.dtype[np.void]]",
6363
)
6464

6565

6666
def test_drop_fields() -> None:
6767
ndtype = [("a", np.int64), ("b", [("b_a", np.double), ("b_b", np.int64)])]
6868
a = np.ones((int(3),), dtype=ndtype)
6969

70-
assert_type(
71-
rfn.drop_fields(a, "a"),
72-
"np.ndarray[_nt.Shape1, np.dtype[np.void]]",
73-
)
70+
assert_type(rfn.drop_fields(a, "a"), "_nt.Array1D[np.void]")
7471
assert_type(
7572
rfn.drop_fields(a, "a", asrecarray=True),
76-
"np.rec.recarray[_nt.Shape1, np.dtype[np.void]]",
73+
"np.rec.recarray[_nt.Rank1, np.dtype[np.void]]",
7774
)
7875
assert_type(
7976
rfn.rec_drop_fields(a, "a"),
80-
"np.rec.recarray[_nt.Shape1, np.dtype[np.void]]",
77+
"np.rec.recarray[_nt.Rank1, np.dtype[np.void]]",
8178
)
8279

8380

@@ -87,7 +84,7 @@ def test_rename_fields() -> None:
8784

8885
assert_type(
8986
rfn.rename_fields(a, {"a": "A", "b_b": "B_B"}),
90-
"np.ndarray[_nt.Shape1, np.dtype[np.void]]",
87+
"_nt.Array1D[np.void]",
9188
)
9289

9390

@@ -98,7 +95,7 @@ def test_repack_fields() -> None:
9895
assert_type(rfn.repack_fields(dt.type(0)), np.void)
9996
assert_type(
10097
rfn.repack_fields(np.ones((3,), dtype=dt)),
101-
"np.ndarray[_nt.Shape1, np.dtype[np.void]]",
98+
"_nt.Array1D[np.void]",
10299
)
103100

104101

@@ -115,40 +112,31 @@ def unstructured_to_structured() -> None:
115112

116113
def test_apply_along_fields() -> None:
117114
b = np.ones(4, dtype=[("x", "i4"), ("y", "f4"), ("z", "f8")])
118-
assert_type(
119-
rfn.apply_along_fields(np.mean, b),
120-
"np.ndarray[_nt.Shape1, np.dtype[np.void]]",
121-
)
115+
assert_type(rfn.apply_along_fields(np.mean, b), "_nt.Array1D[np.void]")
122116

123117

124118
def test_assign_fields_by_name() -> None:
125119
b = np.ones(4, dtype=[("x", "i4"), ("y", "f4"), ("z", "f8")])
126-
assert_type(
127-
rfn.apply_along_fields(np.mean, b),
128-
"np.ndarray[_nt.Shape1, np.dtype[np.void]]",
129-
)
120+
assert_type(rfn.apply_along_fields(np.mean, b), "_nt.Array1D[np.void]")
130121

131122

132123
def test_require_fields() -> None:
133124
a = np.ones(4, dtype=[("a", "i4"), ("b", "f8"), ("c", "u1")])
134125
assert_type(
135126
rfn.require_fields(a, [("b", "f4"), ("c", "u1")]),
136-
"np.ndarray[_nt.Shape1, np.dtype[np.void]]",
127+
"_nt.Array1D[np.void]",
137128
)
138129

139130

140131
def test_stack_arrays() -> None:
141132
x = np.zeros((int(2),), np.int32)
142-
assert_type(
143-
rfn.stack_arrays(x),
144-
"np.ndarray[_nt.Shape1, np.dtype[np.int32]]",
145-
)
133+
assert_type(rfn.stack_arrays(x), "_nt.Array1D[np.int32]")
146134

147135
z = np.ones((int(2),), [("A", "|S3"), ("B", float)])
148136
zz = np.ones((int(2),), [("A", "|S3"), ("B", np.float64), ("C", np.float64)])
149137
assert_type(
150138
rfn.stack_arrays((z, zz)),
151-
"np.ma.MaskedArray[_nt.Shape, np.dtype[np.void]]",
139+
"_nt.MArray[np.void]",
152140
)
153141

154142

src/numpy-stubs/@test/static/accept/array_constructors.pyi

Lines changed: 85 additions & 85 deletions
Large diffs are not rendered by default.

src/numpy-stubs/@test/static/accept/char.pyi

Lines changed: 70 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -2,46 +2,45 @@ from typing import TypeAlias, assert_type
22

33
import _numtype as _nt
44
import numpy as np
5-
import numpy.typing as npt
65

7-
BytesArray: TypeAlias = npt.NDArray[np.bytes_]
8-
StrArray: TypeAlias = npt.NDArray[np.str_]
6+
BytesArray: TypeAlias = _nt.Array[np.bytes_]
7+
StrArray: TypeAlias = _nt.Array[np.str_]
98
StringArray: TypeAlias = np.ndarray[_nt.Shape, np.dtypes.StringDType]
109

1110
AR_S: BytesArray
1211
AR_U: StrArray
1312
AR_T: StringArray
1413
AR_SUT: BytesArray | StrArray | StringArray
1514

16-
assert_type(np.char.equal(AR_U, AR_U), npt.NDArray[np.bool])
17-
assert_type(np.char.equal(AR_S, AR_S), npt.NDArray[np.bool])
18-
assert_type(np.char.equal(AR_T, AR_T), npt.NDArray[np.bool])
19-
assert_type(np.char.equal(AR_S, AR_U, dtype=np.bool_), npt.NDArray[np.bool])
15+
assert_type(np.char.equal(AR_U, AR_U), _nt.Array[np.bool])
16+
assert_type(np.char.equal(AR_S, AR_S), _nt.Array[np.bool])
17+
assert_type(np.char.equal(AR_T, AR_T), _nt.Array[np.bool])
18+
assert_type(np.char.equal(AR_S, AR_U, dtype=np.bool_), _nt.Array[np.bool])
2019

21-
assert_type(np.char.not_equal(AR_U, AR_U), npt.NDArray[np.bool])
22-
assert_type(np.char.not_equal(AR_S, AR_S), npt.NDArray[np.bool])
23-
assert_type(np.char.not_equal(AR_T, AR_T), npt.NDArray[np.bool])
24-
assert_type(np.char.not_equal(AR_S, AR_U, dtype=np.bool_), npt.NDArray[np.bool])
20+
assert_type(np.char.not_equal(AR_U, AR_U), _nt.Array[np.bool])
21+
assert_type(np.char.not_equal(AR_S, AR_S), _nt.Array[np.bool])
22+
assert_type(np.char.not_equal(AR_T, AR_T), _nt.Array[np.bool])
23+
assert_type(np.char.not_equal(AR_S, AR_U, dtype=np.bool_), _nt.Array[np.bool])
2524

26-
assert_type(np.char.greater_equal(AR_U, AR_U), npt.NDArray[np.bool])
27-
assert_type(np.char.greater_equal(AR_S, AR_S), npt.NDArray[np.bool])
28-
assert_type(np.char.greater_equal(AR_T, AR_T), npt.NDArray[np.bool])
29-
assert_type(np.char.greater_equal(AR_S, AR_U, dtype=np.bool_), npt.NDArray[np.bool])
25+
assert_type(np.char.greater_equal(AR_U, AR_U), _nt.Array[np.bool])
26+
assert_type(np.char.greater_equal(AR_S, AR_S), _nt.Array[np.bool])
27+
assert_type(np.char.greater_equal(AR_T, AR_T), _nt.Array[np.bool])
28+
assert_type(np.char.greater_equal(AR_S, AR_U, dtype=np.bool_), _nt.Array[np.bool])
3029

31-
assert_type(np.char.less_equal(AR_U, AR_U), npt.NDArray[np.bool])
32-
assert_type(np.char.less_equal(AR_S, AR_S), npt.NDArray[np.bool])
33-
assert_type(np.char.less_equal(AR_T, AR_T), npt.NDArray[np.bool])
34-
assert_type(np.char.less_equal(AR_S, AR_U, dtype=np.bool_), npt.NDArray[np.bool])
30+
assert_type(np.char.less_equal(AR_U, AR_U), _nt.Array[np.bool])
31+
assert_type(np.char.less_equal(AR_S, AR_S), _nt.Array[np.bool])
32+
assert_type(np.char.less_equal(AR_T, AR_T), _nt.Array[np.bool])
33+
assert_type(np.char.less_equal(AR_S, AR_U, dtype=np.bool_), _nt.Array[np.bool])
3534

36-
assert_type(np.char.greater(AR_U, AR_U), npt.NDArray[np.bool])
37-
assert_type(np.char.greater(AR_S, AR_S), npt.NDArray[np.bool])
38-
assert_type(np.char.greater(AR_T, AR_T), npt.NDArray[np.bool])
39-
assert_type(np.char.greater(AR_S, AR_U, dtype=np.bool_), npt.NDArray[np.bool])
35+
assert_type(np.char.greater(AR_U, AR_U), _nt.Array[np.bool])
36+
assert_type(np.char.greater(AR_S, AR_S), _nt.Array[np.bool])
37+
assert_type(np.char.greater(AR_T, AR_T), _nt.Array[np.bool])
38+
assert_type(np.char.greater(AR_S, AR_U, dtype=np.bool_), _nt.Array[np.bool])
4039

41-
assert_type(np.char.less(AR_U, AR_U), npt.NDArray[np.bool])
42-
assert_type(np.char.less(AR_S, AR_S), npt.NDArray[np.bool])
43-
assert_type(np.char.less(AR_T, AR_T), npt.NDArray[np.bool])
44-
assert_type(np.char.less(AR_S, AR_U, dtype=np.bool_), npt.NDArray[np.bool])
40+
assert_type(np.char.less(AR_U, AR_U), _nt.Array[np.bool])
41+
assert_type(np.char.less(AR_S, AR_S), _nt.Array[np.bool])
42+
assert_type(np.char.less(AR_T, AR_T), _nt.Array[np.bool])
43+
assert_type(np.char.less(AR_S, AR_U, dtype=np.bool_), _nt.Array[np.bool])
4544

4645
assert_type(np.char.multiply(AR_U, 5), StrArray)
4746
assert_type(np.char.multiply(AR_U, 5), StrArray)
@@ -70,7 +69,7 @@ assert_type(np.char.expandtabs(AR_T), StringArray)
7069

7170
assert_type(np.char.join(AR_U, "_"), StrArray)
7271
assert_type(np.char.join(AR_S, [b"_", b""]), BytesArray)
73-
assert_type(np.char.join(AR_T, "_"), StrArray | StringArray)
72+
assert_type(np.char.join(AR_T, "_"), StrArray | _nt.StringArrayND)
7473

7574
assert_type(np.char.ljust(AR_U, 5), StrArray)
7675
assert_type(np.char.ljust(AR_S, [4, 3, 1], fillchar=[b"a", b"b", b"c"]), BytesArray)
@@ -97,10 +96,10 @@ assert_type(np.char.strip(AR_S, b"_"), BytesArray)
9796
assert_type(np.char.strip(AR_T), StringArray)
9897
assert_type(np.char.strip(AR_T, "_"), StringArray)
9998

100-
assert_type(np.char.count(AR_U, "a", start=[1, 2, 3]), npt.NDArray[np.int_])
101-
assert_type(np.char.count(AR_S, [b"a", b"b", b"c"], end=9), npt.NDArray[np.int_])
102-
assert_type(np.char.count(AR_T, AR_T, start=[1, 2, 3]), npt.NDArray[np.int_])
103-
assert_type(np.char.count(AR_T, ["a", "b", "c"], end=9), npt.NDArray[np.int_])
99+
assert_type(np.char.count(AR_U, "a", start=[1, 2, 3]), _nt.Array[np.int_])
100+
assert_type(np.char.count(AR_S, [b"a", b"b", b"c"], end=9), _nt.Array[np.int_])
101+
assert_type(np.char.count(AR_T, AR_T, start=[1, 2, 3]), _nt.Array[np.int_])
102+
assert_type(np.char.count(AR_T, ["a", "b", "c"], end=9), _nt.Array[np.int_])
104103

105104
assert_type(np.char.partition(AR_U, "\n"), StrArray)
106105
assert_type(np.char.partition(AR_S, [b"a", b"b", b"c"]), BytesArray)
@@ -112,17 +111,17 @@ assert_type(np.char.replace(AR_U, "_", "-"), StrArray)
112111
assert_type(np.char.replace(AR_S, [b"_", b""], [b"a", b"b"]), BytesArray)
113112
assert_type(np.char.replace(AR_T, "_", "-"), StringArray)
114113

115-
assert_type(np.char.split(AR_U, "_"), npt.NDArray[np.object_])
116-
assert_type(np.char.split(AR_S, maxsplit=[1, 2, 3]), npt.NDArray[np.object_])
117-
assert_type(np.char.split(AR_T, "_"), npt.NDArray[np.object_])
114+
assert_type(np.char.split(AR_U, "_"), _nt.Array[np.object_])
115+
assert_type(np.char.split(AR_S, maxsplit=[1, 2, 3]), _nt.Array[np.object_])
116+
assert_type(np.char.split(AR_T, "_"), _nt.Array[np.object_])
118117

119-
assert_type(np.char.rsplit(AR_U, "_"), npt.NDArray[np.object_])
120-
assert_type(np.char.rsplit(AR_S, maxsplit=[1, 2, 3]), npt.NDArray[np.object_])
121-
assert_type(np.char.rsplit(AR_T, "_"), npt.NDArray[np.object_])
118+
assert_type(np.char.rsplit(AR_U, "_"), _nt.Array[np.object_])
119+
assert_type(np.char.rsplit(AR_S, maxsplit=[1, 2, 3]), _nt.Array[np.object_])
120+
assert_type(np.char.rsplit(AR_T, "_"), _nt.Array[np.object_])
122121

123-
assert_type(np.char.splitlines(AR_U), npt.NDArray[np.object_])
124-
assert_type(np.char.splitlines(AR_S, keepends=[True, True, False]), npt.NDArray[np.object_])
125-
assert_type(np.char.splitlines(AR_T), npt.NDArray[np.object_])
122+
assert_type(np.char.splitlines(AR_U), _nt.Array[np.object_])
123+
assert_type(np.char.splitlines(AR_S, keepends=[True, True, False]), _nt.Array[np.object_])
124+
assert_type(np.char.splitlines(AR_T), _nt.Array[np.object_])
126125

127126
assert_type(np.char.lower(AR_U), StrArray)
128127
assert_type(np.char.lower(AR_S), BytesArray)
@@ -148,44 +147,44 @@ assert_type(np.char.zfill(AR_U, 5), StrArray)
148147
assert_type(np.char.zfill(AR_S, [2, 3, 4]), BytesArray)
149148
assert_type(np.char.zfill(AR_T, 5), StringArray)
150149

151-
assert_type(np.char.endswith(AR_U, "a", start=[1, 2, 3]), npt.NDArray[np.bool])
152-
assert_type(np.char.endswith(AR_S, [b"a", b"b", b"c"], end=9), npt.NDArray[np.bool])
153-
assert_type(np.char.endswith(AR_T, "a", start=[1, 2, 3]), npt.NDArray[np.bool])
150+
assert_type(np.char.endswith(AR_U, "a", start=[1, 2, 3]), _nt.Array[np.bool])
151+
assert_type(np.char.endswith(AR_S, [b"a", b"b", b"c"], end=9), _nt.Array[np.bool])
152+
assert_type(np.char.endswith(AR_T, "a", start=[1, 2, 3]), _nt.Array[np.bool])
154153

155-
assert_type(np.char.startswith(AR_U, "a", start=[1, 2, 3]), npt.NDArray[np.bool])
156-
assert_type(np.char.startswith(AR_S, [b"a", b"b", b"c"], end=9), npt.NDArray[np.bool])
157-
assert_type(np.char.startswith(AR_T, "a", start=[1, 2, 3]), npt.NDArray[np.bool])
154+
assert_type(np.char.startswith(AR_U, "a", start=[1, 2, 3]), _nt.Array[np.bool])
155+
assert_type(np.char.startswith(AR_S, [b"a", b"b", b"c"], end=9), _nt.Array[np.bool])
156+
assert_type(np.char.startswith(AR_T, "a", start=[1, 2, 3]), _nt.Array[np.bool])
158157

159-
assert_type(np.char.find(AR_U, "a", start=[1, 2, 3]), npt.NDArray[np.int_])
160-
assert_type(np.char.find(AR_S, [b"a", b"b", b"c"], end=9), npt.NDArray[np.int_])
161-
assert_type(np.char.find(AR_T, "a", start=[1, 2, 3]), npt.NDArray[np.int_])
158+
assert_type(np.char.find(AR_U, "a", start=[1, 2, 3]), _nt.Array[np.int_])
159+
assert_type(np.char.find(AR_S, [b"a", b"b", b"c"], end=9), _nt.Array[np.int_])
160+
assert_type(np.char.find(AR_T, "a", start=[1, 2, 3]), _nt.Array[np.int_])
162161

163-
assert_type(np.char.rfind(AR_U, "a", start=[1, 2, 3]), npt.NDArray[np.int_])
164-
assert_type(np.char.rfind(AR_S, [b"a", b"b", b"c"], end=9), npt.NDArray[np.int_])
165-
assert_type(np.char.rfind(AR_T, "a", start=[1, 2, 3]), npt.NDArray[np.int_])
162+
assert_type(np.char.rfind(AR_U, "a", start=[1, 2, 3]), _nt.Array[np.int_])
163+
assert_type(np.char.rfind(AR_S, [b"a", b"b", b"c"], end=9), _nt.Array[np.int_])
164+
assert_type(np.char.rfind(AR_T, "a", start=[1, 2, 3]), _nt.Array[np.int_])
166165

167-
assert_type(np.char.index(AR_U, "a", start=[1, 2, 3]), npt.NDArray[np.int_])
168-
assert_type(np.char.index(AR_S, [b"a", b"b", b"c"], end=9), npt.NDArray[np.int_])
169-
assert_type(np.char.index(AR_T, "a", start=[1, 2, 3]), npt.NDArray[np.int_])
166+
assert_type(np.char.index(AR_U, "a", start=[1, 2, 3]), _nt.Array[np.int_])
167+
assert_type(np.char.index(AR_S, [b"a", b"b", b"c"], end=9), _nt.Array[np.int_])
168+
assert_type(np.char.index(AR_T, "a", start=[1, 2, 3]), _nt.Array[np.int_])
170169

171-
assert_type(np.char.rindex(AR_U, "a", start=[1, 2, 3]), npt.NDArray[np.int_])
172-
assert_type(np.char.rindex(AR_S, [b"a", b"b", b"c"], end=9), npt.NDArray[np.int_])
173-
assert_type(np.char.rindex(AR_T, "a", start=[1, 2, 3]), npt.NDArray[np.int_])
170+
assert_type(np.char.rindex(AR_U, "a", start=[1, 2, 3]), _nt.Array[np.int_])
171+
assert_type(np.char.rindex(AR_S, [b"a", b"b", b"c"], end=9), _nt.Array[np.int_])
172+
assert_type(np.char.rindex(AR_T, "a", start=[1, 2, 3]), _nt.Array[np.int_])
174173

175-
assert_type(np.char.isdecimal(AR_U), npt.NDArray[np.bool])
176-
assert_type(np.char.isdecimal(AR_T), npt.NDArray[np.bool])
174+
assert_type(np.char.isdecimal(AR_U), _nt.Array[np.bool])
175+
assert_type(np.char.isdecimal(AR_T), _nt.Array[np.bool])
177176

178-
assert_type(np.char.isnumeric(AR_U), npt.NDArray[np.bool])
179-
assert_type(np.char.isnumeric(AR_T), npt.NDArray[np.bool])
177+
assert_type(np.char.isnumeric(AR_U), _nt.Array[np.bool])
178+
assert_type(np.char.isnumeric(AR_T), _nt.Array[np.bool])
180179

181-
assert_type(np.char.isalpha(AR_SUT), npt.NDArray[np.bool])
182-
assert_type(np.char.isalnum(AR_SUT), npt.NDArray[np.bool])
183-
assert_type(np.char.isdigit(AR_SUT), npt.NDArray[np.bool])
184-
assert_type(np.char.islower(AR_SUT), npt.NDArray[np.bool])
185-
assert_type(np.char.isspace(AR_SUT), npt.NDArray[np.bool])
186-
assert_type(np.char.istitle(AR_SUT), npt.NDArray[np.bool])
187-
assert_type(np.char.isupper(AR_SUT), npt.NDArray[np.bool])
188-
assert_type(np.char.str_len(AR_SUT), npt.NDArray[np.int_])
180+
assert_type(np.char.isalpha(AR_SUT), _nt.Array[np.bool])
181+
assert_type(np.char.isalnum(AR_SUT), _nt.Array[np.bool])
182+
assert_type(np.char.isdigit(AR_SUT), _nt.Array[np.bool])
183+
assert_type(np.char.islower(AR_SUT), _nt.Array[np.bool])
184+
assert_type(np.char.isspace(AR_SUT), _nt.Array[np.bool])
185+
assert_type(np.char.istitle(AR_SUT), _nt.Array[np.bool])
186+
assert_type(np.char.isupper(AR_SUT), _nt.Array[np.bool])
187+
assert_type(np.char.str_len(AR_SUT), _nt.Array[np.int_])
189188

190189
assert_type(np.char.array(AR_U), np.char.chararray[tuple[int, ...], np.dtype[np.str_]])
191190
assert_type(np.char.array(AR_S, order="K"), np.char.chararray[tuple[int, ...], np.dtype[np.bytes_]])

0 commit comments

Comments
 (0)