|
| 1 | +import abc |
| 2 | +from abc import ( |
| 3 | + ABC, |
| 4 | + abstractmethod, |
| 5 | +) |
| 6 | +import enum |
| 7 | +from typing import ( |
| 8 | + Any, |
| 9 | + Iterable, |
| 10 | + Sequence, |
| 11 | + TypedDict, |
| 12 | +) |
| 13 | + |
| 14 | +class DlpackDeviceType(enum.IntEnum): |
| 15 | + CPU: int |
| 16 | + CUDA: int |
| 17 | + CPU_PINNED: int |
| 18 | + OPENCL: int |
| 19 | + VULKAN: int |
| 20 | + METAL: int |
| 21 | + VPI: int |
| 22 | + ROCM: int |
| 23 | + |
| 24 | +class DtypeKind(enum.IntEnum): |
| 25 | + INT: int |
| 26 | + UINT: int |
| 27 | + FLOAT: int |
| 28 | + BOOL: int |
| 29 | + STRING: int |
| 30 | + DATETIME: int |
| 31 | + CATEGORICAL: int |
| 32 | + |
| 33 | +class ColumnNullType(enum.IntEnum): |
| 34 | + NON_NULLABLE: int |
| 35 | + USE_NAN: int |
| 36 | + USE_SENTINEL: int |
| 37 | + USE_BITMASK: int |
| 38 | + USE_BYTEMASK: int |
| 39 | + |
| 40 | +class ColumnBuffers(TypedDict): |
| 41 | + data: tuple[Buffer, Any] |
| 42 | + validity: tuple[Buffer, Any] | None |
| 43 | + offsets: tuple[Buffer, Any] | None |
| 44 | + |
| 45 | +class CategoricalDescription(TypedDict): |
| 46 | + is_ordered: bool |
| 47 | + is_dictionary: bool |
| 48 | + categories: Column | None |
| 49 | + |
| 50 | +class Buffer(ABC, metaclass=abc.ABCMeta): |
| 51 | + @property |
| 52 | + @abstractmethod |
| 53 | + def bufsize(self) -> int: ... |
| 54 | + @property |
| 55 | + @abstractmethod |
| 56 | + def ptr(self) -> int: ... |
| 57 | + @abstractmethod |
| 58 | + def __dlpack__(self): ... |
| 59 | + @abstractmethod |
| 60 | + def __dlpack_device__(self) -> tuple[DlpackDeviceType, int | None]: ... |
| 61 | + |
| 62 | +class Column(ABC, metaclass=abc.ABCMeta): |
| 63 | + @property |
| 64 | + @abstractmethod |
| 65 | + def size(self) -> int: ... |
| 66 | + @property |
| 67 | + @abstractmethod |
| 68 | + def offset(self) -> int: ... |
| 69 | + @property |
| 70 | + @abstractmethod |
| 71 | + def dtype(self) -> tuple[DtypeKind, int, str, str]: ... |
| 72 | + @property |
| 73 | + @abstractmethod |
| 74 | + def describe_categorical(self) -> CategoricalDescription: ... |
| 75 | + @property |
| 76 | + @abstractmethod |
| 77 | + def describe_null(self) -> tuple[ColumnNullType, Any]: ... |
| 78 | + @property |
| 79 | + @abstractmethod |
| 80 | + def null_count(self) -> int | None: ... |
| 81 | + @property |
| 82 | + @abstractmethod |
| 83 | + def metadata(self) -> dict[str, Any]: ... |
| 84 | + @abstractmethod |
| 85 | + def num_chunks(self) -> int: ... |
| 86 | + @abstractmethod |
| 87 | + def get_chunks(self, n_chunks: int | None = ...) -> Iterable[Column]: ... |
| 88 | + @abstractmethod |
| 89 | + def get_buffers(self) -> ColumnBuffers: ... |
| 90 | + |
| 91 | +class DataFrame(ABC, metaclass=abc.ABCMeta): |
| 92 | + version: int |
| 93 | + @abstractmethod |
| 94 | + def __dataframe__(self, nan_as_null: bool = ..., allow_copy: bool = ...): ... |
| 95 | + @property |
| 96 | + @abstractmethod |
| 97 | + def metadata(self) -> dict[str, Any]: ... |
| 98 | + @abstractmethod |
| 99 | + def num_columns(self) -> int: ... |
| 100 | + @abstractmethod |
| 101 | + def num_rows(self) -> int | None: ... |
| 102 | + @abstractmethod |
| 103 | + def num_chunks(self) -> int: ... |
| 104 | + @abstractmethod |
| 105 | + def column_names(self) -> Iterable[str]: ... |
| 106 | + @abstractmethod |
| 107 | + def get_column(self, i: int) -> Column: ... |
| 108 | + @abstractmethod |
| 109 | + def get_column_by_name(self, name: str) -> Column: ... |
| 110 | + @abstractmethod |
| 111 | + def get_columns(self) -> Iterable[Column]: ... |
| 112 | + @abstractmethod |
| 113 | + def select_columns(self, indices: Sequence[int]) -> DataFrame: ... |
| 114 | + @abstractmethod |
| 115 | + def select_columns_by_name(self, names: Sequence[str]) -> DataFrame: ... |
| 116 | + @abstractmethod |
| 117 | + def get_chunks(self, n_chunks: int | None = ...) -> Iterable[DataFrame]: ... |
0 commit comments