{"record":{"id":"2bbb3ae0c301e398","repo":"pola-rs/polars","slug":"enum-categories-must-be-strings-found-data-of-typ","errorCode":null,"errorMessage":"Enum categories must be strings; found data of type {dtype}","messagePattern":"Enum categories must be strings; found data of type (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/datatypes/classes.py","lineNumber":1065,"sourceCode":"\n            enum_values = [\n                getattr(v, \"value\", v) for v in categories.__members__.values()\n            ]\n            categories = pl.Series(values=enum_values)\n        elif not isinstance(categories, pl.Series):\n            categories = pl.Series(values=categories)\n\n        if categories.is_empty():\n            self.categories = pl.Series(name=\"category\", dtype=String)\n            return\n\n        if categories.has_nulls():\n            msg = \"Enum categories must not contain null values\"\n            raise TypeError(msg)\n\n        if (dtype := categories.dtype) != String:\n            msg = f\"Enum categories must be strings; found data of type {dtype}\"\n            raise TypeError(msg)\n\n        if categories.n_unique() != categories.len():\n            duplicate = categories.filter(categories.is_duplicated())[0]\n            msg = f\"Enum categories must be unique; found duplicate {duplicate!r}\"\n            raise ValueError(msg)\n\n        self.categories = categories.rechunk().alias(\"category\")\n\n    def __eq__(self, other: PolarsDataType) -> bool:  # type: ignore[override]\n        # allow comparing object instances to class\n        if type(other) is DataTypeClass and issubclass(other, Enum):\n            return True\n        elif isinstance(other, Enum):\n            return self.categories.equals(other.categories)\n        else:\n            return False\n\n    def __hash__(self) -> int:","sourceCodeStart":1047,"sourceCodeEnd":1083,"githubUrl":"https://github.com/pola-rs/polars/blob/df599052daf96e7a9cc30a3b0c6bd25d6947e3c0/py-polars/src/polars/datatypes/classes.py#L1047-L1083","documentation":"Error \"Enum categories must be strings; found data of type {dtype}\" thrown in pola-rs/polars.","triggerScenarios":"Thrown at py-polars/src/polars/datatypes/classes.py:1065 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"df599052daf96e7a9cc30a3b0c6bd25d6947e3c0","analyzedAt":"2026-08-16T12:10:03.978Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}