Skip to content

Commit d86d427

Browse files
committed
Add type stubs for core data structures
Add type annotation stubs for array, table, tensor, builder, memory, device, config, and types modules. Includes type-ignore annotations in related tests.
1 parent bb81a6e commit d86d427

18 files changed

Lines changed: 2561 additions & 134 deletions

python/pyarrow-stubs/pyarrow/array.pyi

Lines changed: 894 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
from collections.abc import Iterable
19+
20+
from pyarrow.lib import MemoryPool, _Weakrefable
21+
22+
from .array import StringArray, StringViewArray
23+
24+
25+
class StringBuilder(_Weakrefable):
26+
def __init__(self, memory_pool: MemoryPool | None = None) -> None: ...
27+
def append(self, value: str | bytes | float | None): ...
28+
29+
def append_values(self, values: Iterable[str | bytes | float | None]): ...
30+
31+
def finish(self) -> StringArray: ...
32+
33+
@property
34+
def null_count(self) -> int: ...
35+
def __len__(self) -> int: ...
36+
37+
38+
class StringViewBuilder(_Weakrefable):
39+
def __init__(self, memory_pool: MemoryPool | None = None) -> None: ...
40+
def append(self, value: str | bytes | float | None): ...
41+
42+
def append_values(self, values: Iterable[str | bytes | float | None]): ...
43+
44+
def finish(self) -> StringViewArray: ...
45+
46+
@property
47+
def null_count(self) -> int: ...
48+
def __len__(self) -> int: ...
49+
50+
51+
__all__ = ["StringBuilder", "StringViewBuilder"]
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
from typing import NamedTuple
19+
20+
21+
class VersionInfo(NamedTuple):
22+
major: int
23+
minor: int
24+
patch: int
25+
26+
27+
class CppBuildInfo(NamedTuple):
28+
version: str
29+
version_info: VersionInfo
30+
so_version: str
31+
full_so_version: str
32+
compiler_id: str
33+
compiler_version: str
34+
compiler_flags: str
35+
git_id: str
36+
git_description: str
37+
package_kind: str
38+
build_type: str
39+
40+
41+
class BuildInfo(NamedTuple):
42+
build_type: str
43+
cpp_build_info: CppBuildInfo
44+
45+
46+
class RuntimeInfo(NamedTuple):
47+
simd_level: str
48+
detected_simd_level: str
49+
50+
51+
build_info: BuildInfo
52+
cpp_build_info: CppBuildInfo
53+
cpp_version: str
54+
cpp_version_info: VersionInfo
55+
56+
57+
def runtime_info() -> RuntimeInfo: ...
58+
def set_timezone_db_path(path: str) -> None: ...
59+
60+
61+
__all__ = [
62+
"VersionInfo",
63+
"BuildInfo",
64+
"CppBuildInfo",
65+
"RuntimeInfo",
66+
"build_info",
67+
"cpp_build_info",
68+
"cpp_version",
69+
"cpp_version_info",
70+
"runtime_info",
71+
"set_timezone_db_path",
72+
]
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
import enum
19+
20+
from pyarrow.lib import _Weakrefable
21+
22+
23+
class DeviceAllocationType(enum.Enum):
24+
CPU = enum.auto()
25+
CUDA = enum.auto()
26+
CUDA_HOST = enum.auto()
27+
OPENCL = enum.auto()
28+
VULKAN = enum.auto()
29+
METAL = enum.auto()
30+
VPI = enum.auto()
31+
ROCM = enum.auto()
32+
ROCM_HOST = enum.auto()
33+
EXT_DEV = enum.auto()
34+
CUDA_MANAGED = enum.auto()
35+
ONEAPI = enum.auto()
36+
WEBGPU = enum.auto()
37+
HEXAGON = enum.auto()
38+
39+
40+
class Device(_Weakrefable):
41+
@property
42+
def type_name(self) -> str: ...
43+
44+
@property
45+
def device_id(self) -> int: ...
46+
47+
@property
48+
def is_cpu(self) -> bool: ...
49+
50+
@property
51+
def device_type(self) -> DeviceAllocationType: ...
52+
53+
54+
class MemoryManager(_Weakrefable):
55+
@property
56+
def device(self) -> Device: ...
57+
58+
@property
59+
def is_cpu(self) -> bool: ...
60+
61+
62+
def default_cpu_memory_manager() -> MemoryManager: ...
63+
64+
65+
__all__ = ["DeviceAllocationType", "Device",
66+
"MemoryManager", "default_cpu_memory_manager"]
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
from pyarrow.lib import _Weakrefable
19+
20+
21+
class MemoryPool(_Weakrefable):
22+
def release_unused(self) -> None: ...
23+
24+
def bytes_allocated(self) -> int: ...
25+
26+
def total_bytes_allocated(self) -> int: ...
27+
28+
def max_memory(self) -> int | None: ...
29+
30+
def num_allocations(self) -> int: ...
31+
32+
def print_stats(self) -> None: ...
33+
34+
@property
35+
def backend_name(self) -> str: ...
36+
37+
38+
class LoggingMemoryPool(MemoryPool):
39+
...
40+
41+
42+
class ProxyMemoryPool(MemoryPool):
43+
...
44+
45+
46+
def default_memory_pool() -> MemoryPool: ...
47+
48+
49+
def proxy_memory_pool(parent: MemoryPool) -> ProxyMemoryPool: ...
50+
51+
52+
def logging_memory_pool(parent: MemoryPool) -> LoggingMemoryPool: ...
53+
54+
55+
def system_memory_pool() -> MemoryPool: ...
56+
57+
58+
def jemalloc_memory_pool() -> MemoryPool: ...
59+
60+
61+
def mimalloc_memory_pool() -> MemoryPool: ...
62+
63+
64+
def set_memory_pool(pool: MemoryPool) -> None: ...
65+
66+
67+
def log_memory_allocations(enable: bool = True) -> None: ...
68+
69+
70+
def total_allocated_bytes() -> int: ...
71+
72+
73+
def jemalloc_set_decay_ms(decay_ms: int) -> None: ...
74+
75+
76+
def supported_memory_backends() -> list[str]: ...
77+
78+
79+
__all__ = [
80+
"MemoryPool",
81+
"LoggingMemoryPool",
82+
"ProxyMemoryPool",
83+
"default_memory_pool",
84+
"proxy_memory_pool",
85+
"logging_memory_pool",
86+
"system_memory_pool",
87+
"jemalloc_memory_pool",
88+
"mimalloc_memory_pool",
89+
"set_memory_pool",
90+
"log_memory_allocations",
91+
"total_allocated_bytes",
92+
"jemalloc_set_decay_ms",
93+
"supported_memory_backends",
94+
]

0 commit comments

Comments
 (0)