You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Python][Numba] Read and build Arrow arrays in Numba-compiled code #55904
Let @numba.njit functions take pyarrow arrays as arguments, read them without copying, and build new Arrow arrays that are returned to Python as pa.Array.
Motivation
Writing a custom per-element loop over Arrow data from Python means choosing between:
pyarrow.compute: fast, but limited to the kernels that exist, logic that is data dependent or stateful cannot be expressed.
to_numpy() + Numba: needs a copy for nullable arrays, loses the validity bitmap, and does not work for string or binary columns.
Plain Python loops: correct, but orders of magnitude slower.
Numba is widely used for the "custom kernel" case with NumPy. Supporting Arrow directly would let users keep nulls, strings and decimals, avoid copies, and produce Arrow arrays as output.
Proposal
A new optional module, pyarrow.numba, active only when Numba is installed. It registers itself through Numba's numba_extensions entry point, so import pyarrow does not import Numba.
len(a), a[i] (returns None for a null), is_valid(a, i).
Types: integers, floats, bool, date/time/timestamp/duration (as their storage integer), string/binary (and large_*), fixed_size_binary, decimal128 (as an exact (high, low) pair, with decimal_to_float).
Unsupported types (nested, dictionary, decimal256) raise a TypeError at compile time instead of being misread.
Inputs: pa.Array, and any object implementing the Arrow PyCapsule interface (__arrow_c_array__ / __arrow_c_stream__), e.g. polars, pandas, DuckDB, through register_producer(cls) or from_any(obj).
Building
One builder per supported type (Int8Builder … UInt64Builder, Float32/64Builder, BoolBuilder, String/LargeString/Binary/LargeBinaryBuilder) with append(value | None), reserve(n) and finish().
Activity