{"record":{"id":"ab7839af84555221","repo":"pola-rs/polars","slug":"number-of-characters-must-be-0","errorCode":null,"errorMessage":"number of characters must be > 0","messagePattern":"number of characters must be > 0","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/config.py","lineNumber":883,"sourceCode":"        └─────────────────────────────────┴─────┘\n        >>> with pl.Config(fmt_str_lengths=50):\n        ...     print(df)\n        shape: (2, 1)\n        ┌──────────────────────────────────────────────────┐\n        │ txt                                              │\n        │ ---                                              │\n        │ str                                              │\n        ╞══════════════════════════════════════════════════╡\n        │ Play it, Sam. Play 'As Time Goes By'.            │\n        │ This is the beginning of a beautiful friendship. │\n        └──────────────────────────────────────────────────┘\n        \"\"\"\n        if n is None:\n            os.environ.pop(\"POLARS_FMT_STR_LEN\", None)\n        else:\n            if n <= 0:\n                msg = \"number of characters must be > 0\"\n                raise ValueError(msg)\n\n            os.environ[\"POLARS_FMT_STR_LEN\"] = str(n)\n        plr.config_reload_env_var(\"POLARS_FMT_STR_LEN\")\n        return cls\n\n    @classmethod\n    def set_fmt_table_cell_list_len(cls, n: int | None) -> type[Config]:\n        \"\"\"\n        Set the number of elements to display for List values.\n\n        Empty lists will always print \"[]\". Negative values will result in all values\n        being printed. A value of 0 will always \"[…]\" for lists with contents. A value\n        of 1 will print only the final item in the list.\n\n        Parameters\n        ----------\n        n : int\n            Number of values to display.","sourceCodeStart":865,"sourceCodeEnd":901,"githubUrl":"https://github.com/pola-rs/polars/blob/68506541d2de983056c9eb244e1ea05fab377dfc/py-polars/src/polars/config.py#L865-L901","documentation":"`pl.Config.set_fmt_str_lengths(n)` sets how many characters of string values are shown when printing. A non-None value must be > 0 because a truncation length of 0 or negative is meaningless; 0 does NOT mean 'unlimited'. None removes the POLARS_FMT_STR_LEN env var and resets the limit.","triggerScenarios":"`pl.Config.set_fmt_str_lengths(0)` (hoping to disable truncation) or a negative value; passing a computed length that ended up <= 0.","commonSituations":"Users pass 0 expecting to show full strings; the correct way to remove the limit is None (or a very large value).","solutions":["To remove the limit: `pl.Config.set_fmt_str_lengths(None)`.","To effectively show everything: pass a large value such as `pl.Config.set_fmt_str_lengths(10_000)`.","Guard computed values: `max(1, n)` before passing."],"exampleFix":"# before\npl.Config.set_fmt_str_lengths(0)  # ValueError: number of characters must be > 0\n\n# after\npl.Config.set_fmt_str_lengths(None)  # no truncation limit","handlingStrategy":"validation","validationCode":"def set_str_lengths(n: int | None) -> None:\n    if n is not None and n <= 0:\n        raise ValueError(\"use None to remove the string-length limit, not 0\")\n    pl.Config.set_fmt_str_lengths(n)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Treat None as 'no limit'; never use 0 for that meaning.","Clamp user-supplied display settings: n = None if n in (0, 'unlimited') else max(1, int(n))."],"tags":["config","formatting","display","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"}