Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
a82f4f5
update escaping for html
attack68 Mar 14, 2021
51bda2c
update escaping for html
attack68 Mar 14, 2021
a323f93
tests for format_escape
attack68 Mar 14, 2021
64a54d3
Merge remote-tracking branch 'upstream/master' into escape_html_forma…
attack68 Mar 15, 2021
e01eeb5
check and docs fix
attack68 Mar 15, 2021
2348165
versionadded and whatsnew
attack68 Mar 15, 2021
27f39eb
only use escape on str
attack68 Mar 15, 2021
c1b29c3
refactor
attack68 Mar 15, 2021
0008af2
add decimal and thousands options to format function
attack68 Mar 21, 2021
02ba51e
add decimal and thousands options to format function
attack68 Mar 21, 2021
b07de09
docs
attack68 Mar 21, 2021
8ea4e0a
Merge remote-tracking branch 'upstream/master' into format_decimal_th…
attack68 Mar 23, 2021
2202a7c
tests with parameters
attack68 Mar 23, 2021
45dd2f1
var names
attack68 Mar 23, 2021
fb5dc2f
Merge remote-tracking branch 'upstream/master' into format_decimal_th…
attack68 Mar 27, 2021
863dd6c
move format tests
attack68 Mar 27, 2021
131b928
Merge remote-tracking branch 'upstream/master' into format_decimal_th…
attack68 Mar 31, 2021
b82e0b1
Merge remote-tracking branch 'upstream/master' into format_decimal_th…
attack68 Apr 13, 2021
a0b7fd6
restructure formatter wrappers
attack68 Apr 13, 2021
c35b1ee
Merge remote-tracking branch 'upstream/master' into format_decimal_th…
attack68 Apr 14, 2021
70f1e2b
Merge remote-tracking branch 'upstream/master' into format_decimal_th…
attack68 Apr 15, 2021
d834f8f
Merge remote-tracking branch 'upstream/master' into format_decimal_th…
attack68 Apr 18, 2021
19d862b
Merge remote-tracking branch 'upstream/master' into format_decimal_th…
attack68 Apr 20, 2021
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
only use escape on str
  • Loading branch information
attack68 committed Mar 15, 2021
commit 27f39ebdb72ed020094d2e4113319faba64fb122
8 changes: 6 additions & 2 deletions pandas/io/formats/style.py
Original file line number Diff line number Diff line change
Expand Up @@ -2205,11 +2205,15 @@ def _maybe_wrap_formatter(
else:
raise TypeError(f"'formatter' expected str or callable, got {type(formatter)}")

def _str_escape(x):
"""only use escape_func on str, else return input"""
return escape_func(x) if isinstance(x, str) else x

if na_rep is None:
return (lambda x: formatter_func(escape_func(x))) if escape else formatter_func
return (lambda x: formatter_func(_str_escape(x))) if escape else formatter_func
else:
if escape:
return lambda x: na_rep if pd.isna(x) else formatter_func(escape_func(x))
return lambda x: na_rep if pd.isna(x) else formatter_func(_str_escape(x))
else:
return lambda x: na_rep if pd.isna(x) else formatter_func(x)

Expand Down
10 changes: 10 additions & 0 deletions pandas/tests/io/formats/style/test_style.py
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,16 @@ def test_format_escape_na_rep(self):
assert ex in s.render()
assert expected2 in s.render()

def test_format_escape_floats(self):
# test given formatter for number format is not impacted by escape
s = self.df.style.format("{:.1f}", escape=True)
for expected in [">0.0<", ">1.0<", ">-1.2<", ">-0.6<"]:
assert expected in s.render()
# tests precision of floats is not impacted by escape
s = self.df.style.format(precision=1, escape=True)
for expected in [">0<", ">1<", ">-1.2<", ">-0.6<"]:
assert expected in s.render()

def test_nonunique_raises(self):
df = DataFrame([[1, 2]], columns=["A", "A"])
msg = "style is not supported for non-unique indices."
Expand Down