pola-rs/polars · error · ValueError
Enum categories must be unique; found duplicate {duplicate!r
Error message
Enum categories must be unique; found duplicate {duplicate!r} What it means
Error "Enum categories must be unique; found duplicate {duplicate!r}" thrown in pola-rs/polars.
Source
Thrown at py-polars/src/polars/datatypes/classes.py:1070
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:
return hash((self.__class__, tuple(self.categories)))
def __repr__(self) -> str:
class_name = self.__class__.__name__
return f"{class_name}(categories={self.categories.to_list()!r})"View on GitHub (pinned to df599052da)
When it happens
Trigger: Thrown at py-polars/src/polars/datatypes/classes.py:1070 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/75fcb7462253ff5b.
Report an issue: GitHub.