{"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/9b5d73fd00236295624374b075d16b1fe6ec6df9/py-polars/src/polars/interchange/utils.py#L110-L146","documentation":"In the import direction, dtype_to_polars_dtype maps an interchange Dtype tuple (kind, bit_width, format_str, endianness) to a Polars dtype via dtype_to_polars_dtype_map[kind][bit_width], after special-casing DATETIME and CATEGORICAL kinds. Unknown kind/bit-width combinations — e.g. FLOAT16, 128-bit integers, or kinds from newer protocol versions — surface as NotImplementedError chained from a KeyError.","triggerScenarios":"pl.from_dataframe(obj) where a producer exposes a dtype Polars' map lacks: float16 columns (common in ML pipelines), exotic widths like uint64-on-nonstandard layouts, or custom DtypeKind values from a protocol fork/newer revision.","commonSituations":"Ingesting half-precision floats from ML feature stores; producers built on newer protocol revisions than the installed Polars; bit widths like 24 or 128 from specialized formats.","solutions":["Cast unsupported columns on the producer side to a supported width (e.g. float16 -> float32 in pyarrow before export).","Upgrade Polars — the supported dtype map grows over releases.","Catch NotImplementedError per column and convert the offending column via another path (e.g. pyarrow -> pl.from_arrow)."],"exampleFix":"# before: obj has a float16 column -> NotImplementedError\ndf = pl.from_dataframe(obj)\n\n# after: widen on the producer side (pyarrow example)\ntbl = tbl.cast({\"emb\": pa.float32()})\ndf = pl.from_dataframe(tbl.__dataframe__())","handlingStrategy":"fallback","validationCode":"# inspect producer dtypes for kinds/widths Polars maps\nimport polars.interchange.utils as u\n\nunknown = [\n    (i, col.dtype) for i in range(icdf.num_columns())\n    if col_dtype_kind_needs_check(icdf.get_column(i))  # kind/bit_width not in u.dtype_to_polars_dtype_map\n]\nif unknown:\n    # cast those columns on the producer (e.g. float16 -> float32) before import\n    ...","typeGuard":null,"tryCatchPattern":"try:\n    df = pl.from_dataframe(obj)\nexcept NotImplementedError as e:\n    if \"unsupported data type\" not in str(e):\n        raise\n    # fall back to the Arrow path, which understands more widths\n    df = pl.from_arrow(obj_to_pyarrow_table(obj))","preventionTips":["Widen float16 to float32 on the producer before interchange export.","Keep Polars current when consuming from producers on newer protocol revisions.","Prefer pl.from_arrow for exotic physical layouts."],"tags":["polars","interchange-protocol","dtype","float16","notimplementederror"],"backgroundTag":"dtype-not-supported","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"}