Skip to content

Commit fc5f292

Browse files
committed
Revert "to_html formatter not called for float values in a mixed-type column (#25983)"
This reverts commit 77713d5.
1 parent 0b03130 commit fc5f292

File tree

4 files changed

+6
-49
lines changed

4 files changed

+6
-49
lines changed

doc/source/whatsnew/v0.25.0.rst

-1
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,6 @@ I/O
347347
^^^
348348

349349
- Bug in :func:`DataFrame.to_html()` where values were truncated using display options instead of outputting the full content (:issue:`17004`)
350-
- Bug in :meth:`DataFrame.to_html` that would ignore ``formatters`` argument for float values in a column with ``dtype=object`` (:issue:`13021`)
351350
- Fixed bug in missing text when using :meth:`to_clipboard` if copying utf-16 characters in Python 3 on Windows (:issue:`25040`)
352351
- Bug in :func:`read_json` for ``orient='table'`` when it tries to infer dtypes by default, which is not applicable as dtypes are already defined in the JSON schema (:issue:`21345`)
353352
- Bug in :func:`read_json` for ``orient='table'`` and float index, as it infers index dtype by default, which is not applicable because index dtype is already defined in the JSON schema (:issue:`25433`)

pandas/io/formats/format.py

+6-11
Original file line numberDiff line numberDiff line change
@@ -981,24 +981,19 @@ def _format(x):
981981
if leading_space is None:
982982
leading_space = is_float_type.any()
983983

984-
if leading_space is False:
985-
# False specifically, so that the default is
986-
# to include a space if we get here.
987-
tpl = '{v}'
988-
else:
989-
tpl = ' {v}'
990-
991-
# shortcut
992-
if self.formatter is not None:
993-
return [tpl.format(v=self.formatter(x)) for x in self.values]
994-
995984
fmt_values = []
996985
for i, v in enumerate(vals):
997986
if not is_float_type[i] and leading_space:
998987
fmt_values.append(' {v}'.format(v=_format(v)))
999988
elif is_float_type[i]:
1000989
fmt_values.append(float_format(v))
1001990
else:
991+
if leading_space is False:
992+
# False specifically, so that the default is
993+
# to include a space if we get here.
994+
tpl = '{v}'
995+
else:
996+
tpl = ' {v}'
1002997
fmt_values.append(tpl.format(v=_format(v)))
1003998

1004999
return fmt_values

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

-26
This file was deleted.

pandas/tests/io/formats/test_to_html.py

-11
Original file line numberDiff line numberDiff line change
@@ -635,17 +635,6 @@ def test_to_html_invalid_classes_type(classes):
635635
df.to_html(classes=classes)
636636

637637

638-
def test_to_html_formatters_object_type(datapath):
639-
# GH 13021
640-
def f(x):
641-
return x if isinstance(x, str) else '${:,.0f}'.format(x)
642-
643-
df = pd.DataFrame([['a'], [0], [10.4], [3]], columns=['x'])
644-
result = df.to_html(formatters=dict(x=f))
645-
expected = expected_html(datapath, 'gh13021_expected_output')
646-
assert result == expected
647-
648-
649638
def test_to_html_round_column_headers():
650639
# GH 17280
651640
df = DataFrame([1], columns=[0.55555])

0 commit comments

Comments
 (0)