{"record":{"id":"ddefb6bf02e4ab5f","repo":"pola-rs/polars","slug":"unsupported-data-type-dtype-r","errorCode":null,"errorMessage":"unsupported data type: {dtype!r}","messagePattern":"unsupported data type: (.+?)","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/interchange/utils.py","lineNumber":128,"sourceCode":"    },\n    DtypeKind.STRING: {8: String},\n}\n\n\ndef dtype_to_polars_dtype(dtype: Dtype) -> PolarsDataType:\n    \"\"\"Convert interchange protocol data type to Polars data type.\"\"\"\n    kind, bit_width, format_str, _ = dtype\n\n    if kind == DtypeKind.DATETIME:\n        return _temporal_dtype_to_polars_dtype(format_str, dtype)\n    elif kind == DtypeKind.CATEGORICAL:\n        return Enum\n\n    try:\n        return dtype_to_polars_dtype_map[kind][bit_width]\n    except KeyError as exc:\n        msg = f\"unsupported data type: {dtype!r}\"\n        raise NotImplementedError(msg) from exc\n\n\ndef _temporal_dtype_to_polars_dtype(format_str: str, dtype: Dtype) -> PolarsDataType:\n    if (match := re.fullmatch(r\"ts([mun]):(.*)\", format_str)) is not None:\n        time_unit = match.group(1) + \"s\"\n        time_zone = match.group(2) or None\n        return Datetime(\n            time_unit=time_unit,  # type: ignore[arg-type]\n            time_zone=time_zone,\n        )\n    elif format_str == \"tdD\":\n        return Date\n    elif format_str == \"ttu\":\n        return Time\n    elif (match := re.fullmatch(r\"tD([mun])\", format_str)) is not None:\n        time_unit = match.group(1) + \"s\"\n        return Duration(time_unit=time_unit)  # type: ignore[arg-type]\n","sourceCodeStart":110,"sourceCodeEnd":146,"githubUrl":"https://github.com/pola-rs/polars/blob/df599052daf96e7a9cc30a3b0c6bd25d6947e3c0/py-polars/src/polars/interchange/utils.py#L110-L146","documentation":"On the import side, dtype_to_polars_dtype maps a protocol dtype tuple (kind, bit_width, format_string, endianness) to a Polars dtype through dtype_to_polars_dtype_map[kind][bit_width]. If the kind is recognized but the bit width is absent from the map - e.g. FLOAT16, or uncommon integer widths - the KeyError is re-raised as NotImplementedError.","triggerScenarios":"A producer exposing columns with dtype kinds/widths polars does not carry in its map: 16-bit floats, exotic integer widths, or new kinds added by a newer protocol revision.","commonSituations":"ML pipelines that store float16 tensors exposed as dataframes; custom producers; producer upgrades that start emitting widths polars has not mapped.","solutions":["Have the producer widen/cast exotic columns to supported widths (float16 -> float32, odd ints -> Int64)","Upgrade polars in case the dtype was added in a newer release","Skip or transform the offending column upstream before interchange conversion"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"from polars.interchange.utils import dtype_to_polars_dtype\n\ndef dtype_importable(dtype) -> bool:\n    try:\n        dtype_to_polars_dtype(dtype)\n    except NotImplementedError:\n        return False\n    return True","typeGuard":null,"tryCatchPattern":"try:\n    out = pl.from_dataframe(df)\nexcept NotImplementedError as e:\n    if 'unsupported data type' in str(e):\n        raise ValueError(\n            'producer emits a dtype width polars cannot import '\n            '(e.g. float16); widen columns at the source'\n        ) from e\n    raise","preventionTips":["Widen exotic widths (float16, odd int widths) to standard ones in producers before export","Keep producer and polars versions aligned so new dtype kinds are mapped on both sides","Validate producer schema dtypes with dtype_to_polars_dtype in integration tests"],"tags":["polars","interchange-protocol","dtype","not-implemented","import"],"backgroundTag":null,"analyzedSha":"df599052daf96e7a9cc30a3b0c6bd25d6947e3c0","analyzedAt":"2026-08-16T12:10:03.978Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}