Skip to content

Commit d9c1bc5

Browse files
committed
Added tests for to_latex
1 parent 3b355e5 commit d9c1bc5

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

pandas/tests/formats/test_to_latex.py

+45
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,51 @@ def test_to_latex_no_header(self):
331331

332332
assert withoutindex_result == withoutindex_expected
333333

334+
def test_to_latex_specified_header(self):
335+
# GH 7124
336+
df = DataFrame({'a': [1, 2], 'b': ['b1', 'b2']})
337+
withindex_result = df.to_latex(header=['AA', 'BB'])
338+
withindex_expected = r"""\begin{tabular}{lrl}
339+
\toprule
340+
{} & AA & BB \\
341+
\midrule
342+
0 & 1 & b1 \\
343+
1 & 2 & b2 \\
344+
\bottomrule
345+
\end{tabular}
346+
"""
347+
348+
assert withindex_result == withindex_expected
349+
350+
withoutindex_result = df.to_latex(header=['AA', 'BB'], index=False)
351+
withoutindex_expected = r"""\begin{tabular}{rl}
352+
\toprule
353+
AA & BB \\
354+
\midrule
355+
1 & b1 \\
356+
2 & b2 \\
357+
\bottomrule
358+
\end{tabular}
359+
"""
360+
361+
assert withoutindex_result == withoutindex_expected
362+
363+
withoutescape_result = df.to_latex(header=['$A$', '$B$'], escape=False)
364+
withoutescape_expected = r"""\begin{tabular}{lrl}
365+
\toprule
366+
{} & $A$ & $B$ \\
367+
\midrule
368+
0 & 1 & b1 \\
369+
1 & 2 & b2 \\
370+
\bottomrule
371+
\end{tabular}
372+
"""
373+
374+
assert withoutescape_result == withoutescape_expected
375+
376+
with tm.assertRaises(ValueError):
377+
df.to_latex(header=['A'])
378+
334379
def test_to_latex_decimal(self, frame):
335380
# GH 12031
336381
frame.to_latex()

0 commit comments

Comments
 (0)