Skip to content

Commit c92d3a1

Browse files
author
Bas van Beek
committed
ENH: Add annotations for the np.rec functions
1 parent b4be004 commit c92d3a1

File tree

1 file changed

+169
-51
lines changed

1 file changed

+169
-51
lines changed

numpy/core/records.pyi

Lines changed: 169 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,183 @@
1-
from typing import List
1+
import os
2+
from typing import (
3+
List,
4+
Sequence,
5+
Any,
6+
TypeVar,
7+
Iterable,
8+
overload,
9+
Tuple,
10+
Protocol,
11+
)
212

313
from numpy import (
414
format_parser as format_parser,
515
record as record,
616
recarray as recarray,
17+
dtype,
18+
generic,
19+
void,
20+
_ByteOrder,
21+
_SupportsBuffer,
22+
)
23+
24+
from numpy.typing import (
25+
ArrayLike,
26+
DTypeLike,
27+
NDArray,
28+
_ShapeLike,
29+
_ArrayLikeVoid_co,
30+
_NestedSequence,
731
)
832

33+
_SCT = TypeVar("_SCT", bound=generic)
34+
35+
_RecArray = recarray[Any, dtype[_SCT]]
36+
37+
class _SupportsReadInto(Protocol):
38+
def seek(self, offset: int, whence: int, /) -> object: ...
39+
def tell(self, /) -> int: ...
40+
def readinto(self, buffer: memoryview, /) -> int: ...
41+
942
__all__: List[str]
1043

