Skip to content

Commit 9565ddf

Browse files
committed
🎨 replace npt.NDArray with _nt.Array in the tests
1 parent 4a6bfd0 commit 9565ddf

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+1636
-1662
lines changed

‎src/numpy-stubs/@test/runtime/legacy/lib_user_array.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@
1313
N = 10_000
1414
W = H = int(N**0.5)
1515

16-
a: np.ndarray[_nt.Shape2, np.dtype[np.int32]]
17-
ua: container[_nt.Shape2, np.dtype[np.int32]]
16+
a: _nt.Array2D[np.int32]
17+
ua: container[_nt.Rank2, np.dtype[np.int32]]
1818

1919
a = np.arange(N, dtype=np.int32).reshape(W, H)
2020
ua = container(a)
2121

22-
ua_small: container[_nt.Shape2, np.dtype[np.int32]] = ua[:3, :5]
22+
ua_small: container[_nt.Rank2, np.dtype[np.int32]] = ua[:3, :5]
2323
ua_small[0, 0] = 10
2424

25-
ua_bool: container[_nt.Shape2, np.dtype[np.bool]] = ua_small > 1
25+
ua_bool: container[_nt.Rank2, np.dtype[np.bool]] = ua_small > 1
2626

27-
# shape: tuple[int, int] = np.shape(ua)
27+
shape: tuple[int, int] = np.shape(ua)

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

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
"""These tests are based on the doctests from `numpy/lib/recfunctions.py`."""
22

3+
from __future__ import annotations
4+
35
from typing import TYPE_CHECKING, Any, assert_type
46

57
import numpy as np
6-
import numpy.typing as npt
78
from numpy.lib import recfunctions as rfn
89

910
if TYPE_CHECKING:
10-
import _numtype as _nt # noqa: F401, PLC2701
11+
import _numtype as _nt
1112

1213

