|
| 1 | +# Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +# or more contributor license agreements. See the NOTICE file |
| 3 | +# distributed with this work for additional information |
| 4 | +# regarding copyright ownership. The ASF licenses this file |
| 5 | +# to you under the Apache License, Version 2.0 (the |
| 6 | +# "License"); you may not use this file except in compliance |
| 7 | +# with the License. You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, |
| 12 | +# software distributed under the License is distributed on an |
| 13 | +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +# KIND, either express or implied. See the License for the |
| 15 | +# specific language governing permissions and limitations |
| 16 | +# under the License. |
| 17 | + |
| 18 | +import datetime as dt |
| 19 | + |
| 20 | +from collections.abc import Collection, Iterator, Sequence |
| 21 | +from decimal import Decimal |
| 22 | +from typing import Any, Literal, Protocol, TypeAlias, TypeVar |
| 23 | + |
| 24 | +import numpy as np |
| 25 | + |
| 26 | +from numpy.typing import NDArray |
| 27 | + |
| 28 | +from pyarrow.lib import BooleanArray, IntegerArray, ChunkedArray |
| 29 | + |
| 30 | +ArrayLike: TypeAlias = Any |
| 31 | +ScalarLike: TypeAlias = Any |
| 32 | +Order: TypeAlias = Literal["ascending", "descending"] |
| 33 | +JoinType: TypeAlias = Literal[ |
| 34 | + "left semi", |
| 35 | + "right semi", |
| 36 | + "left anti", |
| 37 | + "right anti", |
| 38 | + "inner", |
| 39 | + "left outer", |
| 40 | + "right outer", |
| 41 | + "full outer", |
| 42 | +] |
| 43 | +Compression: TypeAlias = Literal[ |
| 44 | + "gzip", "bz2", "brotli", "lz4", "lz4_frame", "lz4_raw", "zstd", "snappy" |
| 45 | +] |
| 46 | +NullEncoding: TypeAlias = Literal["mask", "encode"] |
| 47 | +NullSelectionBehavior: TypeAlias = Literal["drop", "emit_null"] |
| 48 | +TimeUnit: TypeAlias = Literal["s", "ms", "us", "ns"] |
| 49 | +Mask: TypeAlias = ( |
| 50 | + Sequence[bool | None] |
| 51 | + | NDArray[np.bool_] |
| 52 | + | BooleanArray |
| 53 | + | ChunkedArray[Any] |
| 54 | +) |
| 55 | +Indices: TypeAlias = ( |
| 56 | + Sequence[int | None] |
| 57 | + | NDArray[np.integer[Any]] |
| 58 | + | IntegerArray |
| 59 | + | ChunkedArray[Any] |
| 60 | +) |
| 61 | + |
| 62 | +PyScalar: TypeAlias = (bool | int | float | Decimal | str | bytes | |
| 63 | + dt.date | dt.datetime | dt.time | dt.timedelta) |
| 64 | + |
| 65 | +_T = TypeVar("_T") |
| 66 | +_V = TypeVar("_V", covariant=True) |
| 67 | + |
| 68 | +SingleOrList: TypeAlias = list[_T] | _T |
| 69 | + |
| 70 | + |
| 71 | +class SupportEq(Protocol): |
| 72 | + def __eq__(self, other) -> bool: ... |
| 73 | + |
| 74 | + |
| 75 | +class SupportLt(Protocol): |
| 76 | + def __lt__(self, other) -> bool: ... |
| 77 | + |
| 78 | + |
| 79 | +class SupportGt(Protocol): |
| 80 | + def __gt__(self, other) -> bool: ... |
| 81 | + |
| 82 | + |
| 83 | +class SupportLe(Protocol): |
| 84 | + def __le__(self, other) -> bool: ... |
| 85 | + |
| 86 | + |
| 87 | +class SupportGe(Protocol): |
| 88 | + def __ge__(self, other) -> bool: ... |
| 89 | + |
| 90 | + |
| 91 | +FilterTuple: TypeAlias = ( |
| 92 | + tuple[str, Literal["=", "==", "!="], SupportEq] |
| 93 | + | tuple[str, Literal["<"], SupportLt] |
| 94 | + | tuple[str, Literal[">"], SupportGt] |
| 95 | + | tuple[str, Literal["<="], SupportLe] |
| 96 | + | tuple[str, Literal[">="], SupportGe] |
| 97 | + | tuple[str, Literal["in", "not in"], Collection] |
| 98 | + | tuple[str, str, Any] # Allow general str for operator to avoid type errors |
| 99 | +) |
| 100 | + |
| 101 | + |
| 102 | +class Buffer(Protocol): |
| 103 | + ... |
| 104 | + |
| 105 | + |
| 106 | +class SupportPyBuffer(Protocol): |
| 107 | + ... |
| 108 | + |
| 109 | + |
| 110 | +class SupportArrowStream(Protocol): |
| 111 | + def __arrow_c_stream__(self, requested_schema=None) -> Any: ... |
| 112 | + |
| 113 | + |
| 114 | +class SupportPyArrowArray(Protocol): |
| 115 | + def __arrow_array__(self, type=None) -> Any: ... |
| 116 | + |
| 117 | + |
| 118 | +class SupportArrowArray(Protocol): |
| 119 | + def __arrow_c_array__(self, requested_schema=None) -> Any: ... |
| 120 | + |
| 121 | + |
| 122 | +class SupportArrowDeviceArray(Protocol): |
| 123 | + def __arrow_c_device_array__(self, requested_schema=None, **kwargs) -> Any: ... |
| 124 | + |
| 125 | + |
| 126 | +class SupportArrowSchema(Protocol): |
| 127 | + def __arrow_c_schema__(self) -> Any: ... |
| 128 | + |
| 129 | + |
| 130 | +class NullableCollection(Protocol[_V]): # type: ignore[reportInvalidTypeVarUse] |
| 131 | + def __iter__(self) -> Iterator[_V] | Iterator[_V | None]: ... |
| 132 | + def __len__(self) -> int: ... |
| 133 | + def __contains__(self, item: Any, /) -> bool: ... |
0 commit comments