Skip to content

Commit

Permalink
fix linting
Browse files Browse the repository at this point in the history
  • Loading branch information
saldanhad committed Oct 1, 2024
1 parent ebfd576 commit 1061442
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 27 deletions.
4 changes: 2 additions & 2 deletions doc/source/whatsnew/v3.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,9 @@ MultiIndex
I/O
^^^
- Bug in :class:`DataFrame` and :class:`Series` ``repr`` of :py:class:`collections.abc.Mapping`` elements. (:issue:`57915`)
- Bug in :class:`HTMLFormatter._write_cell` to escape regular spaces as `` `` ensuring multiple spaces are preserved in the HTML output. (:issue:`59876`)
- 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`)
- 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`)
- Bug in :meth:`DataFrame.from_records` where ``columns`` parameter with numpy structured array was not reordering and filtering out the columns (:issue:`59717`)
- Bug in :meth:`DataFrame.to_dict` raises unnecessary ``UserWarning`` when columns are not unique and ``orient='tight'``. (:issue:`58281`)
- Bug in :meth:`DataFrame.to_excel` when writing empty :class:`DataFrame` with :class:`MultiIndex` on both axes (:issue:`57696`)
Expand All @@ -636,8 +638,6 @@ I/O
- Bug in :meth:`read_stata` raising ``KeyError`` when input file is stored in big-endian format and contains strL data. (:issue:`58638`)
- Bug in :meth:`read_stata` where extreme value integers were incorrectly interpreted as missing for format versions 111 and prior (:issue:`58130`)
- Bug in :meth:`read_stata` where the missing code for double was not recognised for format versions 105 and prior (:issue:`58149`)
- 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`)
- Bug in :class:`HTMLFormatter._write_cell` to escape regular spaces as ` `, ensuring multiple spaces are preserved in the HTML output (:issue:`59876`).

Period
^^^^^^
Expand Down
2 changes: 1 addition & 1 deletion pandas/io/formats/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ def _write_cell(

if self.escape:
# escape & first to prevent double escaping of &
esc = {"&": r"&amp;", "<": r"&lt;", ">": r"&gt;"," ":"&nbsp;"}
esc = {"&": r"&amp;", "<": r"&lt;", ">": r"&gt;", " ": "&nbsp;"}
else:
esc = {}

Expand Down
51 changes: 27 additions & 24 deletions pandas/tests/io/test_info_repr_html.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,35 @@
import pytest

import pandas as pd


class Testfloatformat:
@pytest.mark.parametrize("data, format_option, expected_values", [
({"A": [12345.6789]}, "{:12.3f}", "&nbsp;&nbsp;&nbsp;12345.679"),
({"A": [None]}, "{:.3f}", "&nbsp;None"),
({"A": [""]}, "{:.2f}", "&nbsp;"),
({"A": [112345.6789]}, "{:6.3f}", "112345.679"),
({"A": ["foo foo"]}, None, "&nbsp;foo&nbsp;&nbsp;&nbsp;&nbsp;foo"),
({"A": [None]}, None, "&nbsp;None"),
({"A": ["foo foo foo"]}, None, "&nbsp;foo&nbsp;foo&nbsp;foo"),
]) #test cases
@pytest.mark.parametrize(
"data, format_option, expected_values",
[
({"A": [12345.6789]}, "{:12.3f}", "&nbsp;&nbsp;&nbsp;12345.679"),
({"A": [None]}, "{:.3f}", "&nbsp;None"),
({"A": [""]}, "{:.2f}", "&nbsp;"),
({"A": [112345.6789]}, "{:6.3f}", "112345.679"),
({"A": ["foo foo"]}, None, "&nbsp;foo&nbsp;&nbsp;&nbsp;&nbsp;foo"),
({"A": [None]}, None, "&nbsp;None"),
({"A": ["foo foo foo"]}, None, "&nbsp;foo&nbsp;foo&nbsp;foo"),
],
) # test cases
def test_float_formatting_html_output(self, data, format_option, expected_values):
# set float format, avoid for string checks
if format_option is not None:
pd.set_option("display.float_format", format_option.format)

# create dataframe
df = pd.DataFrame(data)

def test_float_formatting_html_output(self,data,format_option, expected_values):
# set float format, avoid for string checks
if format_option is not None:
pd.set_option("display.float_format", format_option.format)

# crate dataframe
df = pd.DataFrame(data)

# capture html output
html_output = df._repr_html_()
# capture html output
html_output = df._repr_html_()

# check
assert expected_values in html_output
# check
assert expected_values in html_output

# reset option
if format_option is not None:
pd.reset_option("display.float_format")
# reset option
if format_option is not None:
pd.reset_option("display.float_format")

0 comments on commit 1061442

Please sign in to comment.