Skip to content

BUG: fix nbsp for html formatting #59964

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pandas/io/formats/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@ def _write_cell(
esc = {}

rs = pprint_thing(s, escape_chars=esc).strip()
# replace spaces betweens strings with non-breaking spaces
rs = rs.replace(" ", "  ")

if self.render_links and is_url(rs):
rs_unescaped = pprint_thing(s, escape_chars={}).strip()
Expand Down
19 changes: 18 additions & 1 deletion pandas/tests/io/formats/test_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,12 +375,29 @@ def test_repr_min_rows(self):
(None, "{:.3f}", "None"),
("", "{:.2f}", ""),
(112345.6789, "{:6.3f}", "112345.679"),
("foo foo", None, "foo      foo"),
(" foo", None, "foo"),
(
"foo foo foo",
None,
"foo foo       foo",
), # odd no.of spaces
(
"foo foo foo",
None,
"foo foo    foo",
), # even no.of spaces
],
)
def test_repr_float_formatting_html_output(
self, data, format_option, expected_values
):
with option_context("display.float_format", format_option.format):
if format_option is not None:
with option_context("display.float_format", format_option.format):
df = DataFrame({"A": [data]})
html_output = df._repr_html_()
assert expected_values in html_output
else:
df = DataFrame({"A": [data]})
html_output = df._repr_html_()
assert expected_values in html_output
Expand Down
Loading