@@ -5,16 +5,32 @@ import numpy.typing as npt
5
5
6
6
from typing_extensions import assert_type
7
7
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_ ]
9
14
10
15
# 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...
15
26
16
27
# 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 ]]])
18
34
19
35
# itemset does not return a value
20
36
# tostring is pretty simple
@@ -24,34 +40,34 @@ assert_type(nd.tolist(), Any)
24
40
# dumps is pretty simple
25
41
26
42
# 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 ])
34
50
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 ])
36
52
37
53
# 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_ ])
40
56
41
57
# 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_ ])
44
60
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 ])
49
65
50
66
# 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 ])
55
71
56
72
# setflags does not return a value
57
73
# fill does not return a value
0 commit comments