Ray's Knowledge Base
Unlock

Python conversions go through the Arrow PyCapsule when it keeps the type

DecisionVerified 4 Oct 2026Holds project: dftracer-utils
Decision. The context, the choice, why, and the options that were turned down.

Context#

to_pandas, to_polars and to_list filled values one by one and decoded dictionary strings per row.

Decision#

  • D1: in Arrow builds to_polars uses pl.DataFrame(self) / pl.Series(self) through the Arrow PyCapsule (polars >= 1.3, no pyarrow). Float16, decimals and pure dictionary columns stay native, because Arrow gives polars Float16, precision-kept decimals and Categorical where the native path gives Float32, precision 38 and String. A frame uses the stream only when every column qualifies.
  • D2: to_pandas builds string columns from the Arrow array when pandas' default str dtype has pyarrow storage (pandas 3). A dictionary<string_view> must be rebuilt with a large_string dictionary before pyarrow can cast it.
  • D3: the native string fill decodes each dictionary entry once (StringFiller in convert.cpp).

Why#

Measured on laghos: to_pandas 657 -> 131 ms, to_polars 715 -> 143 ms, to_list 32 -> 5.4 ms.

Rejected options#

  • pl.from_arrow: it warns that it returns a Series for streams in polars 2.0.
  • pyarrow.table.

Also found by searching

  • to_pandas and to_polars are slow on string columns
  • how does to_polars convert without pyarrow
  • pl.from_arrow warns it returns a Series for streams
  • cannot cast dictionary<string_view> with pyarrow