1314
def test_recursive_fill_fields() -> None:
14-
a: npt.NDArray[np.void] = np.array(
15+
a: _nt.Array[np.void] = np.array(
1516
[(1, 10.0), (2, 20.0)],
1617
dtype=[("A", np.int64), ("B", np.float64)],
1718
)
@@ -101,13 +102,13 @@ def test_repack_fields() -> None:
101102

102103
def test_structured_to_unstructured() -> None:
103104
a = np.zeros(4, dtype=[("a", "i4"), ("b", "f4,u2"), ("c", "f4", 2)])
104-
assert_type(rfn.structured_to_unstructured(a), npt.NDArray[Any])
105+
assert_type(rfn.structured_to_unstructured(a), "_nt.Array")
105106

106107

107108
def unstructured_to_structured() -> None:
108109
dt: np.dtype[np.void] = np.dtype([("a", "i4"), ("b", "f4,u2"), ("c", "f4", 2)])
109110
a = np.arange(20, dtype=np.int32).reshape((4, 5))
110-
assert_type(rfn.unstructured_to_structured(a, dt), npt.NDArray[np.void])
111+
assert_type(rfn.unstructured_to_structured(a, dt), "_nt.Array[np.void]")
111112

112113

113114
def test_apply_along_fields() -> None:
@@ -134,21 +135,15 @@ def test_stack_arrays() -> None:
134135

135136
z = np.ones((int(2),), [("A", "|S3"), ("B", float)])
136137
zz = np.ones((int(2),), [("A", "|S3"), ("B", np.float64), ("C", np.float64)])
137-
assert_type(
138-
rfn.stack_arrays((z, zz)),
139-
"_nt.MArray[np.void]",
140-
)
138+
assert_type(rfn.stack_arrays((z, zz)), "_nt.MArray[np.void]")
141139

142140

143141
def test_find_duplicates() -> None:
144142
ndtype = np.dtype([("a", int)])
145143

146144
a = np.ma.ones(7, mask=[0, 0, 1, 0, 0, 0, 1]).view(ndtype)
147-
assert_type(rfn.find_duplicates(a), np.ma.MaskedArray[Any, np.dtype[np.void]])
145+
assert_type(rfn.find_duplicates(a), "_nt.MArray[np.void, Any]")
148146
assert_type(
149147
rfn.find_duplicates(a, ignoremask=True, return_index=True),
150-
tuple[
151-
np.ma.MaskedArray[Any, np.dtype[np.void]],
152-
np.ndarray[Any, np.dtype[np.int_]],
153-
],
148+
"tuple[_nt.MArray[np.void, Any], _nt.Array[np.intp, Any]]",
154149
)

‎src/numpy-stubs/@test/static/accept/arithmetic.pyi

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import datetime as dt
2-
from typing import Any, assert_type
2+
from typing import assert_type
33

4+
import _numtype as _nt
45
import numpy as np
5-
import numpy.typing as npt
66

77
i: int
88
i8: np.int64
@@ -18,7 +18,7 @@ m8_int: np.timedelta64[int]
1818
m8_delta: np.timedelta64[dt.timedelta]
1919
delta: dt.timedelta
2020

21-
AR_Any: npt.NDArray[Any]
21+
AR_Any: _nt.Array
2222

2323
# Time structures
2424

@@ -59,4 +59,4 @@ assert_type(m8_delta.__divmod__(delta), tuple[int, dt.timedelta])
5959

6060
# Any
6161

62-
assert_type(AR_Any + 2, npt.NDArray[Any])
62+
assert_type(AR_Any + 2, _nt.Array)

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

Lines changed: 153 additions & 153 deletions
Large diffs are not rendered by default.
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
from collections.abc import Mapping
22
from typing import Any, SupportsIndex, assert_type
33

4+
import _numtype as _nt
45
import numpy as np
5-
import numpy.typing as npt
66

77
def mode_func(
8-
ar: npt.NDArray[np.number],
8+
ar: _nt.Array[np.number],
99
width: tuple[int, int],
1010
iaxis: SupportsIndex,
1111
kwargs: Mapping[str, Any],
1212
) -> None: ...
1313

14-
AR_i8: npt.NDArray[np.int64]
15-
AR_f8: npt.NDArray[np.float64]
14+
AR_i8: _nt.Array[np.int64]
15+
AR_f8: _nt.Array[np.float64]
1616
AR_LIKE: list[int]
1717

18-
assert_type(np.pad(AR_i8, (2, 3), "constant"), npt.NDArray[np.int64])
19-
assert_type(np.pad(AR_LIKE, (2, 3), "constant"), npt.NDArray[Any])
18+
assert_type(np.pad(AR_i8, (2, 3), "constant"), _nt.Array[np.int64])
19+
assert_type(np.pad(AR_LIKE, (2, 3), "constant"), _nt.Array)
2020

21-
assert_type(np.pad(AR_f8, (2, 3), mode_func), npt.NDArray[np.float64])
22-
assert_type(np.pad(AR_f8, (2, 3), mode_func, a=1, b=2), npt.NDArray[np.float64])
21+
assert_type(np.pad(AR_f8, (2, 3), mode_func), _nt.Array[np.float64])
22+
assert_type(np.pad(AR_f8, (2, 3), mode_func, a=1, b=2), _nt.Array[np.float64])

‎src/numpy-stubs/@test/static/accept/arrayprint.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import contextlib
22
from collections.abc import Callable
33
from typing import assert_type
44

5+
import _numtype as _nt
56
import numpy as np
6-
import numpy.typing as npt
77
from numpy._core.arrayprint import _FormatOptions
88

9-
AR: npt.NDArray[np.int64]
9+
AR: _nt.Array[np.int64]
1010
func_float: Callable[[np.floating], str]
1111
func_int: Callable[[np.integer], str]
1212

‎src/numpy-stubs/@test/static/accept/arrayterator.pyi

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
from collections.abc import Generator
22
from typing import assert_type
33

4+
import _numtype as _nt
45
import numpy as np
5-
import numpy.typing as npt
66

7-
AR_i8: npt.NDArray[np.int64]
7+
AR_i8: _nt.Array[np.int64]
88
ar_iter: np.lib.Arrayterator[tuple[int, ...], np.dtype[np.int64]]
99

1010
###
1111

12-
assert_type(ar_iter.var, npt.NDArray[np.int64])
12+
assert_type(ar_iter.var, _nt.Array[np.int64])
1313
assert_type(ar_iter.buf_size, int | None)
1414
assert_type(ar_iter.start, list[int])
1515
assert_type(ar_iter.stop, list[int])
1616
assert_type(ar_iter.step, list[int])
1717
assert_type(ar_iter.shape, tuple[int, ...])
1818
assert_type(ar_iter.flat, Generator[np.int64, None, None])
1919

20-
assert_type(ar_iter.__array__(), npt.NDArray[np.int64])
20+
assert_type(ar_iter.__array__(), _nt.Array[np.int64])
2121

2222
for i in ar_iter:
23-
assert_type(i, npt.NDArray[np.int64])
23+
assert_type(i, _nt.Array[np.int64])
2424

2525
assert_type(ar_iter[0], np.lib.Arrayterator[tuple[int, ...], np.dtype[np.int64]])
2626
assert_type(ar_iter[...], np.lib.Arrayterator[tuple[int, ...], np.dtype[np.int64]])

0 commit comments

Comments
 (0)