pola-rs/polars · error · TypeError
Enum categories must be strings; found data of type {dtype}
Error message
Enum categories must be strings; found data of type {dtype} What it means
Error "Enum categories must be strings; found data of type {dtype}" thrown in pola-rs/polars.
Source
Thrown at py-polars/src/polars/datatypes/classes.py:1065
enum_values = [
getattr(v, "value", v) for v in categories.__members__.values()
]
categories = pl.Series(values=enum_values)
elif not isinstance(categories, pl.Series):
categories = pl.Series(values=categories)
if categories.is_empty():
self.categories = pl.Series(name="category", dtype=String)
return
if categories.has_nulls():
msg = "Enum categories must not contain null values"
raise TypeError(msg)
if (dtype := categories.dtype) != String:
msg = f"Enum categories must be strings; found data of type {dtype}"
raise TypeError(msg)
if categories.n_unique() != categories.len():
duplicate = categories.filter(categories.is_duplicated())[0]
msg = f"Enum categories must be unique; found duplicate {duplicate!r}"
raise ValueError(msg)
self.categories = categories.rechunk().alias("category")
def __eq__(self, other: PolarsDataType) -> bool: # type: ignore[override]
# allow comparing object instances to class
if type(other) is DataTypeClass and issubclass(other, Enum):
return True
elif isinstance(other, Enum):
return self.categories.equals(other.categories)
else:
return False
def __hash__(self) -> int:View on GitHub (pinned to df599052da)
When it happens
Trigger: Thrown at py-polars/src/polars/datatypes/classes.py:1065 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of pola-rs/polars@df599052da (2026-08-16).
Data as JSON: /api/errors/2bbb3ae0c301e398.
Report an issue: GitHub.