Skip to content

Commit bdc0cfd

Browse files
committed
nbsp for strings
1 parent 139def2 commit bdc0cfd

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

doc/source/whatsnew/v3.0.0.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,7 @@ I/O
627627
- Bug in :meth:`DataFrame.to_stata` when writing :class:`DataFrame` and ``byteorder=`big```. (:issue:`58969`)
628628
- Bug in :meth:`DataFrame.to_string` that raised ``StopIteration`` with nested DataFrames. (:issue:`16098`)
629629
- Bug in :meth:`HDFStore.get` was failing to save data of dtype datetime64[s] correctly (:issue:`59004`)
630+
- Bug in :meth:`HTMLFormatter._write_cell_` which ignored the spacing between strings. (:issue:`59876`)
630631
- Bug in :meth:`read_csv` causing segmentation fault when ``encoding_errors`` is not a string. (:issue:`59059`)
631632
- Bug in :meth:`read_csv` raising ``TypeError`` when ``index_col`` is specified and ``na_values`` is a dict containing the key ``None``. (:issue:`57547`)
632633
- Bug in :meth:`read_csv` raising ``TypeError`` when ``nrows`` and ``iterator`` are specified without specifying a ``chunksize``. (:issue:`59079`)

pandas/io/formats/html.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,8 @@ def _write_cell(
195195
esc = {}
196196

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

199201
if self.render_links and is_url(rs):
200202
rs_unescaped = pprint_thing(s, escape_chars={}).strip()

pandas/tests/io/formats/test_format.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -375,12 +375,29 @@ def test_repr_min_rows(self):
375375
(None, "{:.3f}", "None"),
376376
("", "{:.2f}", ""),
377377
(112345.6789, "{:6.3f}", "112345.679"),
378+
("foo foo", None, "foo      foo"),
379+
(" foo", None, "foo"),
380+
(
381+
"foo foo foo",
382+
None,
383+
"foo foo       foo",
384+
), # odd no.of spaces
385+
(
386+
"foo foo foo",
387+
None,
388+
"foo foo    foo",
389+
), # even no.of spaces
378390
],
379-
)
391+
) # test float formatting and nbsp in strings
380392
def test_repr_float_formatting_html_output(
381393
self, data, format_option, expected_values
382394
):
383-
with option_context("display.float_format", format_option.format):
395+
if format_option is not None:
396+
with option_context("display.float_format", format_option.format):
397+
df = DataFrame({"A": [data]})
398+
html_output = df._repr_html_()
399+
assert expected_values in html_output
400+
else:
384401
df = DataFrame({"A": [data]})
385402
html_output = df._repr_html_()
386403
assert expected_values in html_output

0 commit comments

Comments
 (0)