11"""These tests are based on the doctests from `numpy/lib/recfunctions.py`."""
22
3- from typing import Any
3+ from typing import TYPE_CHECKING , Any
44from typing_extensions import assert_type
55
66import numpy as np
77import numpy .typing as npt
88from numpy .lib import recfunctions as rfn
99
10+ if TYPE_CHECKING :
11+ import _numtype as _nt # noqa: F401, PLC2701
12+
1013
1114def test_recursive_fill_fields () -> None :
1215 a : npt .NDArray [np .void ] = np .array (
@@ -15,7 +18,7 @@ def test_recursive_fill_fields() -> None:
1518 )
1619 b = np .zeros ((int (3 ),), dtype = a .dtype )
1720 out = rfn .recursive_fill_fields (a , b )
18- assert_type (out , np .ndarray [tuple [ int ] , np .dtype [np .void ]])
21+ assert_type (out , " np.ndarray[_nt.Shape1 , np.dtype[np.void]]" )
1922
2023
2124def test_get_names () -> None :
@@ -57,7 +60,7 @@ def test_merge_arrays() -> None:
5760 np .ones ((int (2 ),), np .int_ ),
5861 np .ones ((int (3 ),), np .float64 ),
5962 )),
60- np .recarray [tuple [ int ] , np .dtype [np .void ]],
63+ " np.recarray[_nt.Shape1 , np.dtype[np.void]]" ,
6164 )
6265
6366
@@ -67,15 +70,15 @@ def test_drop_fields() -> None:
6770
6871 assert_type (
6972 rfn .drop_fields (a , "a" ),
70- np .ndarray [tuple [ int ] , np .dtype [np .void ]],
73+ " np.ndarray[_nt.Shape1 , np.dtype[np.void]]" ,
7174 )
7275 assert_type (
7376 rfn .drop_fields (a , "a" , asrecarray = True ),
74- np .rec .recarray [tuple [ int ] , np .dtype [np .void ]],
77+ " np.rec.recarray[_nt.Shape1 , np.dtype[np.void]]" ,
7578 )
7679 assert_type (
7780 rfn .rec_drop_fields (a , "a" ),
78- np .rec .recarray [tuple [ int ] , np .dtype [np .void ]],
81+ " np.rec.recarray[_nt.Shape1 , np.dtype[np.void]]" ,
7982 )
8083
8184
@@ -85,7 +88,7 @@ def test_rename_fields() -> None:
8588
8689 assert_type (
8790 rfn .rename_fields (a , {"a" : "A" , "b_b" : "B_B" }),
88- np .ndarray [tuple [ int ] , np .dtype [np .void ]],
91+ " np.ndarray[_nt.Shape1 , np.dtype[np.void]]" ,
8992 )
9093
9194
@@ -96,7 +99,7 @@ def test_repack_fields() -> None:
9699 assert_type (rfn .repack_fields (dt .type (0 )), np .void )
97100 assert_type (
98101 rfn .repack_fields (np .ones ((3 ,), dtype = dt )),
99- np .ndarray [tuple [ int ] , np .dtype [np .void ]],
102+ " np.ndarray[_nt.Shape1 , np.dtype[np.void]]" ,
100103 )
101104
102105
@@ -115,38 +118,38 @@ def test_apply_along_fields() -> None:
115118 b = np .ones (4 , dtype = [("x" , "i4" ), ("y" , "f4" ), ("z" , "f8" )])
116119 assert_type (
117120 rfn .apply_along_fields (np .mean , b ),
118- np .ndarray [tuple [ int ] , np .dtype [np .void ]],
121+ " np.ndarray[_nt.Shape1 , np.dtype[np.void]]" ,
119122 )
120123
121124
122125def test_assign_fields_by_name () -> None :
123126 b = np .ones (4 , dtype = [("x" , "i4" ), ("y" , "f4" ), ("z" , "f8" )])
124127 assert_type (
125128 rfn .apply_along_fields (np .mean , b ),
126- np .ndarray [tuple [ int ] , np .dtype [np .void ]],
129+ " np.ndarray[_nt.Shape1 , np.dtype[np.void]]" ,
127130 )
128131
129132
130133def test_require_fields () -> None :
131134 a = np .ones (4 , dtype = [("a" , "i4" ), ("b" , "f8" ), ("c" , "u1" )])
132135 assert_type (
133136 rfn .require_fields (a , [("b" , "f4" ), ("c" , "u1" )]),
134- np .ndarray [tuple [ int ] , np .dtype [np .void ]],
137+ " np.ndarray[_nt.Shape1 , np.dtype[np.void]]" ,
135138 )
136139
137140
138141def test_stack_arrays () -> None :
139142 x = np .zeros ((int (2 ),), np .int32 )
140143 assert_type (
141144 rfn .stack_arrays (x ),
142- np .ndarray [tuple [ int ] , np .dtype [np .int32 ]],
145+ " np.ndarray[_nt.Shape1 , np.dtype[np.int32]]" ,
143146 )
144147
145148 z = np .ones ((int (2 ),), [("A" , "|S3" ), ("B" , float )])
146149 zz = np .ones ((int (2 ),), [("A" , "|S3" ), ("B" , np .float64 ), ("C" , np .float64 )])
147150 assert_type (
148151 rfn .stack_arrays ((z , zz )),
149- np .ma .MaskedArray [tuple [ int , ...] , np .dtype [np .void ]],
152+ " np.ma.MaskedArray[_nt.Shape , np.dtype[np.void]]" ,
150153 )
151154
152155
0 commit comments