File size: 9,567 Bytes
17c6d62
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
import types
import zipfile
from collections.abc import Callable, Collection, Iterable, Iterator, Mapping, Sequence
from re import Pattern
from typing import IO, Any, ClassVar, Generic, Protocol, TypeAlias, overload, type_check_only
from typing import Literal as L

from _typeshed import StrOrBytesPath, StrPath, SupportsKeysAndGetItem, SupportsRead, SupportsWrite
from typing_extensions import Self, TypeVar, deprecated, override

import numpy as np
from numpy._core.multiarray import packbits, unpackbits
from numpy._typing import ArrayLike, DTypeLike, NDArray, _DTypeLike, _SupportsArrayFunc
from numpy.ma.mrecords import MaskedRecords

from ._datasource import DataSource as DataSource

__all__ = [
    "fromregex",
    "genfromtxt",
    "load",
    "loadtxt",
    "packbits",
    "save",
    "savetxt",
    "savez",
    "savez_compressed",
    "unpackbits",
]

_T_co = TypeVar("_T_co", covariant=True)
_SCT = TypeVar("_SCT", bound=np.generic)
_SCT_co = TypeVar("_SCT_co", bound=np.generic, default=Any, covariant=True)

_FName: TypeAlias = StrPath | Iterable[str] | Iterable[bytes]
_FNameRead: TypeAlias = StrPath | SupportsRead[str] | SupportsRead[bytes]
_FNameWriteBytes: TypeAlias = StrPath | SupportsWrite[bytes]
_FNameWrite: TypeAlias = _FNameWriteBytes | SupportsWrite[bytes]

@type_check_only
class _SupportsReadSeek(SupportsRead[_T_co], Protocol[_T_co]):
    def seek(self, offset: int, whence: int, /) -> object: ...

class BagObj(Generic[_T_co]):
    def __init__(self, /, obj: SupportsKeysAndGetItem[str, _T_co]) -> None: ...
    def __getattribute__(self, key: str, /) -> _T_co: ...
    def __dir__(self) -> list[str]: ...

class NpzFile(Mapping[str, NDArray[_SCT_co]]):
    _MAX_REPR_ARRAY_COUNT: ClassVar[int] = 5

    zip: zipfile.ZipFile
    fid: IO[str] | None
    files: list[str]
    allow_pickle: bool
    pickle_kwargs: Mapping[str, Any] | None
    f: BagObj[NpzFile[_SCT_co]]

    #
    def __init__(

        self,

        /,

        fid: IO[Any],

        own_fid: bool = False,

        allow_pickle: bool = False,

        pickle_kwargs: Mapping[str, object] | None = None,

        *,

        max_header_size: int = 10_000,

    ) -> None: ...
    def __del__(self) -> None: ...
    def __enter__(self) -> Self: ...
    def __exit__(self, cls: type[BaseException] | None, e: BaseException | None, tb: types.TracebackType | None, /) -> None: ...
    @override
    def __len__(self) -> int: ...
    @override
    def __iter__(self) -> Iterator[str]: ...
    @override
    def __getitem__(self, key: str, /) -> NDArray[_SCT_co]: ...
    def close(self) -> None: ...

# NOTE: Returns a `NpzFile` if file is a zip file;
# returns an `ndarray`/`memmap` otherwise
def load(

    file: StrOrBytesPath | _SupportsReadSeek[bytes],

    mmap_mode: L["r+", "r", "w+", "c"] | None = None,

    allow_pickle: bool = False,

    fix_imports: bool = True,

    encoding: L["ASCII", "latin1", "bytes"] = "ASCII",

    *,

    max_header_size: int = 10_000,

) -> Any: ...

@overload
def save(file: _FNameWriteBytes, arr: ArrayLike, allow_pickle: bool = True) -> None: ...
@overload
@deprecated("The 'fix_imports' flag is deprecated in NumPy 2.1.")
def save(file: _FNameWriteBytes, arr: ArrayLike, allow_pickle: bool, fix_imports: bool) -> None: ...
@overload
@deprecated("The 'fix_imports' flag is deprecated in NumPy 2.1.")
def save(file: _FNameWriteBytes, arr: ArrayLike, allow_pickle: bool = True, *, fix_imports: bool) -> None: ...

#
def savez(file: _FNameWriteBytes, *args: ArrayLike, allow_pickle: bool = True, **kwds: ArrayLike) -> None: ...

#
def savez_compressed(file: _FNameWriteBytes, *args: ArrayLike, allow_pickle: bool = True, **kwds: ArrayLike) -> None: ...

# File-like objects only have to implement `__iter__` and,
# optionally, `encoding`
@overload
def loadtxt(

    fname: _FName,

    dtype: None = None,

    comments: str | Sequence[str] | None = "#",

    delimiter: str | None = None,

    converters: Mapping[int | str, Callable[[str], Any]] | Callable[[str], Any] | None = None,

    skiprows: int = 0,

    usecols: int | Sequence[int] | None = None,

    unpack: bool = False,

    ndmin: L[0, 1, 2] = 0,

    encoding: str | None = None,

    max_rows: int | None = None,

    *,

    quotechar: str | None = None,

    like: _SupportsArrayFunc | None = None,

) -> NDArray[np.float64]: ...
@overload
def loadtxt(

    fname: _FName,

    dtype: _DTypeLike[_SCT],

    comments: str | Sequence[str] | None = "#",

    delimiter: str | None = None,

    converters: Mapping[int | str, Callable[[str], Any]] | Callable[[str], Any] | None = None,

    skiprows: int = 0,

    usecols: int | Sequence[int] | None = None,

    unpack: bool = False,

    ndmin: L[0, 1, 2] = 0,

    encoding: str | None = None,

    max_rows: int | None = None,

    *,

    quotechar: str | None = None,

    like: _SupportsArrayFunc | None = None,

) -> NDArray[_SCT]: ...
@overload
def loadtxt(

    fname: _FName,

    dtype: DTypeLike,

    comments: str | Sequence[str] | None = "#",

    delimiter: str | None = None,

    converters: Mapping[int | str, Callable[[str], Any]] | Callable[[str], Any] | None = None,

    skiprows: int = 0,

    usecols: int | Sequence[int] | None = None,

    unpack: bool = False,

    ndmin: L[0, 1, 2] = 0,

    encoding: str | None = None,

    max_rows: int | None = None,

    *,

    quotechar: str | None = None,

    like: _SupportsArrayFunc | None = None,

) -> NDArray[Any]: ...

