{"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/df599052daf96e7a9cc30a3b0c6bd25d6947e3c0/py-polars/src/polars/interchange/from_dataframe.py#L34-L70","documentation":"Thrown by pl.from_dataframe when the input is neither a pl.DataFrame, nor a Polars interchange wrapper (PolarsDataFrame), and has no __dataframe__ method. The interchange protocol is the only conversion path this function supports, so any object that does not implement it is rejected up front with TypeError. Note that the whole interchange support in polars is deprecated since version 1.40.0.","triggerScenarios":"Calling pl.from_dataframe(...) with a Python list, dict, numpy array, generator, a Polars LazyFrame (no __dataframe__ method), or a dataframe from a library version that does not implement the protocol (e.g. old pandas, pyspark).","commonSituations":"Mixed-library ETL code that assumes one generic entry point works for every input; upgrading polars to >=1.40.0 where from_dataframe is deprecated; passing a lazy/streaming representation instead of an eager frame; feeding partially-initialized or wrapped dataframe objects.","solutions":["Route by input type: use pl.from_pandas / pl.from_arrow / pl.from_numpy for pandas, Arrow, and numpy inputs instead of from_dataframe","Check hasattr(df, '__dataframe__') before calling pl.from_dataframe and handle the negative branch explicitly","Convert the object to Arrow first (e.g. df.to_arrow()) and call pl.from_arrow(...) which supports nested types too","Migrate away from pl.from_dataframe entirely - the interchange support is deprecated since polars 1.40.0"],"exampleFix":"// before\npl = __import__('polars')\ndf = pl.from_dataframe(some_input)  # raises TypeError if no __dataframe__\n\n// after\nif hasattr(some_input, '__dataframe__'):\n    df = pl.from_dataframe(some_input)\nelif 'pandas' in type(some_input).__module__:\n    df = pl.from_pandas(some_input)\nelif 'pyarrow' in type(some_input).__module__:\n    df = pl.from_arrow(some_input)\nelse:\n    raise TypeError(f'cannot convert {type(some_input)!r}')","handlingStrategy":"type-guard","validationCode":"def can_convert_via_interchange(df: object) -> bool:\n    return hasattr(df, '__dataframe__')","typeGuard":"from typing import Any\n\ndef supports_interchange(df: Any) -> bool:\n    \"\"\"Narrow: True means pl.from_dataframe(df) will pass the protocol check.\"\"\"\n    return hasattr(df, '__dataframe__')","tryCatchPattern":"try:\n    out = pl.from_dataframe(df)\nexcept TypeError as e:\n    if 'does not support the dataframe interchange protocol' in str(e):\n        raise TypeError(f'unsupported input {type(df)!r}; use from_pandas/from_arrow') from e\n    raise","preventionTips":["Route conversions by input type (pandas -> pl.from_pandas, Arrow -> pl.from_arrow, numpy -> pl.from_numpy) instead of one generic call","Check hasattr(df, '__dataframe__') before calling pl.from_dataframe on dynamic inputs","Remember pl.from_dataframe is deprecated since polars 1.40.0 - prefer Arrow-based transfer in new code","Add a unit test that feeds each supported input type through your conversion helper"],"tags":["polars","interchange-protocol","type-error","dataframe","deprecated"],"backgroundTag":null,"analyzedSha":"df599052daf96e7a9cc30a3b0c6bd25d6947e3c0","analyzedAt":"2026-08-16T12:10:03.978Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}