File tree 2 files changed +29
-0
lines changed
2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -1564,7 +1564,12 @@ def relabel_index(
1564
1564
levels_ = refactor_levels (level , obj )
1565
1565
1566
1566
def alias_ (x , value ):
1567
+ """
1568
+ Checks and returns formatted values based on specific conditions.
1569
+ """
1567
1570
if isinstance (value , str ):
1571
+ if value .startswith ("$" ) and value .endswith ("$" ):
1572
+ return value
1568
1573
return value .format (x )
1569
1574
return value
1570
1575
Original file line number Diff line number Diff line change @@ -370,6 +370,30 @@ def test_to_latex_number_of_items_in_header_missmatch_raises(
370
370
msg = f"Writing 2 cols but got { num_aliases } aliases"
371
371
with pytest .raises (ValueError , match = msg ):
372
372
df .to_latex (header = header )
373
+
374
+ def test_to_latex_with_latex_header (self ):
375
+
376
+ df = DataFrame ({"a" : [1 , 2 ]})
377
+ result = df .to_latex (header = [r"$\bar{y}$" ], index = False , column_format = "l" )
378
+ expected = r"""
379
+ \begin{tabular}{l}
380
+ \toprule
381
+ $\bar{y}$ \\
382
+ \midrule
383
+ 1 \\
384
+ 2 \\
385
+ \bottomrule
386
+ \end{tabular}
387
+ """
388
+ # Function to remove leading spaces from each line
389
+ def remove_leading_spaces (s ):
390
+ return '\n ' .join (line .lstrip () for line in s .strip ().split ('\n ' ))
391
+
392
+ # Normalize both result and expected strings
393
+ result_clean = remove_leading_spaces (result )
394
+ expected_clean = remove_leading_spaces (expected )
395
+
396
+ assert result_clean == expected_clean , f"Result:\n { repr (result )} \n Expected:\n { repr (expected )} "
373
397
374
398
def test_to_latex_decimal (self ):
375
399
# GH 12031
You can’t perform that action at this time.
0 commit comments