{"record":{"id":"466b9f2a8563e508","repo":"pola-rs/polars","slug":"describe-categorical-only-works-on-categorical-c","errorCode":null,"errorMessage":"`describe_categorical` only works on categorical columns","messagePattern":"`describe_categorical` only works on categorical columns","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/interchange/column.py","lineNumber":78,"sourceCode":"    def describe_categorical(self) -> CategoricalDescription:\n        \"\"\"\n        Description of the categorical data type of the column.\n\n        Raises\n        ------\n        TypeError\n            If the data type of the column is not categorical.\n        \"\"\"\n        dtype = self._col.dtype\n        if isinstance(dtype, Categorical):\n            categories = self._col.unique().drop_nulls().cast(String)\n            is_ordered = False\n        elif isinstance(dtype, Enum):\n            categories = dtype.categories\n            is_ordered = True\n        else:\n            msg = \"`describe_categorical` only works on categorical columns\"\n            raise TypeError(msg)\n\n        return {\n            \"is_ordered\": is_ordered,\n            \"is_dictionary\": True,\n            \"categories\": PolarsColumn(categories, allow_copy=self._allow_copy),\n        }\n\n    @property\n    def describe_null(self) -> tuple[ColumnNullType, int | None]:\n        \"\"\"Description of the null representation the column uses.\"\"\"\n        if self.null_count == 0:\n            return ColumnNullType.NON_NULLABLE, None\n        else:\n            return ColumnNullType.USE_BITMASK, 0\n\n    @property\n    def null_count(self) -> int:\n        \"\"\"The number of null elements.\"\"\"","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/pola-rs/polars/blob/9b5d73fd00236295624374b075d16b1fe6ec6df9/py-polars/src/polars/interchange/column.py#L60-L96","documentation":"Raised by PolarsColumn.describe_categorical when the column's dtype is neither Categorical nor Enum. The method's contract is to describe categorical metadata (categories, ordering); calling it on any other dtype is a misuse and triggers this error. Check col.dtype / describe_logical first.","triggerScenarios":"Thrown at py-polars/src/polars/interchange/column.py:78 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Only call describe_categorical on columns with the Categorical dtype; cast first with .cast(pl.Categorical) if appropriate."],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"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"}