pola-rs/polars · error · NotImplementedError
unsupported data type: {dtype!r}
Error message
unsupported data type: {dtype!r} What it means
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.
Source
Thrown at py-polars/src/polars/interchange/utils.py:128
},
DtypeKind.STRING: {8: String},
}
def dtype_to_polars_dtype(dtype: Dtype) -> PolarsDataType:
"""Convert interchange protocol data type to Polars data type."""
kind, bit_width, format_str, _ = dtype
if kind == DtypeKind.DATETIME:
return _temporal_dtype_to_polars_dtype(format_str, dtype)
elif kind == DtypeKind.CATEGORICAL:
return Enum
try:
return dtype_to_polars_dtype_map[kind][bit_width]
except KeyError as exc:
msg = f"unsupported data type: {dtype!r}"
raise NotImplementedError(msg) from exc
def _temporal_dtype_to_polars_dtype(format_str: str, dtype: Dtype) -> PolarsDataType:
if (match := re.fullmatch(r"ts([mun]):(.*)", format_str)) is not None:
time_unit = match.group(1) + "s"
time_zone = match.group(2) or None
return Datetime(
time_unit=time_unit, # type: ignore[arg-type]
time_zone=time_zone,
)
elif format_str == "tdD":
return Date
elif format_str == "ttu":
return Time
elif (match := re.fullmatch(r"tD([mun])", format_str)) is not None:
time_unit = match.group(1) + "s"
return Duration(time_unit=time_unit) # type: ignore[arg-type]
View on GitHub (pinned to df599052da)
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
Defensive patterns
Strategy: try-catch
Validate before calling
from polars.interchange.utils import dtype_to_polars_dtype
def dtype_importable(dtype) -> bool:
try:
dtype_to_polars_dtype(dtype)
except NotImplementedError:
return False
return True Try / catch
try:
out = pl.from_dataframe(df)
except NotImplementedError as e:
if 'unsupported data type' in str(e):
raise ValueError(
'producer emits a dtype width polars cannot import '
'(e.g. float16); widen columns at the source'
) from e
raise Prevention
- 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
When it happens
Trigger: 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.
Common situations: ML pipelines that store float16 tensors exposed as dataframes; custom producers; producer upgrades that start emitting widths polars has not mapped.
Related errors
- unsupported data type: {dtype}
- non-dictionary categoricals are not yet supported
- non-string categories are not supported
- unsupported null type: {null_type!r}
- data type {dtype!r} not supported by the interchange protoco
AI-assisted analysis of pola-rs/polars@df599052da (2026-08-16).
Data as JSON: /api/errors/ddefb6bf02e4ab5f.
Report an issue: GitHub.