{"record":{"id":"39f7f350a521086e","repo":"pola-rs/polars","slug":"expected-pyarrow-table-array-or-one-or-more-reco","errorCode":null,"errorMessage":"expected PyArrow Table, Array, or one or more RecordBatches; got {qualified_type_name(data)!r}","messagePattern":"expected PyArrow Table, Array, or one or more RecordBatches; got (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/convert/general.py","lineNumber":607,"sourceCode":"        )\n\n    if isinstance(data, Iterable):\n        pa_table = pa.Table.from_batches(\n            itertools.chain.from_iterable(\n                (b.to_batches() if isinstance(b, pa.Table) else [b]) for b in data\n            )\n        )\n        return wrap_df(\n            arrow_to_pydf(\n                data=pa_table,\n                rechunk=rechunk,\n                schema=schema,\n                schema_overrides=schema_overrides,\n            )\n        )\n\n    msg = f\"expected PyArrow Table, Array, or one or more RecordBatches; got {qualified_type_name(data)!r}\"\n    raise TypeError(msg)\n\n\n@overload\ndef from_pandas(\n    data: pd.DataFrame,\n    *,\n    schema_overrides: SchemaDict | None = ...,\n    rechunk: bool = ...,\n    nan_to_null: bool = ...,\n    include_index: bool = ...,\n) -> DataFrame: ...\n\n\n@overload\ndef from_pandas(\n    data: pd.Series[Any] | pd.Index[Any] | pd.DatetimeIndex,\n    *,\n    schema_overrides: SchemaDict | None = ...,","sourceCodeStart":589,"sourceCodeEnd":625,"githubUrl":"https://github.com/pola-rs/polars/blob/5d8ebabf11caea54a5c29178a64a058762f49766/py-polars/src/polars/convert/general.py#L589-L625","documentation":"`pl.from_arrow(data)` accepts only `pyarrow.Table`, `pyarrow.Array`/`ChunkedArray`, `pa.RecordBatch`, or a sequence of RecordBatches. Anything else — a `pa.Dataset`, an already-polars DataFrame, a pandas object, an arrow scalar — falls through to a TypeError that names the qualified type of what you passed.","triggerScenarios":"`pl.from_arrow(pa.dataset('data_dir'))` (a Dataset — call `.to_table()` first); `pl.from_arrow(pl.DataFrame(...))` (already polars); `pl.from_arrow(pa.scalar(1))`; `pl.from_arrow(pa.feather.read_table(...))` is fine but a flight `FlightStream` is not.","commonSituations":"Assuming any pyarrow object converts; double-converting data that is already a polars DataFrame; passing datasets or IPC readers instead of materialized tables.","solutions":["For a `pa.Dataset`, materialize first: `pl.from_arrow(ds.to_table())` — or better, scan the files directly with `pl.scan_parquet`/`pl.scan_ipc`.","If the input is already a polars DataFrame/Series, skip the conversion entirely.","Type-check before calling: Table, Array, ChunkedArray, RecordBatch, or a list of batches."],"exampleFix":"# before\nds = pa.dataset(\"s3://bucket/data/\")\ndf = pl.from_arrow(ds)  # TypeError: expected PyArrow Table, Array, ...\n\n# after\ndf = pl.scan_parquet(\"s3://bucket/data/\").collect()  # or pl.from_arrow(ds.to_table())","handlingStrategy":"type-guard","validationCode":"import pyarrow as pa\n\ndef arrow_to_df(data):\n    if isinstance(data, pa.Dataset):\n        data = data.to_table()\n    return pl.from_arrow(data)","typeGuard":"import pyarrow as pa\nfrom typing import Any, TypeGuard\n\nArrowInput = pa.Table | pa.Array | pa.ChunkedArray | pa.RecordBatch | list[pa.RecordBatch] | tuple[pa.RecordBatch, ...]\n\ndef is_arrow_convertible(data: Any) -> TypeGuard[ArrowInput]:\n    return isinstance(data, (pa.Table, pa.Array, pa.ChunkedArray, pa.RecordBatch)) or (\n        isinstance(data, (list, tuple)) and bool(data) and all(isinstance(b, pa.RecordBatch) for b in data)\n    )","tryCatchPattern":null,"preventionTips":["Materialize pa.Dataset to a Table (or scan the files with pl.scan_parquet/pl.scan_ipc) before from_arrow.","Check isinstance against pa.Table/Array/ChunkedArray/RecordBatch at API boundaries.","Skip conversion entirely if the object is already a polars DataFrame."],"tags":["conversion","arrow","typeerror","interop","polars"],"backgroundTag":"invalid-input-type","analyzedSha":"5d8ebabf11caea54a5c29178a64a058762f49766","analyzedAt":"2026-08-19T12:15:06.350Z","contentChangedAt":"2026-08-19T12:15:06.350Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}