pola-rs/polars · error · TypeError
object does not support PyCapsule interface; found
Error message
object does not support PyCapsule interface; found {obj!r} What it means
pycapsule_to_frame accepts objects implementing the Arrow PyCapsule Interface (__arrow_c_stream__/__arrow_c_array__). If the object supports neither interface, polars cannot import it and raises TypeError showing the object's repr.
Solutions
- Upgrade pandas/pyarrow so the source object implements __arrow_c_stream__.
- Convert via Arrow first: pl.from_pandas(df) or pl.from_arrow(table) instead of the capsule path.
- Pass a supported object type (Arrow Table/RecordBatch, capsule-capable frame) to from_dataframe.
- For plain Python data use pl.DataFrame(rows) or pl.from_dicts(...) rather than from_dataframe.
Example fix
// before pldf = pl.from_dataframe(pdf) # old pandas, no capsule // after pldf = pl.from_pandas(pdf) # or upgrade pandas to >= 2.x
Defensive patterns
Strategy: type-guard
Validate before calling
def supports_arrow_capsule(obj) -> bool:
return hasattr(obj, "__arrow_c_stream__") or hasattr(obj, "__arrow_c_array__") Type guard
def has_pycapsule_interface(obj) -> bool:
return hasattr(obj, "__arrow_c_stream__") or hasattr(obj, "__arrow_c_array__") Try / catch
try:
df = pl.from_dataframe(obj)
except TypeError as e:
if "PyCapsule interface" in str(e):
df = pl.from_pandas(obj) if hasattr(obj, "to_pandas") else pl.from_dicts(obj)
else:
raise Prevention
- Upgrade pandas/pyarrow to versions implementing the Arrow PyCapsule interface.
- Route non-capsule sources through from_pandas/from_arrow/from_dicts.
- Check hasattr(obj, "__arrow_c_stream__") before calling from_dataframe.
- Pin library versions in requirements to keep interop predictable.
When it happens
Trigger: Calling pl.from_dataframe(obj) or pl.DataFrame(obj) where obj is not an Arrow-C-compatible object (e.g. a pandas DataFrame from an old pandas without __arrow_c_stream__, a dict, or a plain list) and no capsule interface is found.
Common situations: Old pandas versions lacking Arrow PyCapsule support, passing non-Arrow Python objects, or interop with libraries that don't implement the interface.
Understand the failure class
Background: "is not a compatible type" / "cannot merge" errors: when a value's type doesn't match what the library requires — this error's family across 65 libraries.
Related errors
- activate dtype-categorical to convert dictionary arrays
- activate the 'dtype-struct' feature to handle struct data…
- cannot parse Python data type
- Deserialization from JSON not implemented for
- expected object supporting the PyCapsule Interface, got
AI-assisted analysis of pola-rs/polars@fe841f959e (2026-09-18).
Data as JSON: /api/errors/b4c75ce7919d20f0.
Report an issue: GitHub.
Appendix: source
Thrown at py-polars/src/polars/_utils/pycapsule.py:48
rechunk: bool = False,
) -> DataFrame:
"""Convert PyCapsule object to DataFrame."""
if hasattr(obj, "__arrow_c_array__"):
# This uses the fact that PySeries.from_arrow_c_array will create a
# struct-typed Series. Then we unpack that to a DataFrame.
tmp_col_name = ""
s = wrap_s(PySeries.from_arrow_c_array(obj))
df = s.to_frame(tmp_col_name).unnest(tmp_col_name)
elif hasattr(obj, "__arrow_c_stream__"):
# This uses the fact that PySeries.from_arrow_c_stream will create a
# struct-typed Series. Then we unpack that to a DataFrame.
tmp_col_name = ""
s = wrap_s(PySeries.from_arrow_c_stream(obj))
df = s.to_frame(tmp_col_name).unnest(tmp_col_name)
else:
msg = f"object does not support PyCapsule interface; found {obj!r} "
raise TypeError(msg)
if rechunk:
df = df.rechunk()
if schema or schema_overrides:
df = wrap_df(
dataframe_to_pydf(df, schema=schema, schema_overrides=schema_overrides)
)
return df
View on GitHub (pinned to fe841f959e)