From effabc420e96da86f0d27fb2b147bc3cf4750254 Mon Sep 17 00:00:00 2001 From: alexander-beedie Date: Sun, 27 Aug 2023 18:49:46 +0400 Subject: [PATCH] bonus unit test --- py-polars/tests/unit/test_cfg.py | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/py-polars/tests/unit/test_cfg.py b/py-polars/tests/unit/test_cfg.py index ae71ebc2b1209..d689a0b413fa6 100644 --- a/py-polars/tests/unit/test_cfg.py +++ b/py-polars/tests/unit/test_cfg.py @@ -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" @@ -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" @@ -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" @@ -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)