Copilot commented on code in PR #55264: URL: https://github.com/apache/arrow/pull/55264#discussion_r4597255387
########## python/pyarrow-stubs/__lib/array.pyi: ########## @@ -0,0 +1,637 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import builtins +from collections.abc import Collection, Iterable, Iterator, Sequence +from typing import Any, ClassVar, Self, SupportsIndex, overload + +import numpy as np +import pandas as pd +from numpy.typing import NDArray + +# Placeholders (Any) until scalar.pyi is annotated; mypy rejects them as +# types when imported through pyarrow.lib. +from pyarrow.__lib.scalar import Int64Scalar, Scalar +from pyarrow._compute import CastOptions +from pyarrow._stubs_typing import ( + ArrayLike, + Indices, + MapsAsPydicts, + Mask, + NullEncoding, + NullPlacement, + NullSelectionBehavior, + Order, + SupportsArrowArray, + SupportsArrowDeviceArray, + SupportsPyArrowArray, +) +from pyarrow.lib import ( + BaseExtensionType, + Buffer, + ChunkedArray, + DataType, + Device, + DeviceAllocationType, + Field, + MemoryManager, + MemoryPool, + StructType, + Tensor, + _Weakrefable, +) +from typing_extensions import CapsuleType + +# Return type Array, as most callers get that. +# At runtime it returns ChunkedArray only for binary overflow or when +# __arrow_array__ returns 2+ chunks (GH-55499) +def array( + obj: Array + | Iterable[Any] + | SupportsArrowArray + | SupportsArrowDeviceArray + | SupportsPyArrowArray, + type: Any | None = None, + mask: Array | Iterable[bool] | NDArray[np.bool_] | None = None, + size: int | None = None, + from_pandas: bool | None = None, + safe: bool = True, + memory_pool: MemoryPool | None = None, +) -> Array: ... +@overload +def asarray( # type: ignore[overload-overlap] + values: ChunkedArray, type: Any | None = None +) -> ChunkedArray: ... +@overload +def asarray( + values: Array + | Iterable[Any] + | SupportsArrowArray + | SupportsArrowDeviceArray + | SupportsPyArrowArray, + type: Any | None = None, +) -> Array: ... +def nulls( + size: int, + type: Any | None = None, + memory_pool: MemoryPool | None = None, +) -> Array: ... +def repeat( + value: Any, + size: int, + memory_pool: MemoryPool | None = None, +) -> Array: ... +def infer_type( + values: Sequence[Any] | NDArray[Any], + mask: Mask | None = None, + from_pandas: bool = False, +) -> DataType: ... + +class ArrayStatistics(_Weakrefable): + @property + def null_count(self) -> int | None: ... + @property + def distinct_count(self) -> int | None: ... + @property + def is_null_count_exact(self) -> bool | None: ... + @property + def is_distinct_count_exact(self) -> bool | None: ... + @property + def min(self) -> Any | None: ... + @property + def is_min_exact(self) -> bool | None: ... + @property + def max(self) -> Any | None: ... + @property + def is_max_exact(self) -> bool | None: ... + +class _PandasConvertible(_Weakrefable): + def to_pandas( + self, + memory_pool: MemoryPool | None = None, + categories: list[Any] | tuple[Any, ...] | None = None, + strings_to_categorical: bool = False, + zero_copy_only: bool = False, + integer_object_nulls: bool = False, + date_as_object: bool = True, + timestamp_as_object: bool = False, + use_threads: bool = True, + deduplicate_objects: bool = True, + ignore_metadata: bool = False, + safe: bool = True, + split_blocks: bool = False, + self_destruct: bool = False, + maps_as_pydicts: MapsAsPydicts | None = None, + types_mapper: Any = None, # Callable[[DataType], ExtensionDtype | None] | None + coerce_temporal_nanoseconds: bool = False, + ) -> pd.Series | pd.DataFrame: ... + +class Array(_PandasConvertible): + __hash__: ClassVar[None] # type: ignore[assignment] + def diff(self, other: Array) -> str: ... + def cast( + self, + target_type: DataType | str | None = None, + safe: bool | None = None, + options: CastOptions | None = None, + memory_pool: MemoryPool | None = None, + ) -> Array: ... + def view(self, target_type: DataType | str) -> Array: ... + def sum(self, **kwargs: Any) -> Scalar: ... + @property + def type(self) -> DataType: ... + def unique(self) -> Self: ... + def dictionary_encode( + self, null_encoding: NullEncoding = "mask" + ) -> DictionaryArray: ... + def value_counts(self) -> StructArray: ... + @staticmethod + def from_pandas( + obj: pd.Series | NDArray[Any] | ArrayLike, + mask: Array | Iterable[bool] | NDArray[np.bool_] | None = None, + type: DataType | str | None = None, + safe: bool = True, + memory_pool: MemoryPool | None = None, + ) -> Array: ... + @staticmethod + def from_buffers( + type: DataType, + length: int, + buffers: Collection[Buffer | None], + null_count: int = -1, + offset: int = 0, + children: Collection[Array] | None = None, + ) -> Array: ... + @property + def null_count(self) -> int: ... + @property + def nbytes(self) -> int: ... + def get_total_buffer_size(self) -> int: ... + def __sizeof__(self) -> int: ... + def __iter__(self) -> Iterator[Scalar]: ... + def to_string( + self, + *, + indent: int = 2, + top_level_indent: int = 0, + window: int = 10, + container_window: int = 2, + skip_new_lines: bool = False, + element_size_limit: int = 100, + ) -> str: ... + def equals(self, other: Array) -> bool: ... + def __len__(self) -> int: ... + def is_null(self, *, nan_is_null: bool = False) -> BooleanArray: ... + def is_nan(self) -> BooleanArray: ... + def is_valid(self) -> BooleanArray: ... + def fill_null(self, fill_value: Any) -> Self: ... + @overload + def __getitem__(self, key: SupportsIndex) -> Scalar: ... + @overload + def __getitem__(self, key: builtins.slice) -> Self: ... + def slice(self, offset: int = 0, length: int | None = None) -> Self: ... + def take(self, indices: Indices) -> Self: ... + def drop_null(self) -> Self: ... + def filter( + self, + mask: Mask, + *, + null_selection_behavior: NullSelectionBehavior = "drop", + ) -> Self: ... + def index( + self, + value: Any, + start: int | None = None, + end: int | None = None, + *, + memory_pool: MemoryPool | None = None, + ) -> Int64Scalar: ... + def sort( + self, + order: Order = "ascending", + null_placement: NullPlacement = "at_end", + **kwargs: Any, + ) -> Self: ... + def __array__( + self, dtype: np.dtype[Any] | None = None, copy: bool | None = None + ) -> NDArray[Any]: ... + def to_numpy( + self, zero_copy_only: bool = True, writable: bool = False + ) -> NDArray[Any]: ... + def to_pylist( + self, + *, + maps_as_pydicts: MapsAsPydicts | None = None, + ) -> list[Any]: ... + + tolist = to_pylist + def to_tensor(self, *, allow_nulls: bool = False) -> Tensor: ... + def validate(self, *, full: bool = False) -> None: ... + @property + def offset(self) -> int: ... + def buffers(self) -> list[Buffer | None]: ... + def copy_to(self, destination: MemoryManager | Device) -> Self: ... + def _export_to_c(self, out_ptr: int, out_schema_ptr: int = 0) -> None: ... + @staticmethod + def _import_from_c(in_ptr: int, type: int | DataType) -> Array: ... + def __arrow_c_array__( + self, requested_schema: CapsuleType | None = None + ) -> tuple[CapsuleType, CapsuleType]: ... + @staticmethod + def _import_from_c_capsule( + schema_capsule: CapsuleType, array_capsule: CapsuleType + ) -> Array: ... + def _export_to_c_device(self, out_ptr: int, out_schema_ptr: int = 0) -> None: ... + @staticmethod + def _import_from_c_device(in_ptr: int, type: DataType | int) -> Array: ... + def __arrow_c_device_array__( + self, requested_schema: CapsuleType | None = None, **kwargs: Any + ) -> tuple[CapsuleType, CapsuleType]: ... + @staticmethod + def _import_from_c_device_capsule( + schema_capsule: CapsuleType, array_capsule: CapsuleType + ) -> Array: ... + def __dlpack__( Review Comment: The stubs omit `Array.from_dlpack()`, so type checkers reject this supported constructor. The same issue affects `FixedShapeTensorArray.from_dlpack()` and `from_tensor()` in this file at line 552. Add the static constructor signatures, returning `Array` for the base constructor and `FixedShapeTensorArray` for the specialized constructors. ########## python/pyarrow-stubs/__lib/array.pyi: ########## @@ -0,0 +1,637 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import builtins +from collections.abc import Collection, Iterable, Iterator, Sequence +from typing import Any, ClassVar, Self, SupportsIndex, overload + +import numpy as np +import pandas as pd +from numpy.typing import NDArray + +# Placeholders (Any) until scalar.pyi is annotated; mypy rejects them as +# types when imported through pyarrow.lib. +from pyarrow.__lib.scalar import Int64Scalar, Scalar +from pyarrow._compute import CastOptions +from pyarrow._stubs_typing import ( + ArrayLike, + Indices, + MapsAsPydicts, + Mask, + NullEncoding, + NullPlacement, + NullSelectionBehavior, + Order, + SupportsArrowArray, + SupportsArrowDeviceArray, + SupportsPyArrowArray, +) +from pyarrow.lib import ( + BaseExtensionType, + Buffer, + ChunkedArray, + DataType, + Device, + DeviceAllocationType, + Field, + MemoryManager, + MemoryPool, + StructType, + Tensor, + _Weakrefable, +) +from typing_extensions import CapsuleType + +# Return type Array, as most callers get that. +# At runtime it returns ChunkedArray only for binary overflow or when +# __arrow_array__ returns 2+ chunks (GH-55499) +def array( + obj: Array + | Iterable[Any] + | SupportsArrowArray + | SupportsArrowDeviceArray + | SupportsPyArrowArray, + type: Any | None = None, + mask: Array | Iterable[bool] | NDArray[np.bool_] | None = None, + size: int | None = None, + from_pandas: bool | None = None, + safe: bool = True, + memory_pool: MemoryPool | None = None, +) -> Array: ... +@overload +def asarray( # type: ignore[overload-overlap] + values: ChunkedArray, type: Any | None = None +) -> ChunkedArray: ... +@overload +def asarray( + values: Array + | Iterable[Any] + | SupportsArrowArray + | SupportsArrowDeviceArray + | SupportsPyArrowArray, + type: Any | None = None, +) -> Array: ... +def nulls( + size: int, + type: Any | None = None, + memory_pool: MemoryPool | None = None, +) -> Array: ... +def repeat( + value: Any, + size: int, + memory_pool: MemoryPool | None = None, +) -> Array: ... +def infer_type( + values: Sequence[Any] | NDArray[Any], + mask: Mask | None = None, + from_pandas: bool = False, +) -> DataType: ... + +class ArrayStatistics(_Weakrefable): + @property + def null_count(self) -> int | None: ... + @property + def distinct_count(self) -> int | None: ... + @property + def is_null_count_exact(self) -> bool | None: ... + @property + def is_distinct_count_exact(self) -> bool | None: ... + @property + def min(self) -> Any | None: ... + @property + def is_min_exact(self) -> bool | None: ... + @property + def max(self) -> Any | None: ... + @property + def is_max_exact(self) -> bool | None: ... + +class _PandasConvertible(_Weakrefable): + def to_pandas( + self, + memory_pool: MemoryPool | None = None, + categories: list[Any] | tuple[Any, ...] | None = None, + strings_to_categorical: bool = False, + zero_copy_only: bool = False, + integer_object_nulls: bool = False, + date_as_object: bool = True, + timestamp_as_object: bool = False, + use_threads: bool = True, + deduplicate_objects: bool = True, + ignore_metadata: bool = False, + safe: bool = True, + split_blocks: bool = False, + self_destruct: bool = False, + maps_as_pydicts: MapsAsPydicts | None = None, + types_mapper: Any = None, # Callable[[DataType], ExtensionDtype | None] | None + coerce_temporal_nanoseconds: bool = False, + ) -> pd.Series | pd.DataFrame: ... + +class Array(_PandasConvertible): + __hash__: ClassVar[None] # type: ignore[assignment] + def diff(self, other: Array) -> str: ... + def cast( + self, + target_type: DataType | str | None = None, + safe: bool | None = None, + options: CastOptions | None = None, + memory_pool: MemoryPool | None = None, + ) -> Array: ... + def view(self, target_type: DataType | str) -> Array: ... + def sum(self, **kwargs: Any) -> Scalar: ... + @property + def type(self) -> DataType: ... + def unique(self) -> Self: ... + def dictionary_encode( + self, null_encoding: NullEncoding = "mask" + ) -> DictionaryArray: ... + def value_counts(self) -> StructArray: ... + @staticmethod + def from_pandas( + obj: pd.Series | NDArray[Any] | ArrayLike, + mask: Array | Iterable[bool] | NDArray[np.bool_] | None = None, + type: DataType | str | None = None, + safe: bool = True, + memory_pool: MemoryPool | None = None, + ) -> Array: ... + @staticmethod + def from_buffers( + type: DataType, + length: int, + buffers: Collection[Buffer | None], + null_count: int = -1, + offset: int = 0, + children: Collection[Array] | None = None, + ) -> Array: ... + @property + def null_count(self) -> int: ... + @property + def nbytes(self) -> int: ... + def get_total_buffer_size(self) -> int: ... + def __sizeof__(self) -> int: ... + def __iter__(self) -> Iterator[Scalar]: ... + def to_string( + self, + *, + indent: int = 2, + top_level_indent: int = 0, + window: int = 10, + container_window: int = 2, + skip_new_lines: bool = False, + element_size_limit: int = 100, + ) -> str: ... + def equals(self, other: Array) -> bool: ... + def __len__(self) -> int: ... + def is_null(self, *, nan_is_null: bool = False) -> BooleanArray: ... + def is_nan(self) -> BooleanArray: ... + def is_valid(self) -> BooleanArray: ... + def fill_null(self, fill_value: Any) -> Self: ... + @overload + def __getitem__(self, key: SupportsIndex) -> Scalar: ... + @overload + def __getitem__(self, key: builtins.slice) -> Self: ... + def slice(self, offset: int = 0, length: int | None = None) -> Self: ... + def take(self, indices: Indices) -> Self: ... + def drop_null(self) -> Self: ... + def filter( + self, + mask: Mask, + *, + null_selection_behavior: NullSelectionBehavior = "drop", + ) -> Self: ... + def index( + self, + value: Any, + start: int | None = None, + end: int | None = None, + *, + memory_pool: MemoryPool | None = None, + ) -> Int64Scalar: ... + def sort( + self, + order: Order = "ascending", + null_placement: NullPlacement = "at_end", + **kwargs: Any, + ) -> Self: ... + def __array__( + self, dtype: np.dtype[Any] | None = None, copy: bool | None = None + ) -> NDArray[Any]: ... + def to_numpy( + self, zero_copy_only: bool = True, writable: bool = False + ) -> NDArray[Any]: ... + def to_pylist( + self, + *, + maps_as_pydicts: MapsAsPydicts | None = None, + ) -> list[Any]: ... + + tolist = to_pylist + def to_tensor(self, *, allow_nulls: bool = False) -> Tensor: ... + def validate(self, *, full: bool = False) -> None: ... + @property + def offset(self) -> int: ... + def buffers(self) -> list[Buffer | None]: ... + def copy_to(self, destination: MemoryManager | Device) -> Self: ... + def _export_to_c(self, out_ptr: int, out_schema_ptr: int = 0) -> None: ... + @staticmethod + def _import_from_c(in_ptr: int, type: int | DataType) -> Array: ... + def __arrow_c_array__( + self, requested_schema: CapsuleType | None = None + ) -> tuple[CapsuleType, CapsuleType]: ... + @staticmethod + def _import_from_c_capsule( + schema_capsule: CapsuleType, array_capsule: CapsuleType + ) -> Array: ... + def _export_to_c_device(self, out_ptr: int, out_schema_ptr: int = 0) -> None: ... + @staticmethod + def _import_from_c_device(in_ptr: int, type: DataType | int) -> Array: ... + def __arrow_c_device_array__( + self, requested_schema: CapsuleType | None = None, **kwargs: Any + ) -> tuple[CapsuleType, CapsuleType]: ... + @staticmethod + def _import_from_c_device_capsule( + schema_capsule: CapsuleType, array_capsule: CapsuleType + ) -> Array: ... + def __dlpack__( + self, + *, + stream: int | None = None, + max_version: tuple[int, int] | None = None, + dl_device: tuple[int, int] | None = None, + copy: bool | None = None, + ) -> CapsuleType: ... + def __dlpack_device__(self) -> tuple[int, int]: ... + @property + def device_type(self) -> DeviceAllocationType: ... + @property + def is_cpu(self) -> bool: ... + @property + def statistics(self) -> ArrayStatistics | None: ... Review Comment: The `Array` stub omits the arithmetic and bitwise operators implemented in `array.pxi:2437–2483`, so supported expressions such as `arr + other`, `-arr`, and `arr & other` fail type checking. Add these signatures, allowing binary operations to return `ChunkedArray` when the other operand is chunked. ########## python/pyarrow-stubs/__lib/io.pyi: ########## @@ -15,15 +15,11 @@ # specific language governing permissions and limitations # under the License. -"""Type stubs for PyArrow. - -This is a placeholder stub file. -Complete type annotations will be added in subsequent PRs. -""" +# Placeholder stub - complete annotations in future PR. +# At runtime, these symbols are provided by the pyarrow.lib C extension. from typing import Any -# TODO(GH-48970): remove __getattr__ before release as this -# will annotate non-existing attributes as Any. -# https://github.com/apache/arrow/issues/48970 +class Buffer: ... Review Comment: Defining `Buffer` as an empty class rejects valid operations such as `pa.schema([]).serialize().to_pybytes()`, `len(buffer)`, and indexing. The module-level `__getattr__` does not apply to instances. Preserve a permissive placeholder until the I/O interface is annotated. ########## python/pyarrow-stubs/__lib/types.pyi: ########## @@ -0,0 +1,663 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from collections.abc import Iterable, Iterator, Mapping, Sequence +from typing import Any, ClassVar, Literal, Self, TypeAlias, overload + +import numpy as np +import pandas as pd +from numpy.typing import DTypeLike +from pyarrow._stubs_typing import ( + BinaryType, + BinaryViewType, + BoolType, + Date32Type, + Date64Type, + Float16Type, + Float32Type, + Float64Type, + Int8Type, + Int16Type, + Int32Type, + Int64Type, + IntegerType, + LargeBinaryType, + LargeStringType, + MonthDayNanoIntervalType, + NullType, + StringType, + StringViewType, + SupportsArrowSchema, + TimeUnit, + UInt8Type, + UInt16Type, + UInt32Type, + UInt64Type, +) +from pyarrow.lib import ( + Array, + Buffer, + ChunkedArray, + ExtensionArray, + ExtensionScalar, + MemoryPool, + Table, +) +from typing_extensions import CapsuleType + +class _Weakrefable: ... +class _Metadata(_Weakrefable): ... + +class DataType(_Weakrefable): + def field(self, i: int) -> Field: ... + @property + def id(self) -> int: ... + @property + def bit_width(self) -> int: ... + @property + def byte_width(self) -> int: ... + @property + def num_fields(self) -> int: ... + @property + def num_buffers(self) -> int: ... + @property + def has_variadic_buffers(self) -> bool: ... + def equals( + self, other: DataType | str, *, check_metadata: bool = False + ) -> bool: ... + def to_pandas_dtype(self) -> _PandasDtype: ... + def _export_to_c(self, out_ptr: int) -> None: ... + @staticmethod + def _import_from_c(in_ptr: int) -> DataType: ... + def __arrow_c_schema__(self) -> CapsuleType: ... + @staticmethod + def _import_from_c_capsule(schema: CapsuleType) -> DataType: ... + +_PandasDtype: TypeAlias = ( + type[np.generic] | np.dtype[Any] | pd.api.extensions.ExtensionDtype +) + +_Time32Unit: TypeAlias = Literal["s", "ms"] +_Time64Unit: TypeAlias = Literal["us", "ns"] + +class TimestampType(DataType): + @property + def unit(self) -> TimeUnit: ... + @property + def tz(self) -> str | None: ... + +class Time32Type(DataType): + @property + def unit(self) -> _Time32Unit: ... + +class Time64Type(DataType): + @property + def unit(self) -> _Time64Unit: ... + +class DurationType(DataType): + @property + def unit(self) -> TimeUnit: ... + +class FixedSizeBinaryType(DataType): ... + +class Decimal32Type(FixedSizeBinaryType): + @property + def precision(self) -> int: ... + @property + def scale(self) -> int: ... + +class Decimal64Type(FixedSizeBinaryType): + @property + def precision(self) -> int: ... + @property + def scale(self) -> int: ... + +class Decimal128Type(FixedSizeBinaryType): + @property + def precision(self) -> int: ... + @property + def scale(self) -> int: ... + +class Decimal256Type(FixedSizeBinaryType): + @property + def precision(self) -> int: ... + @property + def scale(self) -> int: ... + +class ListType(DataType): + @property + def value_field(self) -> Field: ... + @property + def value_type(self) -> DataType: ... + +class LargeListType(DataType): + @property + def value_field(self) -> Field: ... + @property + def value_type(self) -> DataType: ... + +class ListViewType(DataType): + @property + def value_field(self) -> Field: ... + @property + def value_type(self) -> DataType: ... + +class LargeListViewType(DataType): + @property + def value_field(self) -> Field: ... + @property + def value_type(self) -> DataType: ... + +class FixedSizeListType(DataType): + @property + def value_field(self) -> Field: ... + @property + def value_type(self) -> DataType: ... + @property + def list_size(self) -> int: ... + +class DictionaryMemo(_Weakrefable): ... + +class DictionaryType(DataType): + @property + def ordered(self) -> bool: ... + @property + def index_type(self) -> IntegerType: ... + @property + def value_type(self) -> DataType: ... + +class MapType(DataType): + @property + def key_field(self) -> Field: ... + @property + def key_type(self) -> DataType: ... + @property + def item_field(self) -> Field: ... + @property + def item_type(self) -> DataType: ... + @property + def keys_sorted(self) -> bool: ... + +class StructType(DataType): + def get_field_index(self, name: str | bytes) -> int: ... + def field(self, i: int | str | bytes) -> Field: ... + def get_all_field_indices(self, name: str | bytes) -> list[int]: ... + def __len__(self) -> int: ... + def __iter__(self) -> Iterator[Field]: ... + + __getitem__ = field + @property + def names(self) -> list[str]: ... + @property + def fields(self) -> list[Field]: ... + +class UnionType(DataType): + @property + def mode(self) -> Literal["sparse", "dense"]: ... + @property + def type_codes(self) -> list[int]: ... + def __len__(self) -> int: ... + def __iter__(self) -> Iterator[Field]: ... + def field(self, i: int) -> Field: ... + + __getitem__ = field + +class SparseUnionType(UnionType): + @property + def mode(self) -> Literal["sparse"]: ... + +class DenseUnionType(UnionType): + @property + def mode(self) -> Literal["dense"]: ... + +_RunEndType: TypeAlias = Int16Type | Int32Type | Int64Type + +class RunEndEncodedType(DataType): + @property + def run_end_type(self) -> _RunEndType: ... + @property + def value_type(self) -> DataType: ... + +class BaseExtensionType(DataType): + def __arrow_ext_class__(self) -> type[ExtensionArray]: ... + def __arrow_ext_scalar_class__(self) -> type[ExtensionScalar]: ... + @property + def extension_name(self) -> str: ... + @property + def storage_type(self) -> DataType: ... + def wrap_array( + self, storage: Array | ChunkedArray + ) -> ExtensionArray | ChunkedArray: ... + +class ExtensionType(BaseExtensionType): + def __init__(self, storage_type: DataType, extension_name: str) -> None: ... + def __arrow_ext_serialize__(self) -> bytes: ... + @classmethod + def __arrow_ext_deserialize__( + cls, storage_type: DataType, serialized: bytes + ) -> Self: ... + __hash__: ClassVar[None] # type: ignore[assignment] + +class FixedShapeTensorType(BaseExtensionType): + @property + def value_type(self) -> DataType: ... + @property + def shape(self) -> list[int]: ... + @property + def dim_names(self) -> list[str] | None: ... + @property + def permutation(self) -> list[int] | None: ... + +class Bool8Type(BaseExtensionType): ... +class UuidType(BaseExtensionType): ... +class JsonType(BaseExtensionType): ... + +class OpaqueType(BaseExtensionType): + @property + def type_name(self) -> str: ... + @property + def vendor_name(self) -> str: ... + +class UnknownExtensionType(ExtensionType): + def __init__(self, storage_type: DataType, serialized: bytes) -> None: ... + +def register_extension_type(ext_type: BaseExtensionType) -> None: ... +def unregister_extension_type(type_name: str) -> None: ... + +_FieldName: TypeAlias = str | bytes +_StrOrBytes: TypeAlias = str | bytes +_MetadataMapping: TypeAlias = ( + Mapping[bytes, bytes] + | Mapping[str, str] + | Mapping[bytes, str] + | Mapping[str, bytes] +) +_MetadataIterable: TypeAlias = Iterable[tuple[_StrOrBytes, _StrOrBytes]] +_KeyValueMetadataInput: TypeAlias = _MetadataMapping | _MetadataIterable +_DataTypeAlias: TypeAlias = Literal[ + "null", + "bool", + "boolean", + "i1", + "int8", + "i2", + "int16", + "i4", + "int32", + "i8", + "int64", + "u1", + "uint8", + "u2", + "uint16", + "u4", + "uint32", + "u8", + "uint64", + "f2", + "halffloat", + "float16", + "f4", + "float", + "float32", + "f8", + "double", + "float64", + "string", + "str", + "utf8", + "binary", + "large_string", + "large_str", + "large_utf8", + "large_binary", + "binary_view", + "string_view", + "date32", + "date64", + "date32[day]", + "date64[ms]", + "time32[s]", + "time32[ms]", + "time64[us]", + "time64[ns]", + "timestamp[s]", + "timestamp[ms]", + "timestamp[us]", + "timestamp[ns]", + "duration[s]", + "duration[ms]", + "duration[us]", + "duration[ns]", + "month_day_nano_interval", +] +_DataTypeAliasInput: TypeAlias = _DataTypeAlias | str +_DataTypeLike: TypeAlias = DataType | _DataTypeAliasInput + +class KeyValueMetadata(_Metadata, Mapping[bytes, bytes]): + def __init__( + self, + __arg0__: _KeyValueMetadataInput | KeyValueMetadata | None = None, + **kwargs: str | bytes, + ) -> None: ... + __hash__: ClassVar[None] # type: ignore[assignment] + def equals(self, other: KeyValueMetadata) -> bool: ... + def __len__(self) -> int: ... + def __contains__(self, key: object, /) -> bool: ... + def __getitem__(self, key: str | bytes, /) -> bytes: ... + def __iter__(self) -> Iterator[bytes]: ... + def key(self, i: int) -> bytes: ... + def value(self, i: int) -> bytes: ... + # The runtime yields generators instead of Mapping views + def keys(self) -> Iterator[bytes]: ... # type: ignore[override] # ty: ignore[invalid-method-override] # noqa: E501 + def values(self) -> Iterator[bytes]: ... # type: ignore[override] # ty: ignore[invalid-method-override] # noqa: E501 + def items(self) -> Iterator[tuple[bytes, bytes]]: ... # type: ignore[override] # ty: ignore[invalid-method-override] # noqa: E501 + def get_all(self, key: str | bytes) -> list[bytes]: ... + def to_dict(self) -> dict[bytes, bytes]: ... + +class Field(_Weakrefable): + def equals(self, other: Field, check_metadata: bool = False) -> bool: ... + @property + def nullable(self) -> bool: ... + @property + def name(self) -> str: ... + @property + def metadata(self) -> dict[bytes, bytes] | None: ... + @property + def type(self) -> DataType: ... + def with_metadata( + self, + metadata: _KeyValueMetadataInput | KeyValueMetadata | None, + ) -> Field: ... + def remove_metadata(self) -> Field: ... + def with_type(self, new_type: DataType) -> Field: ... + def with_name(self, name: str | bytes) -> Field: ... + def with_nullable(self, nullable: bool) -> Field: ... + def flatten(self) -> list[Field]: ... + def _export_to_c(self, out_ptr: int) -> None: ... + @staticmethod + def _import_from_c(in_ptr: int) -> Field: ... + def __arrow_c_schema__(self) -> CapsuleType: ... + @staticmethod + def _import_from_c_capsule(schema: CapsuleType) -> Field: ... + +_FieldTuple: TypeAlias = ( + tuple[_FieldName, _DataTypeLike] + | tuple[_FieldName, _DataTypeLike, bool | None] + | tuple[ + _FieldName, + _DataTypeLike, + bool | None, + _KeyValueMetadataInput | KeyValueMetadata | None, + ] +) +_StructFieldsInput: TypeAlias = ( + Iterable[Field | _FieldTuple] | Mapping[_FieldName, _DataTypeLike] +) +_SchemaFieldsInput: TypeAlias = _StructFieldsInput + +class Schema(_Weakrefable): + def __len__(self) -> int: ... + def __getitem__(self, key: int, /) -> Field: ... + + _field = __getitem__ + def __iter__(self) -> Iterator[Field]: ... + def __sizeof__(self) -> int: ... + @property + def pandas_metadata(self) -> dict[str, Any] | None: ... + @property + def names(self) -> list[str]: ... + @property + def types(self) -> list[DataType]: ... + @property + def metadata(self) -> dict[bytes, bytes] | None: ... + def empty_table(self) -> Table: ... + def equals(self, other: Schema, check_metadata: bool = False) -> bool: ... + @classmethod + def from_pandas( + cls, df: pd.DataFrame, preserve_index: bool | None = None + ) -> Schema: ... + def field(self, i: int | str | bytes) -> Field: ... + def get_field_index(self, name: str | bytes) -> int: ... + def get_all_field_indices(self, name: str | bytes) -> list[int]: ... + def append(self, field: Field) -> Schema: ... + def insert(self, i: int, field: Field) -> Schema: ... + def remove(self, i: int) -> Schema: ... + def set(self, i: int, field: Field) -> Schema: ... + def with_metadata( + self, metadata: _KeyValueMetadataInput | KeyValueMetadata | None + ) -> Schema: ... + def serialize(self, memory_pool: MemoryPool | None = None) -> Buffer: ... + def remove_metadata(self) -> Schema: ... + def to_string( + self, + truncate_metadata: bool = True, + show_field_metadata: bool = True, + show_schema_metadata: bool = True, + element_size_limit: int = 100, + ) -> str: ... + def _export_to_c(self, out_ptr: int) -> None: ... + @staticmethod + def _import_from_c(in_ptr: int) -> Schema: ... + def __arrow_c_schema__(self) -> CapsuleType: ... + @staticmethod + def _import_from_c_capsule(schema: CapsuleType) -> Schema: ... + +def unify_schemas( + schemas: Iterable[Schema], + *, + promote_options: Literal["default", "permissive"] = "default", +) -> Schema: ... +@overload +def field( + name: SupportsArrowSchema, + type: None = None, + nullable: bool | None = None, + metadata: _KeyValueMetadataInput | KeyValueMetadata | None = None, +) -> Field: ... +@overload +def field( + name: _FieldName, + type: _DataTypeLike, + nullable: bool | None = None, + metadata: _KeyValueMetadataInput | KeyValueMetadata | None = None, +) -> Field: ... +def null() -> NullType: ... +def bool_() -> BoolType: ... +def uint8() -> UInt8Type: ... +def int8() -> Int8Type: ... +def uint16() -> UInt16Type: ... +def int16() -> Int16Type: ... +def uint32() -> UInt32Type: ... +def int32() -> Int32Type: ... +def int64() -> Int64Type: ... +def uint64() -> UInt64Type: ... +def timestamp(unit: TimeUnit | str, tz: str | None = None) -> TimestampType: ... +def time32(unit: _Time32Unit | str) -> Time32Type: ... +def time64(unit: _Time64Unit | str) -> Time64Type: ... +def duration(unit: TimeUnit | str) -> DurationType: ... +def month_day_nano_interval() -> MonthDayNanoIntervalType: ... +def date32() -> Date32Type: ... +def date64() -> Date64Type: ... +def float16() -> Float16Type: ... +def float32() -> Float32Type: ... +def float64() -> Float64Type: ... +def decimal32(precision: int, scale: int = 0) -> Decimal32Type: ... +def decimal64(precision: int, scale: int = 0) -> Decimal64Type: ... +def decimal128(precision: int, scale: int = 0) -> Decimal128Type: ... +def decimal256(precision: int, scale: int = 0) -> Decimal256Type: ... +def string() -> StringType: ... + +utf8 = string + +def binary( + length: Literal[-1] | int = ..., +) -> BinaryType | FixedSizeBinaryType: ... +def large_binary() -> LargeBinaryType: ... +def large_string() -> LargeStringType: ... + +large_utf8 = large_string + +def binary_view() -> BinaryViewType: ... +def string_view() -> StringViewType: ... +@overload +def list_(value_type: DataType | Field, list_size: Literal[-1] = -1) -> ListType: ... +@overload +def list_( + value_type: DataType | Field, list_size: int +) -> ListType | FixedSizeListType: ... +def large_list(value_type: DataType | Field) -> LargeListType: ... +def list_view(value_type: DataType | Field) -> ListViewType: ... +def large_list_view(value_type: DataType | Field) -> LargeListViewType: ... +def map_( + key_type: _DataTypeLike | Field, + item_type: _DataTypeLike | Field, + keys_sorted: bool = False, +) -> MapType: ... +def dictionary( + index_type: IntegerType | _DataTypeAliasInput, + value_type: _DataTypeLike, + ordered: bool = False, +) -> DictionaryType: ... +def struct( + fields: _StructFieldsInput, +) -> StructType: ... +def sparse_union( + child_fields: Iterable[Field], type_codes: Sequence[int] | None = None +) -> SparseUnionType: ... +def dense_union( + child_fields: Iterable[Field], type_codes: Sequence[int] | None = None +) -> DenseUnionType: ... +def union( + child_fields: Iterable[Field], + mode: Literal["sparse", "dense"] | int, + type_codes: Sequence[int] | None = None, +) -> SparseUnionType | DenseUnionType: ... +def run_end_encoded( + run_end_type: _RunEndType | _DataTypeAliasInput, Review Comment: Requiring the stub-only `IntegerType` union rejects integer types obtained through APIs annotated as returning `DataType`. For example, `pa.dictionary(pa.array([1]).type, pa.string())` works at runtime but fails this signature. The same problem affects `run_end_encoded()` below. Please accept `DataType | str` for these inputs, matching their runtime contract, rather than requiring callers to cast to synthetic subclasses. ########## python/pyarrow-stubs/__lib/types.pyi: ########## @@ -0,0 +1,663 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from collections.abc import Iterable, Iterator, Mapping, Sequence +from typing import Any, ClassVar, Literal, Self, TypeAlias, overload + +import numpy as np +import pandas as pd +from numpy.typing import DTypeLike +from pyarrow._stubs_typing import ( + BinaryType, + BinaryViewType, + BoolType, + Date32Type, + Date64Type, + Float16Type, + Float32Type, + Float64Type, + Int8Type, + Int16Type, + Int32Type, + Int64Type, + IntegerType, + LargeBinaryType, + LargeStringType, + MonthDayNanoIntervalType, + NullType, + StringType, + StringViewType, + SupportsArrowSchema, + TimeUnit, + UInt8Type, + UInt16Type, + UInt32Type, + UInt64Type, +) +from pyarrow.lib import ( + Array, + Buffer, + ChunkedArray, + ExtensionArray, + ExtensionScalar, + MemoryPool, + Table, +) +from typing_extensions import CapsuleType + +class _Weakrefable: ... +class _Metadata(_Weakrefable): ... + +class DataType(_Weakrefable): + def field(self, i: int) -> Field: ... + @property + def id(self) -> int: ... + @property + def bit_width(self) -> int: ... + @property + def byte_width(self) -> int: ... + @property + def num_fields(self) -> int: ... + @property + def num_buffers(self) -> int: ... + @property + def has_variadic_buffers(self) -> bool: ... + def equals( + self, other: DataType | str, *, check_metadata: bool = False + ) -> bool: ... + def to_pandas_dtype(self) -> _PandasDtype: ... + def _export_to_c(self, out_ptr: int) -> None: ... + @staticmethod + def _import_from_c(in_ptr: int) -> DataType: ... + def __arrow_c_schema__(self) -> CapsuleType: ... + @staticmethod + def _import_from_c_capsule(schema: CapsuleType) -> DataType: ... + +_PandasDtype: TypeAlias = ( + type[np.generic] | np.dtype[Any] | pd.api.extensions.ExtensionDtype +) + +_Time32Unit: TypeAlias = Literal["s", "ms"] +_Time64Unit: TypeAlias = Literal["us", "ns"] + +class TimestampType(DataType): + @property + def unit(self) -> TimeUnit: ... + @property + def tz(self) -> str | None: ... + +class Time32Type(DataType): + @property + def unit(self) -> _Time32Unit: ... + +class Time64Type(DataType): + @property + def unit(self) -> _Time64Unit: ... + +class DurationType(DataType): + @property + def unit(self) -> TimeUnit: ... + +class FixedSizeBinaryType(DataType): ... + +class Decimal32Type(FixedSizeBinaryType): + @property + def precision(self) -> int: ... + @property + def scale(self) -> int: ... + +class Decimal64Type(FixedSizeBinaryType): + @property + def precision(self) -> int: ... + @property + def scale(self) -> int: ... + +class Decimal128Type(FixedSizeBinaryType): + @property + def precision(self) -> int: ... + @property + def scale(self) -> int: ... + +class Decimal256Type(FixedSizeBinaryType): + @property + def precision(self) -> int: ... + @property + def scale(self) -> int: ... + +class ListType(DataType): + @property + def value_field(self) -> Field: ... + @property + def value_type(self) -> DataType: ... + +class LargeListType(DataType): + @property + def value_field(self) -> Field: ... + @property + def value_type(self) -> DataType: ... + +class ListViewType(DataType): + @property + def value_field(self) -> Field: ... + @property + def value_type(self) -> DataType: ... + +class LargeListViewType(DataType): + @property + def value_field(self) -> Field: ... + @property + def value_type(self) -> DataType: ... + +class FixedSizeListType(DataType): + @property + def value_field(self) -> Field: ... + @property + def value_type(self) -> DataType: ... + @property + def list_size(self) -> int: ... + +class DictionaryMemo(_Weakrefable): ... + +class DictionaryType(DataType): + @property + def ordered(self) -> bool: ... + @property + def index_type(self) -> IntegerType: ... + @property + def value_type(self) -> DataType: ... + +class MapType(DataType): + @property + def key_field(self) -> Field: ... + @property + def key_type(self) -> DataType: ... + @property + def item_field(self) -> Field: ... + @property + def item_type(self) -> DataType: ... + @property + def keys_sorted(self) -> bool: ... + +class StructType(DataType): + def get_field_index(self, name: str | bytes) -> int: ... + def field(self, i: int | str | bytes) -> Field: ... + def get_all_field_indices(self, name: str | bytes) -> list[int]: ... + def __len__(self) -> int: ... + def __iter__(self) -> Iterator[Field]: ... + + __getitem__ = field + @property + def names(self) -> list[str]: ... + @property + def fields(self) -> list[Field]: ... + +class UnionType(DataType): + @property + def mode(self) -> Literal["sparse", "dense"]: ... + @property + def type_codes(self) -> list[int]: ... + def __len__(self) -> int: ... + def __iter__(self) -> Iterator[Field]: ... + def field(self, i: int) -> Field: ... + + __getitem__ = field + +class SparseUnionType(UnionType): + @property + def mode(self) -> Literal["sparse"]: ... + +class DenseUnionType(UnionType): + @property + def mode(self) -> Literal["dense"]: ... + +_RunEndType: TypeAlias = Int16Type | Int32Type | Int64Type + +class RunEndEncodedType(DataType): + @property + def run_end_type(self) -> _RunEndType: ... + @property + def value_type(self) -> DataType: ... + +class BaseExtensionType(DataType): + def __arrow_ext_class__(self) -> type[ExtensionArray]: ... + def __arrow_ext_scalar_class__(self) -> type[ExtensionScalar]: ... + @property + def extension_name(self) -> str: ... + @property + def storage_type(self) -> DataType: ... + def wrap_array( + self, storage: Array | ChunkedArray + ) -> ExtensionArray | ChunkedArray: ... + +class ExtensionType(BaseExtensionType): + def __init__(self, storage_type: DataType, extension_name: str) -> None: ... + def __arrow_ext_serialize__(self) -> bytes: ... + @classmethod + def __arrow_ext_deserialize__( + cls, storage_type: DataType, serialized: bytes + ) -> Self: ... + __hash__: ClassVar[None] # type: ignore[assignment] + +class FixedShapeTensorType(BaseExtensionType): + @property + def value_type(self) -> DataType: ... + @property + def shape(self) -> list[int]: ... + @property + def dim_names(self) -> list[str] | None: ... + @property + def permutation(self) -> list[int] | None: ... + +class Bool8Type(BaseExtensionType): ... +class UuidType(BaseExtensionType): ... +class JsonType(BaseExtensionType): ... + +class OpaqueType(BaseExtensionType): + @property + def type_name(self) -> str: ... + @property + def vendor_name(self) -> str: ... + +class UnknownExtensionType(ExtensionType): + def __init__(self, storage_type: DataType, serialized: bytes) -> None: ... + +def register_extension_type(ext_type: BaseExtensionType) -> None: ... +def unregister_extension_type(type_name: str) -> None: ... + +_FieldName: TypeAlias = str | bytes +_StrOrBytes: TypeAlias = str | bytes +_MetadataMapping: TypeAlias = ( + Mapping[bytes, bytes] + | Mapping[str, str] + | Mapping[bytes, str] + | Mapping[str, bytes] +) +_MetadataIterable: TypeAlias = Iterable[tuple[_StrOrBytes, _StrOrBytes]] +_KeyValueMetadataInput: TypeAlias = _MetadataMapping | _MetadataIterable +_DataTypeAlias: TypeAlias = Literal[ + "null", + "bool", + "boolean", + "i1", + "int8", + "i2", + "int16", + "i4", + "int32", + "i8", + "int64", + "u1", + "uint8", + "u2", + "uint16", + "u4", + "uint32", + "u8", + "uint64", + "f2", + "halffloat", + "float16", + "f4", + "float", + "float32", + "f8", + "double", + "float64", + "string", + "str", + "utf8", + "binary", + "large_string", + "large_str", + "large_utf8", + "large_binary", + "binary_view", + "string_view", + "date32", + "date64", + "date32[day]", + "date64[ms]", + "time32[s]", + "time32[ms]", + "time64[us]", + "time64[ns]", + "timestamp[s]", + "timestamp[ms]", + "timestamp[us]", + "timestamp[ns]", + "duration[s]", + "duration[ms]", + "duration[us]", + "duration[ns]", + "month_day_nano_interval", +] +_DataTypeAliasInput: TypeAlias = _DataTypeAlias | str +_DataTypeLike: TypeAlias = DataType | _DataTypeAliasInput + +class KeyValueMetadata(_Metadata, Mapping[bytes, bytes]): + def __init__( + self, + __arg0__: _KeyValueMetadataInput | KeyValueMetadata | None = None, + **kwargs: str | bytes, + ) -> None: ... + __hash__: ClassVar[None] # type: ignore[assignment] + def equals(self, other: KeyValueMetadata) -> bool: ... + def __len__(self) -> int: ... + def __contains__(self, key: object, /) -> bool: ... + def __getitem__(self, key: str | bytes, /) -> bytes: ... + def __iter__(self) -> Iterator[bytes]: ... + def key(self, i: int) -> bytes: ... + def value(self, i: int) -> bytes: ... + # The runtime yields generators instead of Mapping views + def keys(self) -> Iterator[bytes]: ... # type: ignore[override] # ty: ignore[invalid-method-override] # noqa: E501 + def values(self) -> Iterator[bytes]: ... # type: ignore[override] # ty: ignore[invalid-method-override] # noqa: E501 + def items(self) -> Iterator[tuple[bytes, bytes]]: ... # type: ignore[override] # ty: ignore[invalid-method-override] # noqa: E501 + def get_all(self, key: str | bytes) -> list[bytes]: ... + def to_dict(self) -> dict[bytes, bytes]: ... + +class Field(_Weakrefable): + def equals(self, other: Field, check_metadata: bool = False) -> bool: ... + @property + def nullable(self) -> bool: ... + @property + def name(self) -> str: ... + @property + def metadata(self) -> dict[bytes, bytes] | None: ... + @property + def type(self) -> DataType: ... + def with_metadata( + self, + metadata: _KeyValueMetadataInput | KeyValueMetadata | None, + ) -> Field: ... + def remove_metadata(self) -> Field: ... + def with_type(self, new_type: DataType) -> Field: ... + def with_name(self, name: str | bytes) -> Field: ... + def with_nullable(self, nullable: bool) -> Field: ... + def flatten(self) -> list[Field]: ... + def _export_to_c(self, out_ptr: int) -> None: ... + @staticmethod + def _import_from_c(in_ptr: int) -> Field: ... + def __arrow_c_schema__(self) -> CapsuleType: ... + @staticmethod + def _import_from_c_capsule(schema: CapsuleType) -> Field: ... + +_FieldTuple: TypeAlias = ( + tuple[_FieldName, _DataTypeLike] + | tuple[_FieldName, _DataTypeLike, bool | None] + | tuple[ + _FieldName, + _DataTypeLike, + bool | None, + _KeyValueMetadataInput | KeyValueMetadata | None, + ] +) +_StructFieldsInput: TypeAlias = ( + Iterable[Field | _FieldTuple] | Mapping[_FieldName, _DataTypeLike] +) +_SchemaFieldsInput: TypeAlias = _StructFieldsInput + +class Schema(_Weakrefable): + def __len__(self) -> int: ... + def __getitem__(self, key: int, /) -> Field: ... + + _field = __getitem__ + def __iter__(self) -> Iterator[Field]: ... + def __sizeof__(self) -> int: ... + @property + def pandas_metadata(self) -> dict[str, Any] | None: ... + @property + def names(self) -> list[str]: ... + @property + def types(self) -> list[DataType]: ... + @property + def metadata(self) -> dict[bytes, bytes] | None: ... + def empty_table(self) -> Table: ... + def equals(self, other: Schema, check_metadata: bool = False) -> bool: ... + @classmethod + def from_pandas( + cls, df: pd.DataFrame, preserve_index: bool | None = None + ) -> Schema: ... + def field(self, i: int | str | bytes) -> Field: ... + def get_field_index(self, name: str | bytes) -> int: ... + def get_all_field_indices(self, name: str | bytes) -> list[int]: ... + def append(self, field: Field) -> Schema: ... + def insert(self, i: int, field: Field) -> Schema: ... + def remove(self, i: int) -> Schema: ... + def set(self, i: int, field: Field) -> Schema: ... + def with_metadata( + self, metadata: _KeyValueMetadataInput | KeyValueMetadata | None + ) -> Schema: ... + def serialize(self, memory_pool: MemoryPool | None = None) -> Buffer: ... + def remove_metadata(self) -> Schema: ... + def to_string( + self, + truncate_metadata: bool = True, + show_field_metadata: bool = True, + show_schema_metadata: bool = True, + element_size_limit: int = 100, + ) -> str: ... + def _export_to_c(self, out_ptr: int) -> None: ... + @staticmethod + def _import_from_c(in_ptr: int) -> Schema: ... + def __arrow_c_schema__(self) -> CapsuleType: ... + @staticmethod + def _import_from_c_capsule(schema: CapsuleType) -> Schema: ... + +def unify_schemas( + schemas: Iterable[Schema], + *, + promote_options: Literal["default", "permissive"] = "default", +) -> Schema: ... +@overload +def field( + name: SupportsArrowSchema, + type: None = None, + nullable: bool | None = None, + metadata: _KeyValueMetadataInput | KeyValueMetadata | None = None, +) -> Field: ... +@overload +def field( + name: _FieldName, + type: _DataTypeLike, + nullable: bool | None = None, + metadata: _KeyValueMetadataInput | KeyValueMetadata | None = None, +) -> Field: ... +def null() -> NullType: ... +def bool_() -> BoolType: ... +def uint8() -> UInt8Type: ... +def int8() -> Int8Type: ... +def uint16() -> UInt16Type: ... +def int16() -> Int16Type: ... +def uint32() -> UInt32Type: ... +def int32() -> Int32Type: ... +def int64() -> Int64Type: ... +def uint64() -> UInt64Type: ... +def timestamp(unit: TimeUnit | str, tz: str | None = None) -> TimestampType: ... Review Comment: `timestamp()` also accepts `datetime.tzinfo` instances and byte strings: `types.pxi:4208–4211` explicitly converts them, and the existing array tests pass `pytz.timezone(...)`. Restricting `tz` to `str | None` rejects valid calls such as `pa.timestamp("us", tz=datetime.timezone.utc)`. Please include `datetime.tzinfo` and `bytes` in this parameter's annotation. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
