polars.from_arrow

polars.from_arrow(a: Union[pyarrow.lib.Table, pyarrow.lib.Array, pyarrow.lib.ChunkedArray], rechunk: bool = True) Union[polars.internals.frame.DataFrame, polars.internals.series.Series]

Create a DataFrame or Series from an Arrow Table or Array.

This operation will be zero copy for the most part. Types that are not supported by Polars may be cast to the closest supported type.

Parameters
aArrow Table or Array

Data represented as Arrow Table or Array.

rechunkbool, default True

Make sure that all data is contiguous.

Returns
DataFrame or Series

Examples

Constructing a DataFrame from an Arrow Table:

>>> import pyarrow as pa
>>> data = pa.table({"a": [1, 2, 3], "b": [4, 5, 6]})
>>> df = pl.from_arrow(data)
>>> df
shape: (3, 2)
┌─────┬─────┐
│ a   ┆ b   │
│ --- ┆ --- │
│ i64 ┆ i64 │
╞═════╪═════╡
│ 1   ┆ 4   │
├╌╌╌╌╌┼╌╌╌╌╌┤
│ 2   ┆ 5   │
├╌╌╌╌╌┼╌╌╌╌╌┤
│ 3   ┆ 6   │
└─────┴─────┘

Constructing a Series from an Arrow Array:

>>> import pyarrow as pa
>>> data = pa.array([1, 2, 3])
>>> series = pl.from_arrow(data)
>>> series
shape: (3,)
Series: '' [i64]
[
    1
    2
    3
]