Skip to content

Commit

Permalink
BUG: long int formatting with thousands separator (pandas-dev#53017)
Browse files Browse the repository at this point in the history
Co-authored-by: JHM Darbyshire (iMac) <[email protected]>
  • Loading branch information
attack68 and attack68 authored May 1, 2023
1 parent 187e2b0 commit 7772f0f
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 36 deletions.
2 changes: 1 addition & 1 deletion pandas/io/formats/style_render.py
Original file line number Diff line number Diff line change
Expand Up @@ -1747,7 +1747,7 @@ def _default_formatter(x: Any, precision: int, thousands: bool = False) -> Any:
if is_float(x) or is_complex(x):
return f"{x:,.{precision}f}" if thousands else f"{x:.{precision}f}"
elif is_integer(x):
return f"{x:,.0f}" if thousands else str(x)
return f"{x:,}" if thousands else str(x)
return x


Expand Down
14 changes: 0 additions & 14 deletions pandas/tests/io/formats/data/html/gh52272_expected_output.html

This file was deleted.

11 changes: 11 additions & 0 deletions pandas/tests/io/formats/style/test_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,17 @@ def test_str_escape_error():
_str_escape(2.00, "bad_escape") # OK since dtype is float


def test_long_int_formatting():
df = DataFrame(data=[[1234567890123456789]], columns=["test"])
styler = df.style
ctx = styler._translate(True, True)
assert ctx["body"][0][1]["display_value"] == "1234567890123456789"

styler = df.style.format(thousands="_")
ctx = styler._translate(True, True)
assert ctx["body"][0][1]["display_value"] == "1_234_567_890_123_456_789"


def test_format_options():
df = DataFrame({"int": [2000, 1], "float": [1.009, None], "str": ["&<", "&~"]})
ctx = df.style._translate(True, True)
Expand Down
8 changes: 0 additions & 8 deletions pandas/tests/io/formats/test_to_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -896,11 +896,3 @@ def test_to_html_float_format_object_col(datapath):
result = df.to_html(float_format=lambda x: f"{x:,.0f}")
expected = expected_html(datapath, "gh40024_expected_output")
assert result == expected


def test_to_html_float_point_double(datapath):
# GH#52272
df = DataFrame(data=[[1234567890123456789]], columns=["test"])
result = df.to_html()
expected = expected_html(datapath, "gh52272_expected_output")
assert result == expected
13 changes: 0 additions & 13 deletions pandas/tests/io/formats/test_to_latex.py
Original file line number Diff line number Diff line change
Expand Up @@ -1407,16 +1407,3 @@ def test_to_latex_multiindex_multirow(self):
"""
)
assert result == expected


def test_to_latex_exceeding_float_point_double():
df = DataFrame(data=[[1234567890123456789]], columns=["test"])
expected = _dedent(
r"""
\begin{tabular}{lr}
& test \\
0 & 1234567890123456789 \\
\end{tabular}
"""
)
assert df.style.to_latex() == expected

0 comments on commit 7772f0f

Please sign in to comment.