Skip to content

Commit 06b55dc

Browse files
committed
test script for float format
1 parent e1cf343 commit 06b55dc

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

pandas/io/formats/html.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,11 @@ def _write_cell(
190190

191191
if self.escape:
192192
# escape & first to prevent double escaping of &
193+
<<<<<<< Updated upstream
193194
esc = {"&": r"&amp;", "<": r"&lt;", ">": r"&gt;"," ":"&nbsp;"}
195+
=======
196+
esc = {"&": r"&amp;", "<": r"&lt;", ">": r"&gt;"}
197+
>>>>>>> Stashed changes
194198
else:
195199
esc = {}
196200

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import pytest
2+
3+
import pandas as pd
4+
5+
6+
class Testfloatformat:
7+
@pytest.mark.parametrize(
8+
"data, format_option, expected_values",
9+
[
10+
({"A": [12345.6789]}, "{:12.3f}", "12345.679"),
11+
({"A": [None]}, "{:.3f}", "None"),
12+
({"A": [""]}, "{:.2f}", ""),
13+
({"A": [112345.6789]}, "{:6.3f}", "112345.679"),
14+
],
15+
) # test cases
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+
# create dataframe
22+
df = pd.DataFrame(data)
23+
24+
# capture html output
25+
html_output = df._repr_html_()
26+
27+
# check
28+
assert expected_values in html_output
29+
30+
# reset option
31+
if format_option is not None:
32+
pd.reset_option("display.float_format")

0 commit comments

Comments
 (0)