jorisvandenbossche commented on code in PR #55264:
URL: https://github.com/apache/arrow/pull/55264#discussion_r4597268249


##########
python/pyarrow-stubs/__lib/table.pyi:
##########
@@ -0,0 +1,627 @@
+# 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 Iterable, Iterator, Mapping, Sequence
+from typing import Any, ClassVar, Literal, overload, Self, TypeAlias
+
+import numpy as np
+import pandas as pd
+from numpy.typing import NDArray
+
+# Placeholders (Any) until ipc.pyi and scalar.pyi are annotated; mypy
+# rejects them as types when imported through pyarrow.lib.
+from pyarrow.__lib.ipc import RecordBatchReader
+from pyarrow.__lib.scalar import Int64Scalar, Scalar
+from pyarrow._compute import (
+    CastOptions,
+    CountOptions,
+    FunctionOptions,
+    ScalarAggregateOptions,
+    TDigestOptions,
+    VarianceOptions,
+)
+from pyarrow._stubs_typing import (
+    Indices,
+    MapsAsPydicts,
+    Mask,
+    NullEncoding,
+    NullPlacement,
+    NullSelectionBehavior,
+    Order,
+    SupportsArrowArray,
+    SupportsArrowDeviceArray,
+    SupportsArrowStream,
+    SupportsPyArrowArray,
+)
+from pyarrow.lib import (
+    Array,
+    Buffer,
+    DataType,
+    Device,
+    DeviceAllocationType,
+    Field,
+    MemoryManager,
+    MemoryPool,
+    Schema,
+    StructArray,
+    Tensor,
+    _PandasConvertible,
+)
+from typing_extensions import CapsuleType
+
+from pyarrow.compute import Expression
+from pyarrow.interchange.dataframe import _PyArrowDataFrame
+
+_ArrayOrChunkedArray: TypeAlias = Array | ChunkedArray
+
+_Aggregation: TypeAlias = Literal[
+    "all",
+    "any",
+    "approximate_median",
+    "count",
+    "count_all",
+    "count_distinct",
+    "distinct",
+    "first",
+    "first_last",
+    "kurtosis",
+    "last",
+    "list",
+    "max",
+    "mean",
+    "min",
+    "min_max",
+    "one",
+    "pivot_wider",
+    "product",
+    "skew",
+    "stddev",
+    "sum",
+    "tdigest",
+    "variance",
+]
+_AggregationPrefixed: TypeAlias = Literal[
+    "hash_all",
+    "hash_any",
+    "hash_approximate_median",
+    "hash_count",
+    "hash_count_all",
+    "hash_count_distinct",
+    "hash_distinct",
+    "hash_first",
+    "hash_first_last",
+    "hash_kurtosis",
+    "hash_last",
+    "hash_list",
+    "hash_max",
+    "hash_mean",
+    "hash_min",
+    "hash_min_max",
+    "hash_one",
+    "hash_pivot_wider",
+    "hash_product",
+    "hash_skew",
+    "hash_stddev",
+    "hash_sum",
+    "hash_tdigest",
+    "hash_variance",
+]
+_AggregationName: TypeAlias = _Aggregation | _AggregationPrefixed | str
+_AggregateOptions: TypeAlias = (
+    ScalarAggregateOptions
+    | CountOptions
+    | TDigestOptions
+    | VarianceOptions
+    | FunctionOptions
+)
+
+_ChunkedArrayConstructorInput: TypeAlias = (
+    Iterable[
+        Array
+        | Iterable[Any]
+        | SupportsArrowArray
+        | SupportsArrowDeviceArray
+        | SupportsPyArrowArray
+    ]
+    | Array
+    | SupportsArrowArray
+    | SupportsArrowStream
+)
+
+_UnarySelector: TypeAlias = str
+_NullarySelector: TypeAlias = tuple[()]
+_NarySelector: TypeAlias = list[str] | tuple[str, ...]
+_ColumnSelector: TypeAlias = _UnarySelector | _NullarySelector | _NarySelector
+
+class ChunkedArray(_PandasConvertible):
+    @property
+    def type(self) -> DataType: ...
+    def length(self) -> int: ...
+
+    __len__ = length
+
+    def to_string(
+        self,
+        *,
+        indent: int = 0,
+        window: int = 5,
+        container_window: int = 2,
+        skip_new_lines: bool = False,
+        element_size_limit: int = 100,
+    ) -> str: ...
+    def validate(self, *, full: bool = False) -> None: ...
+    @property
+    def null_count(self) -> int: ...
+    @property
+    def nbytes(self) -> int: ...
+    def get_total_buffer_size(self) -> int: ...
+    def __sizeof__(self) -> int: ...
+    @overload
+    def __getitem__(self, key: int | np.integer) -> Scalar: ...
+    @overload
+    def __getitem__(self, key: builtins.slice) -> ChunkedArray: ...
+    __hash__: ClassVar[None]  # type: ignore[assignment]
+    def is_null(self, *, nan_is_null: bool = False) -> ChunkedArray: ...
+    def is_nan(self) -> ChunkedArray: ...
+    def is_valid(self) -> ChunkedArray: ...
+    def cast(
+        self,
+        target_type: DataType | str | None = None,
+        safe: bool | None = None,
+        options: CastOptions | None = None,
+    ) -> ChunkedArray: ...
+    def fill_null(self, fill_value: Any) -> ChunkedArray: ...
+    def equals(self, other: ChunkedArray | None) -> bool: ...
+    def to_numpy(self, zero_copy_only: bool = False) -> np.ndarray: ...

Review Comment:
   Small note, numpy.typing also exposes a `Array1D`, which is like `NDArray` 
but the shape generic part fixed to a 1d shape. I think we have many cases 
where we only accept 1d arrays, so that could be a future improvements (but I 
would say let's leave as is for this PR ;))



-- 
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]

Reply via email to