From 7b3c02ac14a81ad24c39d257e38d90f120000bd6 Mon Sep 17 00:00:00 2001 From: Matthew Zeitlin Date: Fri, 16 Apr 2021 10:31:30 -0400 Subject: [PATCH 1/2] TST: use expected_html structure --- .../data/html/gh13828_expected_output.html | 21 +++++++++ .../data/html/gh40024_expected_output.html | 18 +++++++ pandas/tests/io/formats/test_to_html.py | 47 ++----------------- 3 files changed, 44 insertions(+), 42 deletions(-) create mode 100644 pandas/tests/io/formats/data/html/gh13828_expected_output.html create mode 100644 pandas/tests/io/formats/data/html/gh40024_expected_output.html diff --git a/pandas/tests/io/formats/data/html/gh13828_expected_output.html b/pandas/tests/io/formats/data/html/gh13828_expected_output.html new file mode 100644 index 0000000000000..3c93a1419865f --- /dev/null +++ b/pandas/tests/io/formats/data/html/gh13828_expected_output.html @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + +
GroupData
0A1.22
1A{na_rep}
\ No newline at end of file diff --git a/pandas/tests/io/formats/data/html/gh40024_expected_output.html b/pandas/tests/io/formats/data/html/gh40024_expected_output.html new file mode 100644 index 0000000000000..0877c29525d2c --- /dev/null +++ b/pandas/tests/io/formats/data/html/gh40024_expected_output.html @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + +
x
01,000
1test
diff --git a/pandas/tests/io/formats/test_to_html.py b/pandas/tests/io/formats/test_to_html.py index ec2f109900f3a..a61e77bec9828 100644 --- a/pandas/tests/io/formats/test_to_html.py +++ b/pandas/tests/io/formats/test_to_html.py @@ -851,7 +851,7 @@ def test_to_html_multilevel(multiindex_year_month_day_dataframe_random_data): @pytest.mark.parametrize("na_rep", ["NaN", "Ted"]) -def test_to_html_na_rep_and_float_format(na_rep): +def test_to_html_na_rep_and_float_format(na_rep, datapath): # https://github.com/pandas-dev/pandas/issues/13828 df = DataFrame( [ @@ -861,51 +861,14 @@ def test_to_html_na_rep_and_float_format(na_rep): columns=["Group", "Data"], ) result = df.to_html(na_rep=na_rep, float_format="{:.2f}".format) - expected = f""" - - - - - - - - - - - - - - - - - - - -
GroupData
0A1.22
1A{na_rep}
""" + expected = expected_html(datapath, "gh13828_expected_output") + expected = expected.format(na_rep=na_rep) assert result == expected -def test_to_html_float_format_object_col(): +def test_to_html_float_format_object_col(datapath): # GH#40024 df = DataFrame(data={"x": [1000.0, "test"]}) result = df.to_html(float_format=lambda x: f"{x:,.0f}") - expected = """ - - - - - - - - - - - - - - - - -
x
01,000
1test
""" - + expected = expected_html(datapath, "gh40024_expected_output") assert result == expected From baf7e23e368b1fc3b836ada42361ed7c4c129e5c Mon Sep 17 00:00:00 2001 From: Matthew Zeitlin Date: Fri, 16 Apr 2021 10:32:59 -0400 Subject: [PATCH 2/2] Add newline --- pandas/tests/io/formats/data/html/gh13828_expected_output.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/io/formats/data/html/gh13828_expected_output.html b/pandas/tests/io/formats/data/html/gh13828_expected_output.html index 3c93a1419865f..690d638c31d5b 100644 --- a/pandas/tests/io/formats/data/html/gh13828_expected_output.html +++ b/pandas/tests/io/formats/data/html/gh13828_expected_output.html @@ -18,4 +18,4 @@ {na_rep} - \ No newline at end of file +