{"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":null,"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/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/py-polars/src/polars/config.py#L865-L901","documentation":"Value validation in Config.set_fmt_str_lengths: the setter requires a positive integer for the maximum string length shown in formatted output; passing 0 or a negative value violates the invariant that at least one character must be displayed.","triggerScenarios":"pl.Config.set_fmt_str_lengths(0) or set_fmt_str_lengths(-5); passing None resets the env var and is allowed.","commonSituations":"Computing the length dynamically and getting 0/negative; misreading the API as 'extra padding' rather than an absolute count.","solutions":["Pass a positive integer, e.g. set_fmt_str_lengths(50)","Pass None to reset to the default","Guard with max(1, n) when computing dynamically"],"exampleFix":"// before\npl.Config.set_fmt_str_lengths(len(df))  # 0 -> ValueError\n// after\npl.Config.set_fmt_str_lengths(max(1, len(df)))","handlingStrategy":"validation","validationCode":"n = 50  # computed\nassert n is None or n > 0, f'n must be > 0, got {n}'","typeGuard":"def valid_str_len(n: int | None) -> bool:\n    return n is None or n > 0","tryCatchPattern":"try:\n    pl.Config.set_fmt_str_lengths(n)\nexcept ValueError:\n    pl.Config.set_fmt_str_lengths(None)  # fall back to default","preventionTips":["Guard computed values with max(1, n)","Use None to reset instead of 0","Set generous positive values (e.g. >= 10) for display"],"tags":["polars","config","display"],"backgroundTag":"argument-out-of-range","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"}