Skip to content

Commit 1061442

Browse files
committed
fix linting
1 parent ebfd576 commit 1061442

File tree

3 files changed

+30
-27
lines changed

3 files changed

+30
-27
lines changed

doc/source/whatsnew/v3.0.0.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,9 @@ MultiIndex
619619
I/O
620620
^^^
621621
- Bug in :class:`DataFrame` and :class:`Series` ``repr`` of :py:class:`collections.abc.Mapping`` elements. (:issue:`57915`)
622+
- Bug in :class:`HTMLFormatter._write_cell` to escape regular spaces as `` `` ensuring multiple spaces are preserved in the HTML output. (:issue:`59876`)
622623
- Bug in :meth:`.DataFrame.to_json` when ``"index"`` was a value in the :attr:`DataFrame.column` and :attr:`Index.name` was ``None``. Now, this will fail with a ``ValueError`` (:issue:`58925`)
624+
- Bug in :meth:`DataFrame._repr_html_` pass :func: ``get_option("display.float_format")`` to :class:`DataFrameFormatter`, such that HTML output respects the configured float formatting. (:issue:`59876`)
623625
- Bug in :meth:`DataFrame.from_records` where ``columns`` parameter with numpy structured array was not reordering and filtering out the columns (:issue:`59717`)
624626
- Bug in :meth:`DataFrame.to_dict` raises unnecessary ``UserWarning`` when columns are not unique and ``orient='tight'``. (:issue:`58281`)
625627
- Bug in :meth:`DataFrame.to_excel` when writing empty :class:`DataFrame` with :class:`MultiIndex` on both axes (:issue:`57696`)
@@ -636,8 +638,6 @@ I/O
636638
- Bug in :meth:`read_stata` raising ``KeyError`` when input file is stored in big-endian format and contains strL data. (:issue:`58638`)
637639
- Bug in :meth:`read_stata` where extreme value integers were incorrectly interpreted as missing for format versions 111 and prior (:issue:`58130`)
638640
- Bug in :meth:`read_stata` where the missing code for double was not recognised for format versions 105 and prior (:issue:`58149`)
639-
- Bug in :meth:`DataFrame._repr_html_` pass :func:`get_option("display.float_format")` to :class:`DataFrameFormatter`, such that HTML output respects the configured float formatting (:issue:`59876`)
640-
- Bug in :class:`HTMLFormatter._write_cell` to escape regular spaces as ` `, ensuring multiple spaces are preserved in the HTML output (:issue:`59876`).
641641

642642
Period
643643
^^^^^^

pandas/io/formats/html.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ def _write_cell(
190190

191191
if self.escape:
192192
# escape & first to prevent double escaping of &
193-
esc = {"&": r"&amp;", "<": r"&lt;", ">": r"&gt;"," ":"&nbsp;"}
193+
esc = {"&": r"&amp;", "<": r"&lt;", ">": r"&gt;", " ": "&nbsp;"}
194194
else:
195195
esc = {}
196196

+27-24
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,35 @@
11
import pytest
2+
23
import pandas as pd
34

45

56
class Testfloatformat:
6-
@pytest.mark.parametrize("data, format_option, expected_values", [
7-
({"A": [12345.6789]}, "{:12.3f}", "&nbsp;&nbsp;&nbsp;12345.679"),
8-
({"A": [None]}, "{:.3f}", "&nbsp;None"),
9-
({"A": [""]}, "{:.2f}", "&nbsp;"),
10-
({"A": [112345.6789]}, "{:6.3f}", "112345.679"),
11-
({"A": ["foo foo"]}, None, "&nbsp;foo&nbsp;&nbsp;&nbsp;&nbsp;foo"),
12-
({"A": [None]}, None, "&nbsp;None"),
13-
({"A": ["foo foo foo"]}, None, "&nbsp;foo&nbsp;foo&nbsp;foo"),
14-
]) #test cases
7+
@pytest.mark.parametrize(
8+
"data, format_option, expected_values",
9+
[
10+
({"A": [12345.6789]}, "{:12.3f}", "&nbsp;&nbsp;&nbsp;12345.679"),
11+
({"A": [None]}, "{:.3f}", "&nbsp;None"),
12+
({"A": [""]}, "{:.2f}", "&nbsp;"),
13+
({"A": [112345.6789]}, "{:6.3f}", "112345.679"),
14+
({"A": ["foo foo"]}, None, "&nbsp;foo&nbsp;&nbsp;&nbsp;&nbsp;foo"),
15+
({"A": [None]}, None, "&nbsp;None"),
16+
({"A": ["foo foo foo"]}, None, "&nbsp;foo&nbsp;foo&nbsp;foo"),
17+
],
18+
) # test cases
19+
def test_float_formatting_html_output(self, data, format_option, expected_values):
20+
# set float format, avoid for string checks
21+
if format_option is not None:
22+
pd.set_option("display.float_format", format_option.format)
23+
24+
# create dataframe
25+
df = pd.DataFrame(data)
1526

16-
def test_float_formatting_html_output(self,data,format_option, expected_values):
17-
# set float format, avoid for string checks
18-
if format_option is not None:
19-
pd.set_option("display.float_format", format_option.format)
20-
21-
# crate dataframe
22-
df = pd.DataFrame(data)
23-
24-
# capture html output
25-
html_output = df._repr_html_()
27+
# capture html output
28+
html_output = df._repr_html_()
2629

27-
# check
28-
assert expected_values in html_output
30+
# check
31+
assert expected_values in html_output
2932

30-
# reset option
31-
if format_option is not None:
32-
pd.reset_option("display.float_format")
33+
# reset option
34+
if format_option is not None:
35+
pd.reset_option("display.float_format")

0 commit comments

Comments
 (0)