11"""These tests are based on the doctests from `numpy/lib/recfunctions.py`."""
22
3+ from __future__ import annotations
4+
35from typing import TYPE_CHECKING , Any , assert_type
46
57import numpy as np
6- import numpy .typing as npt
78from numpy .lib import recfunctions as rfn
89
910if TYPE_CHECKING :
10- import _numtype as _nt # noqa: F401, PLC2701
11+ import _numtype as _nt
1112
1213
1314def 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
102103def 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
107108def 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
113114def 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
143141def 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 )
0 commit comments