Skip to content

Commit a0d641a

Browse files
attack68topper-123
authored andcommitted
BUG: long int formatting with thousands separator (pandas-dev#53017)
Co-authored-by: JHM Darbyshire (iMac) <[email protected]>
1 parent 8b88210 commit a0d641a

File tree

5 files changed

+12
-36
lines changed

5 files changed

+12
-36
lines changed

pandas/io/formats/style_render.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1747,7 +1747,7 @@ def _default_formatter(x: Any, precision: int, thousands: bool = False) -> Any:
17471747
if is_float(x) or is_complex(x):
17481748
return f"{x:,.{precision}f}" if thousands else f"{x:.{precision}f}"
17491749
elif is_integer(x):
1750-
return f"{x:,.0f}" if thousands else str(x)
1750+
return f"{x:,}" if thousands else str(x)
17511751
return x
17521752

17531753

pandas/tests/io/formats/data/html/gh52272_expected_output.html

-14
This file was deleted.

pandas/tests/io/formats/style/test_format.py

+11
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,17 @@ def test_str_escape_error():
416416
_str_escape(2.00, "bad_escape") # OK since dtype is float
417417

418418

419+
def test_long_int_formatting():
420+
df = DataFrame(data=[[1234567890123456789]], columns=["test"])
421+
styler = df.style
422+
ctx = styler._translate(True, True)
423+
assert ctx["body"][0][1]["display_value"] == "1234567890123456789"
424+
425+
styler = df.style.format(thousands="_")
426+
ctx = styler._translate(True, True)
427+
assert ctx["body"][0][1]["display_value"] == "1_234_567_890_123_456_789"
428+
429+
419430
def test_format_options():
420431
df = DataFrame({"int": [2000, 1], "float": [1.009, None], "str": ["&<", "&~"]})
421432
ctx = df.style._translate(True, True)

pandas/tests/io/formats/test_to_html.py

-8
Original file line numberDiff line numberDiff line change
@@ -896,11 +896,3 @@ def test_to_html_float_format_object_col(datapath):
896896
result = df.to_html(float_format=lambda x: f"{x:,.0f}")
897897
expected = expected_html(datapath, "gh40024_expected_output")
898898
assert result == expected
899-
900-
901-
def test_to_html_float_point_double(datapath):
902-
# GH#52272
903-
df = DataFrame(data=[[1234567890123456789]], columns=["test"])
904-
result = df.to_html()
905-
expected = expected_html(datapath, "gh52272_expected_output")
906-
assert result == expected

pandas/tests/io/formats/test_to_latex.py

-13
Original file line numberDiff line numberDiff line change
@@ -1407,16 +1407,3 @@ def test_to_latex_multiindex_multirow(self):
14071407
"""
14081408
)
14091409
assert result == expected
1410-
1411-
1412-
def test_to_latex_exceeding_float_point_double():
1413-
df = DataFrame(data=[[1234567890123456789]], columns=["test"])
1414-
expected = _dedent(
1415-
r"""
1416-
\begin{tabular}{lr}
1417-
& test \\
1418-
0 & 1234567890123456789 \\
1419-
\end{tabular}
1420-
"""
1421-
)
1422-
assert df.style.to_latex() == expected

0 commit comments

Comments
 (0)