44+
@overload
1145
def fromarrays(
12-
arrayList,
13-
dtype=...,
14-
shape=...,
15-
formats=...,
16-
names=...,
17-
titles=...,
18-
aligned=...,
19-
byteorder=...,
20-
): ...
46+
arrayList: Iterable[ArrayLike],
47+
dtype: DTypeLike = ...,
48+
shape: None | _ShapeLike = ...,
49+
formats: None = ...,
50+
names: None = ...,
51+
titles: None = ...,
52+
aligned: bool = ...,
53+
byteorder: None = ...,
54+
) -> _RecArray[Any]: ...
55+
@overload
56+
def fromarrays(
57+
arrayList: Iterable[ArrayLike],
58+
dtype: None = ...,
59+
shape: None | _ShapeLike = ...,
60+
*,
61+
formats: DTypeLike,
62+
names: None | str | Sequence[str] = ...,
63+
titles: None | str | Sequence[str] = ...,
64+
aligned: bool = ...,
65+
byteorder: None | _ByteOrder = ...,
66+
) -> _RecArray[record]: ...
67+
68+
@overload
2169
def fromrecords(
22-
recList,
23-
dtype=...,
24-
shape=...,
25-
formats=...,
26-
names=...,
27-
titles=...,
28-
aligned=...,
29-
byteorder=...,
30-
): ...
70+
recList: _ArrayLikeVoid_co | Tuple[Any, ...] | _NestedSequence[Tuple[Any, ...]],
71+
dtype: DTypeLike = ...,
72+
shape: None | _ShapeLike = ...,
73+
formats: None = ...,
74+
names: None = ...,
75+
titles: None = ...,
76+
aligned: bool = ...,
77+
byteorder: None = ...,
78+
) -> _RecArray[record]: ...
79+
@overload
80+
def fromrecords(
81+
recList: _ArrayLikeVoid_co | Tuple[Any, ...] | _NestedSequence[Tuple[Any, ...]],
82+
dtype: None = ...,
83+
shape: None | _ShapeLike = ...,
84+
*,
85+
formats: DTypeLike,
86+
names: None | str | Sequence[str] = ...,
87+
titles: None | str | Sequence[str] = ...,
88+
aligned: bool = ...,
89+
byteorder: None | _ByteOrder = ...,
90+
) -> _RecArray[record]: ...
91+
92+
@overload
3193
def fromstring(
32-
datastring,
33-
dtype=...,
34-
shape=...,
35-
offset=...,
36-
formats=...,
37-
names=...,
38-
titles=...,
39-
aligned=...,
40-
byteorder=...,
41-
): ...
94+
datastring: _SupportsBuffer,
95+
dtype: DTypeLike,
96+
shape: None | _ShapeLike = ...,
97+
offset: int = ...,
98+
formats: None = ...,
99+
names: None = ...,
100+
titles: None = ...,
101+
aligned: bool = ...,
102+
byteorder: None = ...,
103+
) -> _RecArray[record]: ...
104+
@overload
105+
def fromstring(
106+
datastring: _SupportsBuffer,
107+
dtype: None = ...,
108+
shape: None | _ShapeLike = ...,
109+
offset: int = ...,
110+
*,
111+
formats: DTypeLike,
112+
names: None | str | Sequence[str] = ...,
113+
titles: None | str | Sequence[str] = ...,
114+
aligned: bool = ...,
115+
byteorder: None | _ByteOrder = ...,
116+
) -> _RecArray[record]: ...
117+
118+
@overload
42119
def fromfile(
43-
fd,
44-
dtype=...,
45-
shape=...,
46-
offset=...,
47-
formats=...,
48-
names=...,
49-
titles=...,
50-
aligned=...,
51-
byteorder=...,
52-
): ...
120+
fd: str | bytes | os.PathLike[str] | os.PathLike[bytes] | _SupportsReadInto,
121+
dtype: DTypeLike,
122+
shape: None | _ShapeLike = ...,
123+
offset: int = ...,
124+
formats: None = ...,
125+
names: None = ...,
126+
titles: None = ...,
127+
aligned: bool = ...,
128+
byteorder: None = ...,
129+
) -> _RecArray[Any]: ...
130+
@overload
131+
def fromfile(
132+
fd: str | bytes | os.PathLike[str] | os.PathLike[bytes] | _SupportsReadInto,
133+
dtype: None = ...,
134+
shape: None | _ShapeLike = ...,
135+
offset: int = ...,
136+
*,
137+
formats: DTypeLike,
138+
names: None | str | Sequence[str] = ...,
139+
titles: None | str | Sequence[str] = ...,
140+
aligned: bool = ...,
141+
byteorder: None | _ByteOrder = ...,
142+
) -> _RecArray[record]: ...
143+
144+
@overload
145+
def array(
146+
obj: _SCT | NDArray[_SCT],
147+
dtype: None = ...,
148+
shape: None | _ShapeLike = ...,
149+
offset: int = ...,
150+
formats: None = ...,
151+
names: None = ...,
152+
titles: None = ...,
153+
aligned: bool = ...,
154+
byteorder: None = ...,
155+
copy: bool = ...,
156+
) -> _RecArray[_SCT]: ...
157+
@overload
158+
def array(
159+
obj: ArrayLike,
160+
dtype: DTypeLike,
161+
shape: None | _ShapeLike = ...,
162+
offset: int = ...,
163+
formats: None = ...,
164+
names: None = ...,
165+
titles: None = ...,
166+
aligned: bool = ...,
167+
byteorder: None = ...,
168+
copy: bool = ...,
169+
) -> _RecArray[Any]: ...
170+
@overload
53171
def array(
54-
obj,
55-
dtype=...,
56-
shape=...,
57-
offset=...,
58-
strides=...,
59-
formats=...,
60-
names=...,
61-
titles=...,
62-
aligned=...,
63-
byteorder=...,
64-
copy=...,
65-
): ...
172+
obj: ArrayLike,
173+
dtype: None = ...,
174+
shape: None | _ShapeLike = ...,
175+
offset: int = ...,
176+
*,
177+
formats: DTypeLike,
178+
names: None | str | Sequence[str] = ...,
179+
titles: None | str | Sequence[str] = ...,
180+
aligned: bool = ...,
181+
byteorder: None | _ByteOrder = ...,
182+
copy: bool = ...,
183+
) -> _RecArray[record]: ...

0 commit comments

Comments
 (0)