Skip to content

Commit

Permalink
bonus unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-beedie committed Sep 5, 2023
1 parent b3be0df commit effabc4
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions py-polars/tests/unit/test_cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -541,8 +541,7 @@ def test_numeric_right_alignment() -> None:
"└───────┴─────┴─────┘"
)

with pl.Config():
pl.Config.set_fmt_float("mixed")
with pl.Config(fmt_float="mixed"):
assert (
str(df) == "shape: (3, 3)\n"
"┌───────┬─────┬─────┐\n"
Expand All @@ -556,12 +555,23 @@ def test_numeric_right_alignment() -> None:
"└───────┴─────┴─────┘"
)

with pl.Config(float_precision=6):
assert str(df) == (
"shape: (3, 3)\n"
"┌──────────┬──────────┬──────────┐\n"
"│ a ┆ b ┆ c │\n"
"│ --- ┆ --- ┆ --- │\n"
"│ f64 ┆ f64 ┆ f64 │\n"
"╞══════════╪══════════╪══════════╡\n"
"│ 1.100000 ┆ 4.000000 ┆ 7.000000 │\n"
"│ 2.220000 ┆ 5.000000 ┆ 8.000000 │\n"
"│ 3.333000 ┆ 6.000000 ┆ 9.000000 │\n"
"└──────────┴──────────┴──────────┘"
)
df = pl.DataFrame(
{"a": [1.1, 22.2, 3.33], "b": [444, 55.5, 6.6], "c": [77.7, 8888, 9.9999]}
)
with pl.Config():
pl.Config.set_fmt_float("full")
pl.Config.set_float_precision(1)
with pl.Config(fmt_float="full", float_precision=1):
assert (
str(df) == "shape: (3, 3)\n"
"┌──────┬───────┬────────┐\n"
Expand All @@ -582,8 +592,7 @@ def test_numeric_right_alignment() -> None:
"c": [700000.0, 80000000000000000.0, 900],
}
)
with pl.Config():
pl.Config.set_float_precision(2)
with pl.Config(float_precision=2):
assert (
str(df) == "shape: (3, 3)\n"
"┌─────────┬─────────┬───────────┐\n"
Expand All @@ -596,6 +605,7 @@ def test_numeric_right_alignment() -> None:
"│ 3.33e16 ┆ 6.00e17 ┆ 900.00 │\n"
"└─────────┴─────────┴───────────┘"
)

# test nonsensical float precision raises an error
with pytest.raises(ValueError):
pl.Config.set_float_precision(50)
Expand Down

0 comments on commit effabc4

Please sign in to comment.