def savetxt(

    fname: StrPath | _FNameWrite,

    X: ArrayLike,

    fmt: str | Sequence[str] = "%.18e",

    delimiter: str = " ",

    newline: str = "\n",

    header: str = "",

    footer: str = "",

    comments: str = "# ",

    encoding: str | None = None,

) -> None: ...

@overload
def fromregex(

    file: _FNameRead,

    regexp: str | bytes | Pattern[Any],

    dtype: _DTypeLike[_SCT],

    encoding: str | None = None,

) -> NDArray[_SCT]: ...
@overload
def fromregex(

    file: _FNameRead,

    regexp: str | bytes | Pattern[Any],

    dtype: DTypeLike,

    encoding: str | None = None,

) -> NDArray[Any]: ...

@overload
def genfromtxt(

    fname: _FName,

    dtype: None = None,

    comments: str = ...,

    delimiter: str | int | Iterable[int] | None = ...,

    skip_header: int = ...,

    skip_footer: int = ...,

    converters: Mapping[int | str, Callable[[str], Any]] | None = ...,

    missing_values: Any = ...,

    filling_values: Any = ...,

    usecols: Sequence[int] | None = ...,

    names: L[True] | str | Collection[str] | None = ...,

    excludelist: Sequence[str] | None = ...,

    deletechars: str = ...,

    replace_space: str = ...,

    autostrip: bool = ...,

    case_sensitive: bool | L["upper", "lower"] = ...,

    defaultfmt: str = ...,

    unpack: bool | None = ...,

    usemask: bool = ...,

    loose: bool = ...,

    invalid_raise: bool = ...,

    max_rows: int | None = ...,

    encoding: str = ...,

    *,

    ndmin: L[0, 1, 2] = ...,

    like: _SupportsArrayFunc | None = ...,

) -> NDArray[Any]: ...
@overload
def genfromtxt(

    fname: _FName,

    dtype: _DTypeLike[_SCT],

    comments: str = ...,

    delimiter: str | int | Iterable[int] | None = ...,

    skip_header: int = ...,

    skip_footer: int = ...,

    converters: Mapping[int | str, Callable[[str], Any]] | None = ...,

    missing_values: Any = ...,

    filling_values: Any = ...,

    usecols: Sequence[int] | None = ...,

    names: L[True] | str | Collection[str] | None = ...,

    excludelist: Sequence[str] | None = ...,

    deletechars: str = ...,

    replace_space: str = ...,

    autostrip: bool = ...,

    case_sensitive: bool | L["upper", "lower"] = ...,

    defaultfmt: str = ...,

    unpack: bool | None = ...,

    usemask: bool = ...,

    loose: bool = ...,

    invalid_raise: bool = ...,

    max_rows: int | None = ...,

    encoding: str = ...,

    *,

    ndmin: L[0, 1, 2] = ...,

    like: _SupportsArrayFunc | None = ...,

) -> NDArray[_SCT]: ...
@overload
def genfromtxt(

    fname: _FName,

    dtype: DTypeLike,

    comments: str = ...,

    delimiter: str | int | Iterable[int] | None = ...,

    skip_header: int = ...,

    skip_footer: int = ...,

    converters: Mapping[int | str, Callable[[str], Any]] | None = ...,

    missing_values: Any = ...,

    filling_values: Any = ...,

    usecols: Sequence[int] | None = ...,

    names: L[True] | str | Collection[str] | None = ...,

    excludelist: Sequence[str] | None = ...,

    deletechars: str = ...,

    replace_space: str = ...,

    autostrip: bool = ...,

    case_sensitive: bool | L["upper", "lower"] = ...,

    defaultfmt: str = ...,

    unpack: bool | None = ...,

    usemask: bool = ...,

    loose: bool = ...,

    invalid_raise: bool = ...,

    max_rows: int | None = ...,

    encoding: str = ...,

    *,

    ndmin: L[0, 1, 2] = ...,

    like: _SupportsArrayFunc | None = ...,

) -> NDArray[Any]: ...

@overload
def recfromtxt(fname: _FName, *, usemask: L[False] = False, **kwargs: object) -> np.recarray[Any, np.dtype[np.record]]: ...
@overload
def recfromtxt(fname: _FName, *, usemask: L[True], **kwargs: object) -> MaskedRecords[Any, np.dtype[np.void]]: ...

@overload
def recfromcsv(fname: _FName, *, usemask: L[False] = False, **kwargs: object) -> np.recarray[Any, np.dtype[np.record]]: ...
@overload
def recfromcsv(fname: _FName, *, usemask: L[True], **kwargs: object) -> MaskedRecords[Any, np.dtype[np.void]]: ...