diff --git a/py-polars/polars/config.py b/py-polars/polars/config.py index fd31a1e425d6..3077cfde8fc6 100644 --- a/py-polars/polars/config.py +++ b/py-polars/polars/config.py @@ -1353,6 +1353,9 @@ def set_tbl_width_chars(cls, width: int | None) -> type[Config]: """ if width is None: os.environ.pop("POLARS_TABLE_WIDTH", None) + elif width < 0: + msg = "width should be positive" + raise ValueError(msg) else: os.environ["POLARS_TABLE_WIDTH"] = str(width) return cls diff --git a/py-polars/tests/unit/test_config.py b/py-polars/tests/unit/test_config.py index 9535f11b3825..2d8b29ed6c74 100644 --- a/py-polars/tests/unit/test_config.py +++ b/py-polars/tests/unit/test_config.py @@ -371,6 +371,9 @@ def test_set_tbl_width_chars() -> None: with pl.Config(tbl_width_chars=87): assert max(len(line) for line in str(df).split("\n")) == 87 + with pytest.raises(ValueError, match="width should be positive"): + pl.Config.set_tbl_width_chars(-1) + def test_shape_below_table_and_inlined_dtype() -> None: df = pl.DataFrame({"a": [1, 2], "b": [3, 4], "c": [5, 6]})