{"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":null,"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/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/py-polars/src/polars/config.py#L986-L1022","documentation":"Config.set_tbl_cell_alignment only accepts 'LEFT', 'CENTER', or 'RIGHT' (case-insensitive, uppercased internally) for the POLARS_FMT_TABLE_CELL_ALIGNMENT setting. Any other string raises a ValueError. Passing None resets the setting to its default.","triggerScenarios":"pl.Config.set_tbl_cell_alignment('middle'), 'centre', 'justify', or any string not in {LEFT, CENTER, RIGHT}.","commonSituations":"Typing 'CENTER' variants like 'MIDDLE' or 'CENTRE'; loading alignment from a config file with unexpected casing is fine, but unsupported keywords are not.","solutions":["Use one of 'LEFT', 'CENTER', 'RIGHT' (any casing).","Pass None to reset to the default alignment.","Validate against {'LEFT','CENTER','RIGHT'} before calling."],"exampleFix":"// before\npl.Config.set_tbl_cell_alignment(\"middle\")\n// after\npl.Config.set_tbl_cell_alignment(\"CENTER\")","handlingStrategy":"validation","validationCode":"VALID = {\"LEFT\", \"CENTER\", \"RIGHT\"}\nif alignment is not None and alignment.upper() not in VALID:\n    raise ValueError(f\"alignment must be one of {sorted(VALID)}\")\npl.Config.set_tbl_cell_alignment(alignment)","typeGuard":"def is_valid_alignment(v) -> bool:\n    return v is None or (isinstance(v, str) and v.upper() in {\"LEFT\", \"CENTER\", \"RIGHT\"})","tryCatchPattern":"try:\n    pl.Config.set_tbl_cell_alignment(alignment)\nexcept ValueError as e:\n    logging.warning(\"bad alignment %r, using default\", alignment)\n    pl.Config.set_tbl_cell_alignment(None)","preventionTips":["Keep alignment values as a module-level constant set.","Never free-form string alignment values from user config without whitelisting.","Remember comparison is case-insensitive, but the vocabulary is fixed."],"tags":["python","polars","config","invalid-enum-value"],"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"}