{"record":{"id":"e59576d5c21e0d40","repo":"pola-rs/polars","slug":"unsupported-data-type-dtype","errorCode":null,"errorMessage":"unsupported data type: {dtype}","messagePattern":"unsupported data type: (.+?)","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/interchange/utils.py","lineNumber":173,"sourceCode":"    if rest > 0:\n        msg = f\"cannot get buffer length for buffer with dtype {dtype!r}\"\n        raise ValueError(msg)\n    return buffer_size // bytes_per_element\n\n\ndef polars_dtype_to_data_buffer_dtype(dtype: PolarsDataType) -> PolarsDataType:\n    \"\"\"Get the data type of the data buffer.\"\"\"\n    if dtype.is_integer() or dtype.is_float() or dtype == Boolean:\n        return dtype\n    elif dtype.is_temporal():\n        return Int32 if dtype == Date else Int64\n    elif dtype == String:\n        return UInt8\n    elif dtype in (Enum, Categorical):\n        return UInt32\n\n    msg = f\"unsupported data type: {dtype}\"\n    raise NotImplementedError(msg)\n","sourceCodeStart":155,"sourceCodeEnd":174,"githubUrl":"https://github.com/pola-rs/polars/blob/df599052daf96e7a9cc30a3b0c6bd25d6947e3c0/py-polars/src/polars/interchange/utils.py#L155-L174","documentation":"polars_dtype_to_data_buffer_dtype decides the physical buffer dtype on the export path: integers/floats/booleans map to themselves, temporal types to Int32 (Date) or Int64, String to UInt8, and Enum/Categorical to UInt32. Any other Polars dtype - Binary, Null, Object, or nested types - has no data-buffer representation, so the function raises NotImplementedError.","triggerScenarios":"Exporting a Polars DataFrame containing Binary, Null, Object, or nested (List/Struct/Array) columns through the interchange protocol, i.e. when a consumer walks df.__dataframe__() and reads column buffers.","commonSituations":"Schemas grown via concat or joins that introduced Null-typed columns; Binary payload columns (hashes, encoded blobs) reaching an interchange consumer; nested aggregations passed through unchanged.","solutions":["Drop or cast unsupported columns before export (Binary -> String, fill Null columns with a concrete dtype, flatten nested columns)","Select only protocol-supported columns before handing the frame to an interchange consumer","Use df.to_arrow() for full-fidelity transfer including nested and binary types"],"exampleFix":"// before\ndf.__dataframe__()  # contains Binary/Null column -> NotImplementedError\n\n// after\ndf = df.with_columns(\n    pl.col('payload').cast(pl.String),        # Binary -> String\n    pl.col('maybe').fill_null(0),              # Null -> concrete dtype\n)\ndf.select(exportable_cols).__dataframe__()","handlingStrategy":"validation","validationCode":"import polars as pl\nfrom polars.interchange.utils import polars_dtype_to_data_buffer_dtype\n\ndef columns_have_buffer_representation(df: pl.DataFrame) -> list[str]:\n    bad = []\n    for name, dtype in zip(df.columns, df.dtypes):\n        try:\n            polars_dtype_to_data_buffer_dtype(dtype)\n        except NotImplementedError:\n            bad.append(name)\n    return bad\n\n# usage: assert not columns_have_buffer_representation(df) before export","typeGuard":null,"tryCatchPattern":"try:\n    proto = df.__dataframe__()\nexcept NotImplementedError as e:\n    if 'unsupported data type' in str(e):\n        bad = columns_have_buffer_representation(df)\n        raise ValueError(f'columns without interchange buffers: {bad}') from e\n    raise","preventionTips":["Cast Binary to String, fill Null columns with concrete dtypes, and flatten nested columns before interchange export","Watch for schema drift after concat/join operations that introduce Null-typed columns","Use df.to_arrow() when Binary or nested data must be preserved end to end"],"tags":["polars","interchange-protocol","dtype","export","not-implemented"],"backgroundTag":null,"analyzedSha":"df599052daf96e7a9cc30a3b0c6bd25d6947e3c0","analyzedAt":"2026-08-16T12:10:03.978Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}