Skip to content

Commit 5c80570

Browse files
author
AntonioAndraues
committed
change to IO and add comment
1 parent 6fb3760 commit 5c80570

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

doc/source/whatsnew/v1.0.0.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,7 @@ I/O
354354
- Bug in :func:`read_hdf` closing stores that it didn't open when Exceptions are raised (:issue:`28699`)
355355
- Bug in :meth:`DataFrame.read_json` where using ``orient="index"`` would not maintain the order (:issue:`28557`)
356356
- Bug in :meth:`DataFrame.to_html` where the length of the ``formatters`` argument was not verified (:issue:`28469`)
357+
- Bug in :meth:`pandas.io.formats.style.Styler` formatting for floating values not displaying decimals correctly (:issue:`13257`)
357358

358359
Plotting
359360
^^^^^^^^

pandas/tests/io/formats/test_style.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1158,6 +1158,7 @@ def test_display_format_raises(self):
11581158
df.style.format(True)
11591159

11601160
def test_display_set_precision(self):
1161+
# Issue #13257
11611162
df = pd.DataFrame(data=[[1.0, 2.0090], [3.2121, 4.566]], columns=["a", "b"])
11621163
s = Styler(df)
11631164

@@ -1189,22 +1190,18 @@ def test_display_subset(self):
11891190
{"a": "{:0.1f}", "b": "{0:.2%}"}, subset=pd.IndexSlice[0, :]
11901191
)._translate()
11911192
expected = "0.1"
1192-
assert ctx["body"][0][1]["display_value"] == expected
1193-
assert ctx["body"][1][1]["display_value"] == "1.1234"
1194-
assert ctx["body"][0][2]["display_value"] == "12.34%"
1195-
1196-
raw_11 = "1.1234"
1197-
ctx = df.style.format("{:0.1f}", subset=pd.IndexSlice[0, :])._translate()
1193+
raw_11 = "1.123400"
11981194
assert ctx["body"][0][1]["display_value"] == expected
11991195
assert ctx["body"][1][1]["display_value"] == raw_11
1196+
assert ctx["body"][0][2]["display_value"] == "12.34%"
12001197

12011198
ctx = df.style.format("{:0.1f}", subset=pd.IndexSlice[0, :])._translate()
12021199
assert ctx["body"][0][1]["display_value"] == expected
12031200
assert ctx["body"][1][1]["display_value"] == raw_11
12041201

12051202
ctx = df.style.format("{:0.1f}", subset=pd.IndexSlice["a"])._translate()
12061203
assert ctx["body"][0][1]["display_value"] == expected
1207-
assert ctx["body"][0][2]["display_value"] == "0.1234"
1204+
assert ctx["body"][0][2]["display_value"] == "0.123400"
12081205

12091206
ctx = df.style.format("{:0.1f}", subset=pd.IndexSlice[0, "a"])._translate()
12101207
assert ctx["body"][0][1]["display_value"] == expected
@@ -1215,8 +1212,8 @@ def test_display_subset(self):
12151212
)._translate()
12161213
assert ctx["body"][0][1]["display_value"] == expected
12171214
assert ctx["body"][1][1]["display_value"] == "1.1"
1218-
assert ctx["body"][0][2]["display_value"] == "0.1234"
1219-
assert ctx["body"][1][2]["display_value"] == "1.1234"
1215+
assert ctx["body"][0][2]["display_value"] == "0.123400"
1216+
assert ctx["body"][1][2]["display_value"] == raw_11
12201217

12211218
def test_display_dict(self):
12221219
df = pd.DataFrame([[0.1234, 0.1234], [1.1234, 1.1234]], columns=["a", "b"])

0 commit comments

Comments
 (0)