Skip to content

Commit 1d6272c

Browse files
authored
TST: Create test for #30122 about display.precision (#45185)
1 parent f46df11 commit 1d6272c

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

pandas/tests/io/formats/test_format.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2874,6 +2874,25 @@ def test_output_display_precision_trailing_zeroes(self):
28742874
expected_output = "0 840\n1 4200\ndtype: float64"
28752875
assert str(s) == expected_output
28762876

2877+
@pytest.mark.parametrize(
2878+
"value,expected",
2879+
[
2880+
([9.4444], " 0\n0 9"),
2881+
([0.49], " 0\n0 5e-01"),
2882+
([10.9999], " 0\n0 11"),
2883+
([9.5444, 9.6], " 0\n0 10\n1 10"),
2884+
([0.46, 0.78, -9.9999], " 0\n0 5e-01\n1 8e-01\n2 -1e+01"),
2885+
],
2886+
)
2887+
def test_set_option_precision(self, value, expected):
2888+
# Issue #30122
2889+
# Precision was incorrectly shown
2890+
2891+
with option_context("display.precision", 0):
2892+
2893+
df_value = DataFrame(value)
2894+
assert str(df_value) == expected
2895+
28772896
def test_output_significant_digits(self):
28782897
# Issue #9764
28792898

0 commit comments

Comments
 (0)