{"record":{"id":"b4c75ce7919d20f0","repo":"pola-rs/polars","slug":"object-does-not-support-pycapsule-interface-found","errorCode":null,"errorMessage":"object does not support PyCapsule interface; found {obj!r} ","messagePattern":"object does not support PyCapsule interface; found (.+?) ","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/_utils/pycapsule.py","lineNumber":48,"sourceCode":"    rechunk: bool = False,\n) -> DataFrame:\n    \"\"\"Convert PyCapsule object to DataFrame.\"\"\"\n    if hasattr(obj, \"__arrow_c_array__\"):\n        # This uses the fact that PySeries.from_arrow_c_array will create a\n        # struct-typed Series. Then we unpack that to a DataFrame.\n        tmp_col_name = \"\"\n        s = wrap_s(PySeries.from_arrow_c_array(obj))\n        df = s.to_frame(tmp_col_name).unnest(tmp_col_name)\n\n    elif hasattr(obj, \"__arrow_c_stream__\"):\n        # This uses the fact that PySeries.from_arrow_c_stream will create a\n        # struct-typed Series. Then we unpack that to a DataFrame.\n        tmp_col_name = \"\"\n        s = wrap_s(PySeries.from_arrow_c_stream(obj))\n        df = s.to_frame(tmp_col_name).unnest(tmp_col_name)\n    else:\n        msg = f\"object does not support PyCapsule interface; found {obj!r} \"\n        raise TypeError(msg)\n\n    if rechunk:\n        df = df.rechunk()\n    if schema or schema_overrides:\n        df = wrap_df(\n            dataframe_to_pydf(df, schema=schema, schema_overrides=schema_overrides)\n        )\n    return df\n","sourceCodeStart":30,"sourceCodeEnd":57,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/py-polars/src/polars/_utils/pycapsule.py#L30-L57","documentation":"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.","triggerScenarios":"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.","commonSituations":"Old pandas versions lacking Arrow PyCapsule support, passing non-Arrow Python objects, or interop with libraries that don't implement the interface.","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."],"exampleFix":"// before\npldf = pl.from_dataframe(pdf)  # old pandas, no capsule\n// after\npldf = pl.from_pandas(pdf)  # or upgrade pandas to >= 2.x","handlingStrategy":"type-guard","validationCode":"def supports_arrow_capsule(obj) -> bool:\n    return hasattr(obj, \"__arrow_c_stream__\") or hasattr(obj, \"__arrow_c_array__\")","typeGuard":"def has_pycapsule_interface(obj) -> bool:\n    return hasattr(obj, \"__arrow_c_stream__\") or hasattr(obj, \"__arrow_c_array__\")","tryCatchPattern":"try:\n    df = pl.from_dataframe(obj)\nexcept TypeError as e:\n    if \"PyCapsule interface\" in str(e):\n        df = pl.from_pandas(obj) if hasattr(obj, \"to_pandas\") else pl.from_dicts(obj)\n    else:\n        raise","preventionTips":["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."],"tags":["polars","arrow","interop"],"backgroundTag":"incompatible-source-type","analyzedSha":"fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e","analyzedAt":"2026-09-18T22:14:11.667Z","contentChangedAt":"2026-09-18T22:14:11.667Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}