Skip to content

Commit 71a3375

Browse files
authored
TST: move and reformat latex_na_rep test (#37717)
1 parent c226fc5 commit 71a3375

File tree

1 file changed

+24
-21
lines changed

1 file changed

+24
-21
lines changed

pandas/tests/io/formats/test_to_latex.py

+24-21
Original file line numberDiff line numberDiff line change
@@ -972,6 +972,30 @@ def test_to_latex_float_format_no_fixed_width_integer(self):
972972
)
973973
assert result == expected
974974

975+
@pytest.mark.parametrize("na_rep", ["NaN", "Ted"])
976+
def test_to_latex_na_rep_and_float_format(self, na_rep):
977+
df = DataFrame(
978+
[
979+
["A", 1.2225],
980+
["A", None],
981+
],
982+
columns=["Group", "Data"],
983+
)
984+
result = df.to_latex(na_rep=na_rep, float_format="{:.2f}".format)
985+
expected = _dedent(
986+
fr"""
987+
\begin{{tabular}}{{llr}}
988+
\toprule
989+
{{}} & Group & Data \\
990+
\midrule
991+
0 & A & 1.22 \\
992+
1 & A & {na_rep} \\
993+
\bottomrule
994+
\end{{tabular}}
995+
"""
996+
)
997+
assert result == expected
998+
975999

9761000
class TestToLatexMultiindex:
9771001
@pytest.fixture
@@ -1431,24 +1455,3 @@ def test_get_strrow_multindex_multicolumn(self, row_num, expected):
14311455
)
14321456

14331457
assert row_string_converter.get_strrow(row_num=row_num) == expected
1434-
1435-
@pytest.mark.parametrize("na_rep", ["NaN", "Ted"])
1436-
def test_to_latex_na_rep_and_float_format(self, na_rep):
1437-
df = DataFrame(
1438-
[
1439-
["A", 1.2225],
1440-
["A", None],
1441-
],
1442-
columns=["Group", "Data"],
1443-
)
1444-
result = df.to_latex(na_rep=na_rep, float_format="{:.2f}".format)
1445-
expected = f"""\\begin{{tabular}}{{llr}}
1446-
\\toprule
1447-
{{}} & Group & Data \\\\
1448-
\\midrule
1449-
0 & A & 1.22 \\\\
1450-
1 & A & {na_rep} \\\\
1451-
\\bottomrule
1452-
\\end{{tabular}}
1453-
"""
1454-
assert result == expected

0 commit comments

Comments
 (0)