dangotbanned commented on code in PR #48622:
URL: https://github.com/apache/arrow/pull/48622#discussion_r2641510816


##########
python/pyarrow-stubs/pyarrow/_stubs_typing.pyi:
##########
@@ -0,0 +1,133 @@
+# 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 datetime as dt
+
+from collections.abc import Collection, Iterator, Sequence
+from decimal import Decimal
+from typing import Any, Literal, Protocol, TypeAlias, TypeVar
+
+import numpy as np
+
+from numpy.typing import NDArray
+
+from pyarrow.lib import BooleanArray, IntegerArray, ChunkedArray
+
+ArrayLike: TypeAlias = Any
+ScalarLike: TypeAlias = Any
+Order: TypeAlias = Literal["ascending", "descending"]
+JoinType: TypeAlias = Literal[
+    "left semi",
+    "right semi",
+    "left anti",
+    "right anti",
+    "inner",
+    "left outer",
+    "right outer",
+    "full outer",
+]
+Compression: TypeAlias = Literal[
+    "gzip", "bz2", "brotli", "lz4", "lz4_frame", "lz4_raw", "zstd", "snappy"
+]
+NullEncoding: TypeAlias = Literal["mask", "encode"]
+NullSelectionBehavior: TypeAlias = Literal["drop", "emit_null"]
+TimeUnit: TypeAlias = Literal["s", "ms", "us", "ns"]
+Mask: TypeAlias = (
+    Sequence[bool | None]
+    | NDArray[np.bool_]
+    | BooleanArray
+    | ChunkedArray[Any]
+)
+Indices: TypeAlias = (
+    Sequence[int | None]
+    | NDArray[np.integer[Any]]
+    | IntegerArray
+    | ChunkedArray[Any]
+)

Review Comment:
   This isn't the most exciting suggestion, but it's something that constantly 
furstrates me 😅 
   
   ```suggestion
   from pyarrow import lib
   
   IntegerType: TypeAlias = (
       lib.Int8Type
       | lib.Int16Type
       | lib.Int32Type
       | lib.Int64Type
       | lib.UInt8Type
       | lib.UInt16Type
       | lib.UInt32Type
       | lib.UInt64Type
   )
   
   Mask: TypeAlias = (
       Sequence[bool | None]
       | NDArray[np.bool_]
       | lib.Array[lib.Scalar[lib.BoolType]]
       | ChunkedArray[Any]
   )
   Indices: TypeAlias = (
       Sequence[int | None]
       | NDArray[np.integer[Any]]
       | lib.Array[lib.Scalar[IntegerType]]
       | ChunkedArray[Any]
   )
   ```
   
   An alternative would just be `Array[Any]`.
   Using the concrete subclasses requires the stubs to do a carefully 
choreographed dance, or the user to `typing.cast` everywhere - sadly



##########
python/pyarrow-stubs/pyarrow/_stubs_typing.pyi:
##########
@@ -0,0 +1,133 @@
+# 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 datetime as dt
+
+from collections.abc import Collection, Iterator, Sequence
+from decimal import Decimal
+from typing import Any, Literal, Protocol, TypeAlias, TypeVar
+
+import numpy as np
+
+from numpy.typing import NDArray
+
+from pyarrow.lib import BooleanArray, IntegerArray, ChunkedArray
+
+ArrayLike: TypeAlias = Any
+ScalarLike: TypeAlias = Any
+Order: TypeAlias = Literal["ascending", "descending"]
+JoinType: TypeAlias = Literal[
+    "left semi",
+    "right semi",
+    "left anti",
+    "right anti",
+    "inner",
+    "left outer",
+    "right outer",
+    "full outer",
+]
+Compression: TypeAlias = Literal[
+    "gzip", "bz2", "brotli", "lz4", "lz4_frame", "lz4_raw", "zstd", "snappy"
+]
+NullEncoding: TypeAlias = Literal["mask", "encode"]
+NullSelectionBehavior: TypeAlias = Literal["drop", "emit_null"]
+TimeUnit: TypeAlias = Literal["s", "ms", "us", "ns"]
+Mask: TypeAlias = (
+    Sequence[bool | None]
+    | NDArray[np.bool_]
+    | BooleanArray
+    | ChunkedArray[Any]
+)
+Indices: TypeAlias = (
+    Sequence[int | None]
+    | NDArray[np.integer[Any]]
+    | IntegerArray
+    | ChunkedArray[Any]
+)

Review Comment:
   This isn't the most exciting suggestion, but it's something that constantly 
frustrates me 😅 
   
   ```suggestion
   from pyarrow import lib
   
   IntegerType: TypeAlias = (
       lib.Int8Type
       | lib.Int16Type
       | lib.Int32Type
       | lib.Int64Type
       | lib.UInt8Type
       | lib.UInt16Type
       | lib.UInt32Type
       | lib.UInt64Type
   )
   
   Mask: TypeAlias = (
       Sequence[bool | None]
       | NDArray[np.bool_]
       | lib.Array[lib.Scalar[lib.BoolType]]
       | ChunkedArray[Any]
   )
   Indices: TypeAlias = (
       Sequence[int | None]
       | NDArray[np.integer[Any]]
       | lib.Array[lib.Scalar[IntegerType]]
       | ChunkedArray[Any]
   )
   ```
   
   An alternative would just be `Array[Any]`.
   Using the concrete subclasses requires the stubs to do a carefully 
choreographed dance, or the user to `typing.cast` everywhere - sadly



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