@@ -5,16 +5,32 @@ import numpy.typing as npt
55
66from typing_extensions import assert_type
77
8- nd : npt .NDArray [np .int_ ]
8+ b1_0d : np .ndarray [tuple [()], np .dtype [np .bool ]]
9+ u2_1d : np .ndarray [tuple [int ], np .dtype [np .uint16 ]]
10+ i4_2d : np .ndarray [tuple [int , int ], np .dtype [np .int32 ]]
11+ f8_3d : np .ndarray [tuple [int , int , int ], np .dtype [np .float64 ]]
12+ cG_4d : np .ndarray [tuple [int , int , int , int ], np .dtype [np .clongdouble ]]
13+ i0_nd : npt .NDArray [np .int_ ]
914
1015# item
11- assert_type (nd .item (), int )
12- assert_type (nd .item (1 ), int )
13- assert_type (nd .item (0 , 1 ), int )
14- assert_type (nd .item ((0 , 1 )), int )
16+ assert_type (i0_nd .item (), int )
17+ assert_type (i0_nd .item (1 ), int )
18+ assert_type (i0_nd .item (0 , 1 ), int )
19+ assert_type (i0_nd .item ((0 , 1 )), int )
20+
21+ assert_type (b1_0d .item (()), bool )
22+ assert_type (u2_1d .item ((0 ,)), int )
23+ assert_type (i4_2d .item (- 1 , 2 ), int )
24+ assert_type (f8_3d .item (2 , 1 , - 1 ), float )
25+ assert_type (cG_4d .item (- 0xEd_fed_Deb_a_dead_bee ), complex ) # c'mon Ed, we talked about this...
1526
1627# tolist
17- assert_type (nd .tolist (), Any )
28+ assert_type (b1_0d .tolist (), bool )
29+ assert_type (u2_1d .tolist (), list [int ])
30+ assert_type (i4_2d .tolist (), list [list [int ]])
31+ assert_type (f8_3d .tolist (), list [list [list [float ]]])
32+ assert_type (cG_4d .tolist (), complex | list [complex ] | list [list [complex ]] | list [list [list [Any ]]])
33+ assert_type (i0_nd .tolist (), int | list [int ] | list [list [int ]] | list [list [list [Any ]]])
1834
1935# itemset does not return a value
2036# tostring is pretty simple
@@ -24,34 +40,34 @@ assert_type(nd.tolist(), Any)
2440# dumps is pretty simple
2541
2642# astype
27- assert_type (nd .astype ("float" ), npt .NDArray [Any ])
28- assert_type (nd .astype (float ), npt .NDArray [Any ])
29- assert_type (nd .astype (np .float64 ), npt .NDArray [np .float64 ])
30- assert_type (nd .astype (np .float64 , "K" ), npt .NDArray [np .float64 ])
31- assert_type (nd .astype (np .float64 , "K" , "unsafe" ), npt .NDArray [np .float64 ])
32- assert_type (nd .astype (np .float64 , "K" , "unsafe" , True ), npt .NDArray [np .float64 ])
33- assert_type (nd .astype (np .float64 , "K" , "unsafe" , True , True ), npt .NDArray [np .float64 ])
43+ assert_type (i0_nd .astype ("float" ), npt .NDArray [Any ])
44+ assert_type (i0_nd .astype (float ), npt .NDArray [Any ])
45+ assert_type (i0_nd .astype (np .float64 ), npt .NDArray [np .float64 ])
46+ assert_type (i0_nd .astype (np .float64 , "K" ), npt .NDArray [np .float64 ])
47+ assert_type (i0_nd .astype (np .float64 , "K" , "unsafe" ), npt .NDArray [np .float64 ])
48+ assert_type (i0_nd .astype (np .float64 , "K" , "unsafe" , True ), npt .NDArray [np .float64 ])
49+ assert_type (i0_nd .astype (np .float64 , "K" , "unsafe" , True , True ), npt .NDArray [np .float64 ])
3450
35- assert_type (np .astype (nd , np .float64 ), npt .NDArray [np .float64 ])
51+ assert_type (np .astype (i0_nd , np .float64 ), npt .NDArray [np .float64 ])
3652
3753# byteswap
38- assert_type (nd .byteswap (), npt .NDArray [np .int_ ])
39- assert_type (nd .byteswap (True ), npt .NDArray [np .int_ ])
54+ assert_type (i0_nd .byteswap (), npt .NDArray [np .int_ ])
55+ assert_type (i0_nd .byteswap (True ), npt .NDArray [np .int_ ])
4056
4157# copy
42- assert_type (nd .copy (), npt .NDArray [np .int_ ])
43- assert_type (nd .copy ("C" ), npt .NDArray [np .int_ ])
58+ assert_type (i0_nd .copy (), npt .NDArray [np .int_ ])
59+ assert_type (i0_nd .copy ("C" ), npt .NDArray [np .int_ ])
4460
45- assert_type (nd .view (), npt .NDArray [np .int_ ])
46- assert_type (nd .view (np .float64 ), npt .NDArray [np .float64 ])
47- assert_type (nd .view (float ), npt .NDArray [Any ])
48- assert_type (nd .view (np .float64 , np .matrix ), np .matrix [tuple [int , int ], Any ])
61+ assert_type (i0_nd .view (), npt .NDArray [np .int_ ])
62+ assert_type (i0_nd .view (np .float64 ), npt .NDArray [np .float64 ])
63+ assert_type (i0_nd .view (float ), npt .NDArray [Any ])
64+ assert_type (i0_nd .view (np .float64 , np .matrix ), np .matrix [tuple [int , int ], Any ])
4965
5066# getfield
51- assert_type (nd .getfield ("float" ), npt .NDArray [Any ])
52- assert_type (nd .getfield (float ), npt .NDArray [Any ])
53- assert_type (nd .getfield (np .float64 ), npt .NDArray [np .float64 ])
54- assert_type (nd .getfield (np .float64 , 8 ), npt .NDArray [np .float64 ])
67+ assert_type (i0_nd .getfield ("float" ), npt .NDArray [Any ])
68+ assert_type (i0_nd .getfield (float ), npt .NDArray [Any ])
69+ assert_type (i0_nd .getfield (np .float64 ), npt .NDArray [np .float64 ])
70+ assert_type (i0_nd .getfield (np .float64 , 8 ), npt .NDArray [np .float64 ])
5571
5672# setflags does not return a value
5773# fill does not return a value
0 commit comments