polars.from_arrow#
- polars.from_arrow(a: pa.Table | pa.Array | pa.ChunkedArray, rechunk: bool = True, schema: Sequence[str] | None = None, schema_overrides: SchemaDict | None = None) DataFrame | Series [source]#
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:
- a
pyarrow.Table
orpyarrow.Array
Data representing an Arrow Table or Array.
- rechunkbool, default True
Make sure that all data is in contiguous memory.
- schemaSequence of str, dict, default None
Column labels to use for resulting DataFrame. Must match data dimensions. If not specified, existing Array table columns are used, with missing names named as column_0, column_1, etc.
- schemaSequence of str, (str,DataType) pairs, or a {str:DataType,} dict
The DataFrame schema may be declared in several ways:
As a dict of {name:type} pairs; if type is None, it will be auto-inferred.
As a list of column names; in this case types are automatically inferred.
As a list of (name,type) pairs; this is equivalent to the dictionary form.
If you supply a list of column names that does not match the names in the underlying data, the names given here will overwrite them. The number of names given in the schema should match the underlying data dimensions.
- schema_overridesdict, default None
Support type specification or override of one or more columns; note that any dtypes inferred from the schema param will be overridden.
- a
- Returns:
DataFrame
orSeries
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 ]