pyarrow-stubs

20.0.0.20251215 · active · verified Fri Apr 10

pyarrow-stubs provides type annotations for the Apache Arrow Python library (PyArrow). Its purpose is to enable static type checking tools like MyPy and Pyright to analyze code that uses PyArrow, improving code quality and catching potential errors at development time. The current version is 20.0.0.20251215, with releases typically aligning with PyArrow's development, and ongoing discussions about potentially integrating stubs directly into the main Apache Arrow project.

Warnings

Install

Imports

Quickstart

This example demonstrates creating a PyArrow Table with explicit type hints. When `pyarrow-stubs` is installed, a type checker like MyPy or Pyright will use these stubs to validate the types in your code, for example, ensuring that `create_arrow_table` returns a `pa.Table`.

import pyarrow as pa
from typing import List

def create_arrow_table(names: List[str], ages: List[int]) -> pa.Table:
    """Creates a PyArrow Table from names and ages."""
    if not (len(names) == len(ages)):
        raise ValueError("Lengths of names and ages must match.")
    
    # Create PyArrow Arrays
    name_array = pa.array(names, type=pa.string())
    age_array = pa.array(ages, type=pa.int64())
    
    # Create a PyArrow Table
    table = pa.table({'name': name_array, 'age': age_array})
    return table

if __name__ == "__main__":
    my_names = ["Alice", "Bob", "Charlie"]
    my_ages = [30, 24, 35]
    
    # This call would be type-checked by tools like MyPy/Pyright
    person_table: pa.Table = create_arrow_table(my_names, my_ages)
    
    print("Created PyArrow Table:")
    print(person_table)

    print(f"\nFirst person's name: {person_table.column('name')[0].as_py()}")

view raw JSON →