codekingpro/portable-devtools
115k
1import os
2from _typeshed import SupportsRead, SupportsWrite
3from typing import Any, BinaryIO, Final, TypeAlias, TypeGuard
4
5import numpy as np
6import numpy.typing as npt
7from numpy.lib._utils_impl import drop_metadata as drop_metadata
8
9__all__: list[str] = []
10
11_DTypeDescr: TypeAlias = list[tuple[str, str]] | list[tuple[str, str, tuple[int, ...]]]
12
13###
14
15EXPECTED_KEYS: Final[set[str]] = ...
16MAGIC_PREFIX: Final = b"\x93NUMPY"
17MAGIC_LEN: Final = 8
18ARRAY_ALIGN: Final = 64
19BUFFER_SIZE: Final = 262_144 # 1 << 18
20GROWTH_AXIS_MAX_DIGITS: Final = 21
21_MAX_HEADER_SIZE: Final = 10_000
22
23def magic(major: int, minor: int) -> bytes: ...
24def read_magic(fp: SupportsRead[bytes]) -> tuple[int, int]: ...
25def dtype_to_descr(dtype: np.dtype) -> _DTypeDescr: ...
26def descr_to_dtype(descr: _DTypeDescr) -> np.dtype: ...
27def header_data_from_array_1_0(array: np.ndarray) -> dict[str, Any]: ...
28def write_array_header_1_0(fp: SupportsWrite[bytes], d: dict[str, Any]) -> None: ...
29def write_array_header_2_0(fp: SupportsWrite[bytes], d: dict[str, Any]) -> None: ...
30def read_array_header_1_0(fp: SupportsRead[bytes], max_header_size: int = 10_000) -> tuple[tuple[int, ...], bool, np.dtype]: ...
31def read_array_header_2_0(fp: SupportsRead[bytes], max_header_size: int = 10_000) -> tuple[tuple[int, ...], bool, np.dtype]: ...
32def write_array(
33 fp: SupportsWrite[bytes],
34 array: np.ndarray,
35 version: tuple[int, int] | None = None,
36 allow_pickle: bool = True,
37 pickle_kwargs: dict[str, Any] | None = None,
38) -> None: ...
39def read_array(
40 fp: SupportsRead[bytes],
41 allow_pickle: bool = False,
42 pickle_kwargs: dict[str, Any] | None = None,
43 *,
44 max_header_size: int = 10_000,
45) -> np.ndarray: ...
46def open_memmap(
47 filename: str | os.PathLike[Any],
48 mode: str = "r+",
49 dtype: npt.DTypeLike | None = None,
50 shape: tuple[int, ...] | None = None,
51 fortran_order: bool = False,
52 version: tuple[int, int] | None = None,
53 *,
54 max_header_size: int = 10_000,
55) -> np.memmap: ...
56def isfileobj(f: object) -> TypeGuard[BinaryIO]: ... # don't use `typing.TypeIs`
57 