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


##########
python/pyarrow-stubs/__lib/array.pyi:
##########
@@ -0,0 +1,613 @@
+# 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 sys
+
+from collections.abc import Iterable, Iterator, Sequence
+
+if sys.version_info >= (3, 11):
+    from typing import Self
+else:
+    from typing_extensions import Self
+
+from typing import Any, Literal
+
+import numpy as np  # type: ignore[import-not-found]
+import pandas as pd  # type: ignore[import-not-found,import-untyped]
+
+from pyarrow._compute import CastOptions
+from pyarrow._stubs_typing import (
+    ArrayLike,
+    Indices,
+    Mask,
+    MapsAsPydicts,
+    Order,
+    SupportsArrowArray,
+    SupportsArrowDeviceArray,
+    SupportsPyArrowArray,
+)
+from pyarrow.lib import (
+    Buffer,
+    Device,
+    MemoryManager,
+    MemoryPool,
+    Tensor,
+    _Weakrefable,
+)
+from typing_extensions import deprecated
+import builtins
+
+from .scalar import Int64Scalar, Scalar
+from .device import DeviceAllocationType
+from .types import BaseExtensionType, DataType, Field, StructType
+from pyarrow._stubs_typing import NullableCollection
+
+def array(
+    values: Iterable[Any]
+    | SupportsArrowArray
+    | SupportsArrowDeviceArray
+    | SupportsPyArrowArray,
+    type: Any | None = None,
+    mask: Mask | pd.Series[bool] | None = None,
+    size: int | None = None,
+    from_pandas: bool | None = None,
+    safe: bool = True,
+    memory_pool: MemoryPool | None = None,
+) -> ArrayLike: ...
+def asarray(
+    values: Iterable[Any] | SupportsArrowArray | SupportsArrowDeviceArray,
+    type: Any | None = None,
+) -> ArrayLike: ...
+def nulls(
+    size: int,
+    type: Any | None = None,
+    memory_pool: MemoryPool | None = None,
+) -> ArrayLike: ...

Review Comment:
   > It seems that `array` and `asarray` may also return `ChunkedArray` (in 
case of binary overflow/`__arrow_array__` for `array` or
   > in case of input `ChunkedArray` for `asarray` ) ... So both keep `Any` - 
until adding overloads later perhaps.
   
   For `asarray` we can indeed type it as returning either of them (question: 
why not type it with a union of both now instead of `Any`), potentially later 
narrowing it down with an overload.
   
   But for `array()` I think this will basically be impossible to describe the 
binary overflow situation in typing terms. So I am afraid there is not much 
alternative to type `array()` (incorrectly ...) to always return `Array` (this 
is also what the external pyarrow-stubs package does). 
   Because the alternative, having `array()` be typed to return `Array | 
ChunkedArray` will require a lot of type casts in user code (essentially every 
time after you use that function and your code assumes you have an Array, which 
will be most code)
   
   (long term this might be something we want to solve in the runtime, eg a 
keyword to indicate that a chunkedarray return is allowed, but by default 
errors on it, but that is for another issue)



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