{"record":{"id":"3c1134d655637aad","repo":"pola-rs/polars","slug":"encoding-must-be-one-of-hex-base64-got-3c1134","errorCode":null,"errorMessage":"`encoding` must be one of {'hex', 'base64'}, got {encoding!r}","messagePattern":"`encoding` must be one of (.+?), got (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/expr/string.py","lineNumber":1433,"sourceCode":"        >>> df.with_columns(pl.col(\"color\").str.decode(\"hex\").alias(\"decoded\"))\n        shape: (3, 2)\n        ┌────────┬─────────────────┐\n        │ color  ┆ decoded         │\n        │ ---    ┆ ---             │\n        │ str    ┆ binary          │\n        ╞════════╪═════════════════╡\n        │ 000000 ┆ b\"\\x00\\x00\\x00\" │\n        │ ffff00 ┆ b\"\\xff\\xff\\x00\" │\n        │ 0000ff ┆ b\"\\x00\\x00\\xff\" │\n        └────────┴─────────────────┘\n        \"\"\"\n        if encoding == \"hex\":\n            return wrap_expr(self._pyexpr.str_hex_decode(strict))\n        elif encoding == \"base64\":\n            return wrap_expr(self._pyexpr.str_base64_decode(strict))\n        else:\n            msg = f\"`encoding` must be one of {{'hex', 'base64'}}, got {encoding!r}\"\n            raise ValueError(msg)\n\n    def encode(self, encoding: TransferEncoding) -> Expr:\n        \"\"\"\n        Encode values using the provided encoding.\n\n        Parameters\n        ----------\n        encoding : {'hex', 'base64'}\n            The encoding to use.\n\n        .. engine-support:: in-memory, streaming, distributed\n\n        Returns\n        -------\n        Expr\n            Expression of data type :class:`String`.\n\n        Examples","sourceCodeStart":1415,"sourceCodeEnd":1451,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/py-polars/src/polars/expr/string.py#L1415-L1451","documentation":"Expr.str.decode() only supports encoding='hex' or encoding='base64'. Any other value raises this ValueError listing the allowed options. The encodings map to dedicated engine kernels (str_hex_decode / str_base64_decode), so unknown names cannot be dispatched.","triggerScenarios":"Calling Expr.str.decode('utf-8') or decode(encoding='base32') or with case variants like 'Base64' / None.","commonSituations":"Confusing text encoding (utf-8) with transfer encoding (hex/base64); casing mistakes when the encoding comes from config; assuming other encodings like base32 are supported.","solutions":["Use encoding='hex' or encoding='base64'.","Fix casing to lowercase: 'base64' not 'Base64'.","For utf-8 decoding of bytes, that is a String dtype concern, not str.decode — handle it outside the expression."],"exampleFix":"// before\npl.col('s').str.decode('utf-8')\n// after\npl.col('s').str.decode('base64')","handlingStrategy":"validation","validationCode":"if encoding not in ('hex', 'base64'):\n    raise ValueError(f'encoding must be hex or base64, got {encoding!r}')","typeGuard":"from typing import Literal\ndef is_transfer_encoding(e: str) -> bool:\n    return e in ('hex', 'base64')","tryCatchPattern":"try:\n    expr = pl.col('s').str.decode(enc)\nexcept ValueError:\n    expr = pl.col('s').str.decode('base64')","preventionTips":["str.decode is for transfer encodings (hex/base64), not text encodings like utf-8.","Normalize casing of encoding strings from config/user input.","Use the TransferEncoding Literal type in your own wrappers."],"tags":["python","polars","value-error","encoding"],"backgroundTag":"invalid-enum-value","analyzedSha":"fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e","analyzedAt":"2026-09-18T22:14:11.667Z","contentChangedAt":"2026-09-18T22:14:11.667Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}