{"record":{"id":"777a96990029ab03","repo":"pola-rs/polars","slug":"invalid-alignment-format-r","errorCode":null,"errorMessage":"invalid alignment: {format!r}","messagePattern":"invalid alignment: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/config.py","lineNumber":1004,"sourceCode":"        ┌────────────┬────────────┐\n        │ column_abc ┆ column_xyz │\n        │        --- ┆        --- │\n        │        f64 ┆       bool │\n        ╞════════════╪════════════╡\n        │        1.0 ┆       true │\n        │        2.5 ┆      false │\n        │        5.0 ┆       true │\n        └────────────┴────────────┘\n\n        Raises\n        ------\n        ValueError: if alignment string not recognised.\n        \"\"\"\n        if format is None:\n            os.environ.pop(\"POLARS_FMT_TABLE_CELL_ALIGNMENT\", None)\n        elif (format := format.upper()) not in {\"LEFT\", \"CENTER\", \"RIGHT\"}:  # type: ignore[assignment]\n            msg = f\"invalid alignment: {format!r}\"\n            raise ValueError(msg)\n        else:\n            os.environ[\"POLARS_FMT_TABLE_CELL_ALIGNMENT\"] = format\n        plr.config_reload_env_var(\"POLARS_FMT_TABLE_CELL_ALIGNMENT\")\n        return cls\n\n    @classmethod\n    def set_tbl_cell_numeric_alignment(cls, format: Alignment | None) -> type[Config]:\n        \"\"\"\n        Set table cell alignment for numeric columns.\n\n        Parameters\n        ----------\n        format : str\n            * \"LEFT\": left aligned\n            * \"CENTER\": center aligned\n            * \"RIGHT\": right aligned\n\n        Examples","sourceCodeStart":986,"sourceCodeEnd":1022,"githubUrl":"https://github.com/pola-rs/polars/blob/68506541d2de983056c9eb244e1ea05fab377dfc/py-polars/src/polars/config.py#L986-L1022","documentation":"`pl.Config.set_tbl_cell_alignment(format)` upper-cases the input and requires one of LEFT, CENTER, or RIGHT (None clears the setting). Any other string raises ValueError before POLARS_FMT_TABLE_CELL_ALIGNMENT is written.","triggerScenarios":"`pl.Config.set_tbl_cell_alignment('centre')` (British spelling), 'middle', 'justify', 'default', or a numeric alignment code.","commonSituations":"Non-US spelling ('centre'); guessing alignment names; passing an enum value from another library.","solutions":["Use one of 'LEFT', 'CENTER', 'RIGHT' (any casing — it is upper-cased for you).","Pass None to reset to the default alignment."],"exampleFix":"# before\npl.Config.set_tbl_cell_alignment(\"centre\")  # ValueError: invalid alignment\n\n# after\npl.Config.set_tbl_cell_alignment(\"CENTER\")","handlingStrategy":"validation","validationCode":"VALID_ALIGNMENTS = frozenset({\"LEFT\", \"CENTER\", \"RIGHT\"})\n\ndef set_alignment(fmt: str | None) -> None:\n    if fmt is not None and fmt.upper() not in VALID_ALIGNMENTS:\n        raise ValueError(f\"alignment must be one of {sorted(VALID_ALIGNMENTS)}, got {fmt!r}\")\n    pl.Config.set_tbl_cell_alignment(fmt)","typeGuard":"from typing import Literal\n\nAlignment = Literal[\"LEFT\", \"CENTER\", \"RIGHT\"]\n\ndef is_alignment(value: str) -> TypeGuard[Alignment]:\n    return value.upper() in {\"LEFT\", \"CENTER\", \"RIGHT\"}","tryCatchPattern":null,"preventionTips":["Use a Literal['LEFT','CENTER','RIGHT'] type in your own wrappers so typos fail type-check.","Normalize user input with .upper() and validate against a set before passing."],"tags":["config","table-display","formatting","validation","polars"],"backgroundTag":"invalid-argument-value","analyzedSha":"68506541d2de983056c9eb244e1ea05fab377dfc","analyzedAt":"2026-08-19T12:15:06.350Z","contentChangedAt":"2026-08-19T12:15:06.350Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}