{"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/df599052daf96e7a9cc30a3b0c6bd25d6947e3c0/py-polars/src/polars/_utils/pycapsule.py#L30-L57","documentation":"pycapsule_to_frame (polars/_utils/pycapsule.py:48) ingests objects through the Arrow PyCapsule interface: it needs __arrow_c_array__ or __arrow_c_stream__. If the object exposes neither, it cannot be read as Arrow data and this TypeError is raised naming the object. Public entry points (pl.DataFrame(data) at frame.py:479, pl.from_arrow, pl.from_dataframe) pre-check with is_pycapsule(), so hitting this raise usually means the object's attributes were non-callable, removed between check and use, or an internal call bypassed the check.","triggerScenarios":"pl.DataFrame(numpy_array) or pl.DataFrame(dict) will not hit this (other branches), but pl.from_dataframe(obj) where obj is a plain Python object (no __arrow_c_* or __dataframe__), or an object with non-callable __arrow_c_array__ attributes does; likewise passing a pandas DataFrame when no interchange path is available.","commonSituations":"Assuming from_dataframe accepts any table-like object; DuckDB/Arrow-producing libraries with partially implemented protocols; stub objects in tests missing the capsule methods.","solutions":["Convert with the right constructor: pl.from_pandas(pdf), pl.from_numpy(arr), pl.from_dict(d)","Pass an Arrow-native object: pyarrow.Table or one implementing __arrow_c_stream__/__arrow_c_array__","Implement the Arrow PyCapsule Protocol on your class (expose __arrow_c_stream__ returning a PyCapsule)"],"exampleFix":"# before\npl.from_dataframe(pandas_df)  # no Arrow/interchange support found\n\n# after\npl.from_pandas(pandas_df)  # or pl.from_arrow(pyarrow_table)","handlingStrategy":"type-guard","validationCode":"def is_arrow_capsule(obj) -> bool:\n    return any(\n        callable(getattr(obj, attr, None))\n        for attr in (\"__arrow_c_stream__\", \"__arrow_c_array__\")\n    )\n\nif not is_arrow_capsule(data) and not hasattr(data, \"__dataframe__\"):\n    data = to_arrow_table(data)  # route pandas/numpy/dict through the right converter\npl.from_dataframe(data)","typeGuard":"def is_arrow_capsule(obj) -> bool:\n    return any(\n        callable(getattr(obj, attr, None))\n        for attr in (\"__arrow_c_stream__\", \"__arrow_c_array__\")\n    )","tryCatchPattern":null,"preventionTips":["Match the constructor to the source: from_pandas/from_numpy/from_dict/from_arrow","For zero-copy, pass objects implementing the Arrow PyCapsule Protocol","Verify duckdb/pyarrow-backed objects expose __arrow_c_stream__ in tests"],"tags":["python","polars","arrow","pycapsule","interop","typeerror"],"backgroundTag":null,"analyzedSha":"df599052daf96e7a9cc30a3b0c6bd25d6947e3c0","analyzedAt":"2026-08-16T12:10:03.978Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}