From 2d17bb5963dc03775121497916377ec1cd98fd0e Mon Sep 17 00:00:00 2001 From: dhruvsamdani Date: Mon, 3 Jan 2022 17:34:09 -0800 Subject: [PATCH 1/3] TST: Create test for #30122 about display.precision --- pandas/tests/io/formats/test_format.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pandas/tests/io/formats/test_format.py b/pandas/tests/io/formats/test_format.py index bf0a10fa702a5..2d5d3c9e0437c 100644 --- a/pandas/tests/io/formats/test_format.py +++ b/pandas/tests/io/formats/test_format.py @@ -2874,6 +2874,18 @@ def test_output_display_precision_trailing_zeroes(self): expected_output = "0 840\n1 4200\ndtype: float64" assert str(s) == expected_output + @pytest.mark.parametrize( + "value", [[9.4444], [0.49], [10.9999], [9.5444, 9.6], [0.46, 0.78, -9.9999]] + ) + def test_set_option_precision(self, value): + # Issue #30122 + # Precision was incorrectly shown + + with option_context("display.precision", 0): + + df = DataFrame(value) + assert str(df) == str(DataFrame(value).round(1)) + def test_output_significant_digits(self): # Issue #9764 From 2629b9bc3d0cafb998b677e3f1d17345da24c229 Mon Sep 17 00:00:00 2001 From: dhruvsamdani Date: Tue, 4 Jan 2022 13:03:43 -0800 Subject: [PATCH 2/3] Updated expected values to be hard coded in parameterization --- pandas/tests/io/formats/test_format.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/pandas/tests/io/formats/test_format.py b/pandas/tests/io/formats/test_format.py index 2d5d3c9e0437c..940b57c234b42 100644 --- a/pandas/tests/io/formats/test_format.py +++ b/pandas/tests/io/formats/test_format.py @@ -2875,16 +2875,24 @@ def test_output_display_precision_trailing_zeroes(self): assert str(s) == expected_output @pytest.mark.parametrize( - "value", [[9.4444], [0.49], [10.9999], [9.5444, 9.6], [0.46, 0.78, -9.9999]] + "value,expected", + [ + ([9.4444], [9]), + ([0.49], [0.5]), + ([10.9999], [11]), + ([9.5444, 9.6], [10, 10]), + ([0.46, 0.78, -9.9999], [0.5, 0.8, -10]), + ], ) - def test_set_option_precision(self, value): + def test_set_option_precision(self, value, expected): # Issue #30122 # Precision was incorrectly shown with option_context("display.precision", 0): - df = DataFrame(value) - assert str(df) == str(DataFrame(value).round(1)) + df_value = DataFrame(value) + df_expected = DataFrame(value) + assert str(df_value) == str(df_expected) def test_output_significant_digits(self): # Issue #9764 From ca0ab101b705170035a791a997e4b982fe221f77 Mon Sep 17 00:00:00 2001 From: dhruvsamdani Date: Tue, 4 Jan 2022 14:46:09 -0800 Subject: [PATCH 3/3] Updated expected values to be hard coded strings in parameterization --- pandas/tests/io/formats/test_format.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/pandas/tests/io/formats/test_format.py b/pandas/tests/io/formats/test_format.py index 940b57c234b42..801bb1845e01e 100644 --- a/pandas/tests/io/formats/test_format.py +++ b/pandas/tests/io/formats/test_format.py @@ -2877,11 +2877,11 @@ def test_output_display_precision_trailing_zeroes(self): @pytest.mark.parametrize( "value,expected", [ - ([9.4444], [9]), - ([0.49], [0.5]), - ([10.9999], [11]), - ([9.5444, 9.6], [10, 10]), - ([0.46, 0.78, -9.9999], [0.5, 0.8, -10]), + ([9.4444], " 0\n0 9"), + ([0.49], " 0\n0 5e-01"), + ([10.9999], " 0\n0 11"), + ([9.5444, 9.6], " 0\n0 10\n1 10"), + ([0.46, 0.78, -9.9999], " 0\n0 5e-01\n1 8e-01\n2 -1e+01"), ], ) def test_set_option_precision(self, value, expected): @@ -2891,8 +2891,7 @@ def test_set_option_precision(self, value, expected): with option_context("display.precision", 0): df_value = DataFrame(value) - df_expected = DataFrame(value) - assert str(df_value) == str(df_expected) + assert str(df_value) == expected def test_output_significant_digits(self): # Issue #9764