{"record":{"id":"036eeae7fba884f2","repo":"pola-rs/polars","slug":"df-of-type-qualified-type-name-df-r-does-not","errorCode":null,"errorMessage":"`df` of type {qualified_type_name(df)!r} does not support the dataframe interchange protocol","messagePattern":"`df` of type (.+?) does not support the dataframe interchange protocol","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/interchange/from_dataframe.py","lineNumber":52,"sourceCode":"        Support for the Dataframe Interchange Protocol is deprecated.\n\n    Parameters\n    ----------\n    df\n        Object supporting the dataframe interchange protocol, i.e. must have implemented\n        the `__dataframe__` method.\n    allow_copy\n        Allow memory to be copied to perform the conversion. If set to False, causes\n        conversions that are not zero-copy to fail.\n    \"\"\"\n    if isinstance(df, pl.DataFrame):\n        return df\n    elif isinstance(df, PolarsDataFrame):\n        return df._df\n\n    if not hasattr(df, \"__dataframe__\"):\n        msg = f\"`df` of type {qualified_type_name(df)!r} does not support the dataframe interchange protocol\"\n        raise TypeError(msg)\n\n    return _from_dataframe(\n        df.__dataframe__(allow_copy=allow_copy),  # type: ignore[arg-type]\n        allow_copy=allow_copy,\n    )\n\n\ndef _from_dataframe(df: InterchangeDataFrame, *, allow_copy: bool) -> DataFrame:\n    chunks = []\n    for chunk in df.get_chunks():\n        polars_chunk = _protocol_df_chunk_to_polars(chunk, allow_copy=allow_copy)\n        chunks.append(polars_chunk)\n\n    # Handle implementations that incorrectly yield no chunks for an empty dataframe\n    if not chunks:\n        polars_chunk = _protocol_df_chunk_to_polars(df, allow_copy=allow_copy)\n        chunks.append(polars_chunk)\n","sourceCodeStart":34,"sourceCodeEnd":70,"githubUrl":"https://github.com/pola-rs/polars/blob/9b5d73fd00236295624374b075d16b1fe6ec6df9/py-polars/src/polars/interchange/from_dataframe.py#L34-L70","documentation":"pl.from_dataframe() only accepts objects implementing the dataframe interchange protocol, which it detects by the presence of a __dataframe__ method (pl.DataFrame and Polars interchange wrappers are short-circuited). Anything else — numpy arrays, dicts, lists, frames from libraries without interchange support — raises this TypeError naming the qualified type. Note from_dataframe and the interchange protocol are deprecated since Polars 1.40.0.","triggerScenarios":"pl.from_dataframe(obj) where obj is a numpy.ndarray, dict, list, pl.LazyFrame, duckdb relation, or a pandas DataFrame whose interchange support is unavailable (pandas < 1.5, or pyarrow missing on older pandas).","commonSituations":"Expecting from_dataframe to be a universal converter and passing numpy arrays or dicts; passing a pl.LazyFrame instead of .collect()-ing it; using pandas without pyarrow installed so pandas.DataFrame has no __dataframe__; migrating code after the 1.40 deprecation of the interchange protocol.","solutions":["Use the native constructor for the source type: pl.from_pandas(df), pl.from_arrow(tbl), or pl.from_numpy(arr, schema=...).","For pandas sources, install/upgrade pyarrow (pip install -U pyarrow) and use pandas >= 2.0 so __dataframe__ exists.","For pl.LazyFrame, call .collect() before conversion.","For your own format, implement a __dataframe__ method returning a protocol-conformant object."],"exampleFix":"# before\ndf = pl.from_dataframe(pandas_df)  # TypeError when __dataframe__ is missing\n\n# after\ndf = pl.from_pandas(pandas_df)","handlingStrategy":"type-guard","validationCode":"if isinstance(df, pl.LazyFrame):\n    df = df.collect()\nelif not hasattr(df, \"__dataframe__\"):\n    if hasattr(df, \"to_arrow\"):          # e.g. pyarrow Table\n        df = pl.from_arrow(df.to_arrow())\n    elif hasattr(df, \"columns\") and \"pandas\" in type(df).__module__:\n        df = pl.from_pandas(df)\n    else:\n        raise TypeError(f\"cannot convert {type(df).__name__} to Polars\")","typeGuard":"from typing import Any, Protocol, TypeGuard\n\nclass SupportsInterchange(Protocol):\n    def __dataframe__(self, *, allow_copy: bool = True) -> Any: ...\n\ndef supports_interchange(obj: Any) -> TypeGuard[SupportsInterchange]:\n    return hasattr(obj, \"__dataframe__\")","tryCatchPattern":"try:\n    df = pl.from_dataframe(obj)\nexcept TypeError as e:\n    if \"does not support the dataframe interchange protocol\" not in str(e):\n        raise\n    df = pl.from_pandas(obj) if \"pandas\" in type(obj).__module__ else pl.from_arrow(obj)","preventionTips":["Prefer the type-specific constructors: pl.from_pandas / pl.from_arrow / pl.from_numpy.","Check hasattr(obj, '__dataframe__') before calling pl.from_dataframe.","Keep pyarrow installed and pandas >= 2.0 if you rely on interchange.","Note the interchange API is deprecated since Polars 1.40.0 — plan a migration to Arrow-based conversion."],"tags":["polars","from-dataframe","interchange-protocol","typeerror","pandas","pyarrow"],"backgroundTag":"missing-dataframe-protocol-support","analyzedSha":"9b5d73fd00236295624374b075d16b1fe6ec6df9","analyzedAt":"2026-08-19T12:15:06.350Z","contentChangedAt":"2026-08-19T12:15:06.350Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}