codekingpro/portable-devtools
114k
1# ruff: noqa: ANN401
2# pyright: reportSelfClsParameterName=false
3from _typeshed import Incomplete, StrOrBytesPath
4from collections.abc import Iterable, Sequence
5from typing import (
6 Any,
7 ClassVar,
8 Literal,
9 Protocol,
10 SupportsIndex,
11 TypeAlias,
12 overload,
13 type_check_only,
14)
15from typing_extensions import Buffer, TypeVar
16
17import numpy as np
18from numpy import _ByteOrder, _OrderKACF
19from numpy._typing import (
20 ArrayLike,
21 DTypeLike,
22 NDArray,
23 _AnyShape,
24 _ArrayLikeVoid_co,
25 _NestedSequence,
26 _Shape,
27 _ShapeLike,
28)
29
30__all__ = [
31 "array",
32 "find_duplicate",
33 "format_parser",
34 "fromarrays",
35 "fromfile",
36 "fromrecords",
37 "fromstring",
38 "recarray",
39 "record",
40]
41
42_T = TypeVar("_T")
43_ScalarT = TypeVar("_ScalarT", bound=np.generic)
44_DTypeT_co = TypeVar("_DTypeT_co", bound=np.dtype, default=np.dtype, covariant=True)
45_ShapeT_co = TypeVar("_ShapeT_co", bound=_Shape, default=_AnyShape, covariant=True)
46
47_RecArray: TypeAlias = recarray[_AnyShape, np.dtype[_ScalarT]]
48
49@type_check_only
50class _SupportsReadInto(Protocol):
51 def seek(self, offset: int, whence: int, /) -> object: ...
52 def tell(self, /) -> int: ...
53 def readinto(self, buffer: memoryview, /) -> int: ...
54
55###
56
57# exported in `numpy.rec`
58class record(np.void): # type: ignore[misc]
59 __name__: ClassVar[Literal["record"]] = "record"
60 __module__: Literal["numpy"] = "numpy"
61
62 def pprint(self) -> str: ...
63
64 def __getattribute__(self, attr: str, /) -> Any: ...
65 def __setattr__(self, attr: str, val: ArrayLike, /) -> None: ...
66
67 @overload
68 def __getitem__(self, key: str | SupportsIndex, /) -> Incomplete: ...
69 @overload
70 def __getitem__(self, key: list[str], /) -> record: ...
71
72# exported in `numpy.rec`
73class recarray(np.ndarray[_ShapeT_co, _DTypeT_co]):
74 __name__: ClassVar[Literal["recarray"]] = "recarray"
75 __module__: Literal["numpy.rec"] = "numpy.rec"
76
77 @overload
78 def __new__(
79 subtype,
80 shape: _ShapeLike,
81 dtype: None = None,
82 buf: Buffer | None = None,
83 offset: SupportsIndex = 0,
84 strides: _ShapeLike | None = None,
85 *,
86 formats: DTypeLike | None,
87 names: str | Sequence[str] | None = None,
88 titles: str | Sequence[str] | None = None,
89 byteorder: _ByteOrder | None = None,
90 aligned: bool = False,
91 order: _OrderKACF = "C",
92 ) -> _RecArray[record]: ...
93 @overload
94 def __new__(
95 subtype,
96 shape: _ShapeLike,
97 dtype: DTypeLike | None,
98 buf: Buffer | None = None,
99 offset: SupportsIndex = 0,
100 strides: _ShapeLike | None = None,
101 formats: None = None,
102 names: None = None,
103 titles: None = None,
104 byteorder: None = None,
105 aligned: Literal[False] = False,
106 order: _OrderKACF = "C",
107 ) -> _RecArray[Incomplete]: ...
108
109 def __getattribute__(self, attr: str, /) -> Any: ...
110 def __setattr__(self, attr: str, val: ArrayLike, /) -> None: ...
111
112 def __array_finalize__(self, /, obj: object) -> None: ...
113
114 #
115 @overload
116 def field(self, /, attr: int | str, val: ArrayLike) -> None: ...
117 @overload
118 def field(self, /, attr: int | str, val: None = None) -> Incomplete: ...
119
120# exported in `numpy.rec`
121class format_parser:
122 dtype: np.dtype[np.void]
123 def __init__(
124 self,
125 /,
126 formats: DTypeLike | None,
127 names: str | Sequence[str] | None,
128 titles: str | Sequence[str] | None,
129 aligned: bool = False,
130 byteorder: _ByteOrder | None = None,
131 ) -> None: ...
132
133# exported in `numpy.rec`
134@overload
135def fromarrays(
136 arrayList: Iterable[ArrayLike],
137 dtype: DTypeLike | None = None,
138 shape: _ShapeLike | None = None,
139 formats: None = None,
140 names: None = None,
141 titles: None = None,
142 aligned: bool = False,
143 byteorder: None = None,
144) -> _RecArray[Any]: ...
145@overload
146def fromarrays(
147 arrayList: Iterable[ArrayLike],
148 dtype: None = None,
149 shape: _ShapeLike | None = None,
150 *,
151 formats: DTypeLike | None,
152 names: str | Sequence[str] | None = None,
153 titles: str | Sequence[str] | None = None,
154 aligned: bool = False,
155 byteorder: _ByteOrder | None = None,
156) -> _RecArray[record]: ...
157
158@overload
159def fromrecords(
160 recList: _ArrayLikeVoid_co | tuple[object, ...] | _NestedSequence[tuple[object, ...]],
161 dtype: DTypeLike | None = None,
162 shape: _ShapeLike | None = None,
163 formats: None = None,
164 names: None = None,
165 titles: None = None,
166 aligned: bool = False,
167 byteorder: None = None,
168) -> _RecArray[record]: ...
169@overload
170def fromrecords(
171 recList: _ArrayLikeVoid_co | tuple[object, ...] | _NestedSequence[tuple[object, ...]],
172 dtype: None = None,
173 shape: _ShapeLike | None = None,
174 *,
175 formats: DTypeLike | None,
176 names: str | Sequence[str] | None = None,
177 titles: str | Sequence[str] | None = None,
178 aligned: bool = False,
179 byteorder: _ByteOrder | None = None,
180) -> _RecArray[record]: ...
181
182# exported in `numpy.rec`
183@overload
184def fromstring(
185 datastring: Buffer,
186 dtype: DTypeLike | None,
187 shape: _ShapeLike | None = None,
188 offset: int = 0,
189 formats: None = None,
190 names: None = None,
191 titles: None = None,
192 aligned: bool = False,
193 byteorder: None = None,
194) -> _RecArray[record]: ...
195@overload
196def fromstring(
197 datastring: Buffer,
198 dtype: None = None,
199 shape: _ShapeLike | None = None,
200 offset: int = 0,
201 *,
202 formats: DTypeLike | None,
203 names: str | Sequence[str] | None = None,
204 titles: str | Sequence[str] | None = None,
205 aligned: bool = False,
206 byteorder: _ByteOrder | None = None,
207) -> _RecArray[record]: ...
208
209# exported in `numpy.rec`
210@overload
211def fromfile(
212 fd: StrOrBytesPath | _SupportsReadInto,
213 dtype: DTypeLike | None,
214 shape: _ShapeLike | None = None,
215 offset: int = 0,
216 formats: None = None,
217 names: None = None,
218 titles: None = None,
219 aligned: bool = False,
220 byteorder: None = None,
221) -> _RecArray[Any]: ...
222@overload
223def fromfile(
224 fd: StrOrBytesPath | _SupportsReadInto,
225 dtype: None = None,
226 shape: _ShapeLike | None = None,
227 offset: int = 0,
228 *,
229 formats: DTypeLike | None,
230 names: str | Sequence[str] | None = None,
231 titles: str | Sequence[str] | None = None,
232 aligned: bool = False,
233 byteorder: _ByteOrder | None = None,
234) -> _RecArray[record]: ...
235
236# exported in `numpy.rec`
237@overload
238def array(
239 obj: _ScalarT | NDArray[_ScalarT],
240 dtype: None = None,
241 shape: _ShapeLike | None = None,
242 offset: int = 0,
243 strides: tuple[int, ...] | None = None,
244 formats: None = None,
245 names: None = None,
246 titles: None = None,
247 aligned: bool = False,
248 byteorder: None = None,
249 copy: bool = True,
250) -> _RecArray[_ScalarT]: ...
251@overload
252def array(
253 obj: ArrayLike,
254 dtype: DTypeLike | None,
255 shape: _ShapeLike | None = None,
256 offset: int = 0,
257 strides: tuple[int, ...] | None = None,
258 formats: None = None,
259 names: None = None,
260 titles: None = None,
261 aligned: bool = False,
262 byteorder: None = None,
263 copy: bool = True,
264) -> _RecArray[Any]: ...
265@overload
266def array(
267 obj: ArrayLike,
268 dtype: None = None,
269 shape: _ShapeLike | None = None,
270 offset: int = 0,
271 strides: tuple[int, ...] | None = None,
272 *,
273 formats: DTypeLike | None,
274 names: str | Sequence[str] | None = None,
275 titles: str | Sequence[str] | None = None,
276 aligned: bool = False,
277 byteorder: _ByteOrder | None = None,
278 copy: bool = True,
279) -> _RecArray[record]: ...
280@overload
281def array(
282 obj: None,
283 dtype: DTypeLike | None,
284 shape: _ShapeLike,
285 offset: int = 0,
286 strides: tuple[int, ...] | None = None,
287 formats: None = None,
288 names: None = None,
289 titles: None = None,
290 aligned: bool = False,
291 byteorder: None = None,
292 copy: bool = True,
293) -> _RecArray[Any]: ...
294@overload
295def array(
296 obj: None,
297 dtype: None = None,
298 *,
299 shape: _ShapeLike,
300 offset: int = 0,
301 strides: tuple[int, ...] | None = None,
302 formats: DTypeLike | None,
303 names: str | Sequence[str] | None = None,
304 titles: str | Sequence[str] | None = None,
305 aligned: bool = False,
306 byteorder: _ByteOrder | None = None,
307 copy: bool = True,
308) -> _RecArray[record]: ...
309@overload
310def array(
311 obj: _SupportsReadInto,
312 dtype: DTypeLike | None,
313 shape: _ShapeLike | None = None,
314 offset: int = 0,
315 strides: tuple[int, ...] | None = None,
316 formats: None = None,
317 names: None = None,
318 titles: None = None,
319 aligned: bool = False,
320 byteorder: None = None,
321 copy: bool = True,
322) -> _RecArray[Any]: ...
323@overload
324def array(
325 obj: _SupportsReadInto,
326 dtype: None = None,
327 shape: _ShapeLike | None = None,
328 offset: int = 0,
329 strides: tuple[int, ...] | None = None,
330 *,
331 formats: DTypeLike | None,
332 names: str | Sequence[str] | None = None,
333 titles: str | Sequence[str] | None = None,
334 aligned: bool = False,
335 byteorder: _ByteOrder | None = None,
336 copy: bool = True,
337) -> _RecArray[record]: ...
338
339# exported in `numpy.rec`
340def find_duplicate(list: Iterable[_T]) -> list[_T]: ...
341 