File tree 1 file changed +45
-0
lines changed
1 file changed +45
-0
lines changed Original file line number Diff line number Diff line change @@ -428,6 +428,51 @@ def test_to_latex_no_header(self):
428
428
429
429
assert withoutindex_result == withoutindex_expected
430
430
431
+ def test_to_latex_specified_header (self ):
432
+ # GH 7124
433
+ df = DataFrame ({'a' : [1 , 2 ], 'b' : ['b1' , 'b2' ]})
434
+ withindex_result = df .to_latex (header = ['AA' , 'BB' ])
435
+ withindex_expected = r"""\begin{tabular}{lrl}
436
+ \toprule
437
+ {} & AA & BB \\
438
+ \midrule
439
+ 0 & 1 & b1 \\
440
+ 1 & 2 & b2 \\
441
+ \bottomrule
442
+ \end{tabular}
443
+ """
444
+
445
+ assert withindex_result == withindex_expected
446
+
447
+ withoutindex_result = df .to_latex (header = ['AA' , 'BB' ], index = False )
448
+ withoutindex_expected = r"""\begin{tabular}{rl}
449
+ \toprule
450
+ AA & BB \\
451
+ \midrule
452
+ 1 & b1 \\
453
+ 2 & b2 \\
454
+ \bottomrule
455
+ \end{tabular}
456
+ """
457
+
458
+ assert withoutindex_result == withoutindex_expected
459
+
460
+ withoutescape_result = df .to_latex (header = ['$A$' , '$B$' ], escape = False )
461
+ withoutescape_expected = r"""\begin{tabular}{lrl}
462
+ \toprule
463
+ {} & $A$ & $B$ \\
464
+ \midrule
465
+ 0 & 1 & b1 \\
466
+ 1 & 2 & b2 \\
467
+ \bottomrule
468
+ \end{tabular}
469
+ """
470
+
471
+ assert withoutescape_result == withoutescape_expected
472
+
473
+ with tm .assertRaises (ValueError ):
474
+ df .to_latex (header = ['A' ])
475
+
431
476
def test_to_latex_decimal (self , frame ):
432
477
# GH 12031
433
478
frame .to_latex ()
You can’t perform that action at this time.
0 commit comments