Skip to content

Commit a1c6275

Browse files
committed
test
1 parent 6a79ec3 commit a1c6275

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

pandas/tests/io/formats/test_to_latex.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -824,6 +824,33 @@ def test_to_latex_escape_special_chars(self):
824824
)
825825
assert result == expected
826826

827+
def test_to_latex_escape_special_chars_in_index_names(self):
828+
special_characters = ["&", "%", "$", "#", "_", "{", "}", "~", "^", "\\"]
829+
df = DataFrame([special_characters, special_characters]).T.set_index(0)
830+
result = df.to_latex(escape=True)
831+
expected = _dedent(
832+
r"""
833+
\begin{tabular}{ll}
834+
\toprule
835+
& 1 \\
836+
0 & \\
837+
\midrule
838+
\& & \& \\
839+
\% & \% \\
840+
\$ & \$ \\
841+
\# & \# \\
842+
\_ & \_ \\
843+
\{ & \{ \\
844+
\} & \} \\
845+
\textasciitilde & \textasciitilde \\
846+
\textasciicircum & \textasciicircum \\
847+
\textbackslash & \textbackslash \\
848+
\bottomrule
849+
\end{tabular}
850+
"""
851+
)
852+
assert result == expected
853+
827854
def test_to_latex_specified_header_special_chars_without_escape(self):
828855
# GH 7124
829856
df = DataFrame({"a": [1, 2], "b": ["b1", "b2"]})

0 commit comments

Comments
 (0)