Skip to content

Commit

Permalink
fix: Fix set_tbl_width_chars panicking with negative width
Browse files Browse the repository at this point in the history
  • Loading branch information
lukemanley committed Jan 25, 2025
1 parent 1993d59 commit 8d27472
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
3 changes: 3 additions & 0 deletions py-polars/polars/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions py-polars/tests/unit/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]})
Expand Down

0 comments on commit 8d27472

Please sign in to comment.