Skip to content

Commit 3ddf085

Browse files
committed
Simplified array inputs, ignore opt imports, fix DLPack signature and test
1 parent 4b70969 commit 3ddf085

2 files changed

Lines changed: 23 additions & 9 deletions

File tree

‎python/pyarrow-stubs/pyarrow/__lib/array.pyi‎

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ else:
2626

2727
from typing import Any, Literal
2828

29-
import numpy as np
30-
import pandas as pd
29+
import numpy as np # type: ignore[import-not-found]
30+
import pandas as pd # type: ignore[import-not-found,import-untyped]
3131

3232
from pyarrow._compute import CastOptions
3333
from pyarrow._stubs_typing import (
@@ -56,8 +56,7 @@ from .types import BaseExtensionType, DataType, Field, StructType
5656
from pyarrow._stubs_typing import NullableCollection
5757

5858
def array(
59-
values: NullableCollection
60-
| Iterable[Any]
59+
values: Iterable[Any]
6160
| SupportsArrowArray
6261
| SupportsArrowDeviceArray
6362
| SupportsPyArrowArray,
@@ -69,10 +68,7 @@ def array(
6968
memory_pool: MemoryPool | None = None,
7069
) -> ArrayLike: ...
7170
def asarray(
72-
values: NullableCollection
73-
| Iterable[Any]
74-
| SupportsArrowArray
75-
| SupportsArrowDeviceArray,
71+
values: Iterable[Any] | SupportsArrowArray | SupportsArrowDeviceArray,
7672
type: Any | None = None,
7773
) -> ArrayLike: ...
7874
def nulls(
@@ -238,7 +234,14 @@ class Array(_PandasConvertible):
238234
def __arrow_c_device_array__(self, requested_schema=None, **kwargs) -> Any: ...
239235
@staticmethod
240236
def _import_from_c_device_capsule(schema_capsule, array_capsule) -> Array: ...
241-
def __dlpack__(self, stream: int | None = None) -> Any: ...
237+
def __dlpack__(
238+
self,
239+
*,
240+
stream: int | None = None,
241+
max_version: tuple[int, int] | None = None,
242+
dl_device: tuple[int, int] | None = None,
243+
copy: bool | None = None,
244+
) -> Any: ...
242245
def __dlpack_device__(self) -> tuple[int, int]: ...
243246
@property
244247
def device_type(self) -> DeviceAllocationType: ...

‎python/pyarrow-stubs/tests/test_array.py‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from typing import Any, cast
2020

2121
import pyarrow.lib as lib
22+
from typing_extensions import CapsuleType
2223

2324
from _check import TYPE_CHECKING_INVALID_USAGE, assert_type, check
2425

@@ -51,6 +52,16 @@ def test_array() -> None:
5152
lib.Int64Array)
5253

5354

55+
def test_array_dlpack() -> None:
56+
arr = cast(lib.Int64Array, lib.array([1, 2]))
57+
capsule = arr.__dlpack__(
58+
max_version=(1, 0),
59+
dl_device=arr.__dlpack_device__(),
60+
copy=False,
61+
)
62+
check(assert_type(capsule, Any), CapsuleType)
63+
64+
5465
def test_import_from_c_capsule() -> None:
5566
capsules = lib.array([1, 2]).__arrow_c_array__()
5667
imported = lib.BooleanArray._import_from_c_capsule(*capsules)

0 commit comments

Comments
 (0)