1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
| import io
| from typing import Any, TypeAlias, assert_type
|
| import numpy as np
| import numpy.typing as npt
|
| _RecArray: TypeAlias = np.recarray[tuple[Any, ...], np.dtype[np.record]]
|
| AR_i8: npt.NDArray[np.int64]
| REC_AR_V: _RecArray
| AR_LIST: list[npt.NDArray[np.int64]]
|
| record: np.record
| file_obj: io.BufferedIOBase
|
| assert_type(np.rec.format_parser(
| formats=[np.float64, np.int64, np.bool],
| names=["f8", "i8", "?"],
| titles=None,
| aligned=True,
| ), np.rec.format_parser)
| assert_type(np.rec.format_parser.dtype, np.dtype[np.void])
|
| assert_type(record.field_a, Any)
| assert_type(record.field_b, Any)
| assert_type(record["field_a"], Any)
| assert_type(record["field_b"], Any)
| assert_type(record.pprint(), str)
| record.field_c = 5
|
| assert_type(REC_AR_V.field(0), Any)
| assert_type(REC_AR_V.field("field_a"), Any)
| assert_type(REC_AR_V.field(0, AR_i8), None)
| assert_type(REC_AR_V.field("field_a", AR_i8), None)
| assert_type(REC_AR_V["field_a"], npt.NDArray[Any])
| assert_type(REC_AR_V.field_a, Any)
| assert_type(REC_AR_V.__array_finalize__(object()), None)
|
| assert_type(
| np.recarray(
| shape=(10, 5),
| formats=[np.float64, np.int64, np.bool],
| order="K",
| byteorder="|",
| ),
| _RecArray,
| )
|
| assert_type(
| np.recarray(
| shape=(10, 5),
| dtype=[("f8", np.float64), ("i8", np.int64)],
| strides=(5, 5),
| ),
| np.recarray,
| )
|
| assert_type(np.rec.fromarrays(AR_LIST), np.recarray)
| assert_type(
| np.rec.fromarrays(AR_LIST, dtype=np.int64),
| np.recarray,
| )
| assert_type(
| np.rec.fromarrays(
| AR_LIST,
| formats=[np.int64, np.float64],
| names=["i8", "f8"]
| ),
| _RecArray,
| )
|
| assert_type(
| np.rec.fromrecords((1, 1.5)),
| _RecArray
| )
|
| assert_type(
| np.rec.fromrecords(
| [(1, 1.5)],
| dtype=[("i8", np.int64), ("f8", np.float64)],
| ),
| _RecArray,
| )
|
| assert_type(
| np.rec.fromrecords(
| REC_AR_V,
| formats=[np.int64, np.float64],
| names=["i8", "f8"]
| ),
| _RecArray,
| )
|
| assert_type(
| np.rec.fromstring(
| b"(1, 1.5)",
| dtype=[("i8", np.int64), ("f8", np.float64)],
| ),
| _RecArray,
| )
|
| assert_type(
| np.rec.fromstring(
| REC_AR_V,
| formats=[np.int64, np.float64],
| names=["i8", "f8"]
| ),
| _RecArray,
| )
|
| assert_type(
| np.rec.fromfile(
| "test_file.txt",
| dtype=[("i8", np.int64), ("f8", np.float64)],
| ),
| np.recarray,
| )
|
| assert_type(
| np.rec.fromfile(
| file_obj,
| formats=[np.int64, np.float64],
| names=["i8", "f8"]
| ),
| _RecArray,
| )
|
| assert_type(np.rec.array(AR_i8), np.recarray[tuple[Any, ...], np.dtype[np.int64]])
|
| assert_type(
| np.rec.array([(1, 1.5)], dtype=[("i8", np.int64), ("f8", np.float64)]),
| np.recarray,
| )
|
| assert_type(
| np.rec.array(
| [(1, 1.5)],
| formats=[np.int64, np.float64],
| names=["i8", "f8"]
| ),
| _RecArray,
| )
|
| assert_type(
| np.rec.array(
| None,
| dtype=np.float64,
| shape=(10, 3),
| ),
| np.recarray,
| )
|
| assert_type(
| np.rec.array(
| None,
| formats=[np.int64, np.float64],
| names=["i8", "f8"],
| shape=(10, 3),
| ),
| _RecArray,
| )
|
| assert_type(
| np.rec.array(file_obj, dtype=np.float64),
| np.recarray,
| )
|
| assert_type(
| np.rec.array(file_obj, formats=[np.int64, np.float64], names=["i8", "f8"]),
| _RecArray,
| )
|
|