@@ -782,24 +782,14 @@ def test_to_latex_escape_false(self, df_with_symbols):
782
782
assert result == expected
783
783
784
784
def test_to_latex_escape_default (self , df_with_symbols ):
785
- result = df_with_symbols .to_latex () # default: escape=True
786
- expected = _dedent (
787
- r"""
788
- \begin{tabular}{lll}
789
- \toprule
790
- & co\$e\textasciicircum x\$ & co\textasciicircum l1 \\
791
- \midrule
792
- a & a & a \\
793
- b & b & b \\
794
- \bottomrule
795
- \end{tabular}
796
- """
797
- )
798
- assert result == expected
785
+ # gh50871: in v2.0 escape is False by default (styler.format.escape=None)
786
+ default = df_with_symbols .to_latex ()
787
+ specified_true = df_with_symbols .to_latex (escape = True )
788
+ assert default != specified_true
799
789
800
790
def test_to_latex_special_escape (self ):
801
791
df = DataFrame ([r"a\b\c" , r"^a^b^c" , r"~a~b~c" ])
802
- result = df .to_latex ()
792
+ result = df .to_latex (escape = True )
803
793
expected = _dedent (
804
794
r"""
805
795
\begin{tabular}{ll}
@@ -818,7 +808,7 @@ def test_to_latex_special_escape(self):
818
808
def test_to_latex_escape_special_chars (self ):
819
809
special_characters = ["&" , "%" , "$" , "#" , "_" , "{" , "}" , "~" , "^" , "\\ " ]
820
810
df = DataFrame (data = special_characters )
821
- result = df .to_latex ()
811
+ result = df .to_latex (escape = True )
822
812
expected = _dedent (
823
813
r"""
824
814
\begin{tabular}{ll}
@@ -1039,7 +1029,7 @@ def test_to_latex_multindex_header(self):
1039
1029
# GH 16718
1040
1030
df = DataFrame ({"a" : [0 ], "b" : [1 ], "c" : [2 ], "d" : [3 ]})
1041
1031
df = df .set_index (["a" , "b" ])
1042
- observed = df .to_latex (header = ["r1" , "r2" ])
1032
+ observed = df .to_latex (header = ["r1" , "r2" ], multirow = False )
1043
1033
expected = _dedent (
1044
1034
r"""
1045
1035
\begin{tabular}{llrr}
@@ -1093,7 +1083,7 @@ def test_to_latex_multiindex_column_tabular(self):
1093
1083
1094
1084
def test_to_latex_multiindex_small_tabular (self ):
1095
1085
df = DataFrame ({("x" , "y" ): ["a" ]}).T
1096
- result = df .to_latex ()
1086
+ result = df .to_latex (multirow = False )
1097
1087
expected = _dedent (
1098
1088
r"""
1099
1089
\begin{tabular}{lll}
@@ -1108,7 +1098,7 @@ def test_to_latex_multiindex_small_tabular(self):
1108
1098
assert result == expected
1109
1099
1110
1100
def test_to_latex_multiindex_tabular (self , multiindex_frame ):
1111
- result = multiindex_frame .to_latex ()
1101
+ result = multiindex_frame .to_latex (multirow = False )
1112
1102
expected = _dedent (
1113
1103
r"""
1114
1104
\begin{tabular}{llrrrr}
@@ -1130,12 +1120,12 @@ def test_to_latex_multicolumn_tabular(self, multiindex_frame):
1130
1120
# GH 14184
1131
1121
df = multiindex_frame .T
1132
1122
df .columns .names = ["a" , "b" ]
1133
- result = df .to_latex ()
1123
+ result = df .to_latex (multirow = False )
1134
1124
expected = _dedent (
1135
1125
r"""
1136
1126
\begin{tabular}{lrrrrr}
1137
1127
\toprule
1138
- a & \multicolumn{2}{l }{c1} & \multicolumn{2}{l }{c2} & c3 \\
1128
+ a & \multicolumn{2}{r }{c1} & \multicolumn{2}{r }{c2} & c3 \\
1139
1129
b & 0 & 1 & 0 & 1 & 0 \\
1140
1130
\midrule
1141
1131
0 & 0 & 4 & 0 & 4 & 0 \\
@@ -1151,7 +1141,7 @@ def test_to_latex_multicolumn_tabular(self, multiindex_frame):
1151
1141
def test_to_latex_index_has_name_tabular (self ):
1152
1142
# GH 10660
1153
1143
df = DataFrame ({"a" : [0 , 0 , 1 , 1 ], "b" : list ("abab" ), "c" : [1 , 2 , 3 , 4 ]})
1154
- result = df .set_index (["a" , "b" ]).to_latex ()
1144
+ result = df .set_index (["a" , "b" ]).to_latex (multirow = False )
1155
1145
expected = _dedent (
1156
1146
r"""
1157
1147
\begin{tabular}{llr}
@@ -1172,12 +1162,16 @@ def test_to_latex_index_has_name_tabular(self):
1172
1162
def test_to_latex_groupby_tabular (self ):
1173
1163
# GH 10660
1174
1164
df = DataFrame ({"a" : [0 , 0 , 1 , 1 ], "b" : list ("abab" ), "c" : [1 , 2 , 3 , 4 ]})
1175
- result = df .groupby ("a" ).describe ().to_latex (float_format = "{:.1f}" .format )
1165
+ result = (
1166
+ df .groupby ("a" )
1167
+ .describe ()
1168
+ .to_latex (float_format = "{:.1f}" .format , escape = True )
1169
+ )
1176
1170
expected = _dedent (
1177
1171
r"""
1178
1172
\begin{tabular}{lrrrrrrrr}
1179
1173
\toprule
1180
- & \multicolumn{8}{l }{c} \\
1174
+ & \multicolumn{8}{r }{c} \\
1181
1175
& count & mean & std & min & 25\% & 50\% & 75\% & max \\
1182
1176
a & & & & & & & & \\
1183
1177
\midrule
@@ -1200,7 +1194,7 @@ def test_to_latex_multiindex_dupe_level(self):
1200
1194
df = DataFrame (
1201
1195
index = pd .MultiIndex .from_tuples ([("A" , "c" ), ("B" , "c" )]), columns = ["col" ]
1202
1196
)
1203
- result = df .to_latex ()
1197
+ result = df .to_latex (multirow = False )
1204
1198
expected = _dedent (
1205
1199
r"""
1206
1200
\begin{tabular}{lll}
@@ -1221,7 +1215,7 @@ def test_to_latex_multicolumn_default(self, multicolumn_frame):
1221
1215
r"""
1222
1216
\begin{tabular}{lrrrrr}
1223
1217
\toprule
1224
- & \multicolumn{2}{l }{c1} & \multicolumn{2}{l }{c2} & c3 \\
1218
+ & \multicolumn{2}{r }{c1} & \multicolumn{2}{r }{c2} & c3 \\
1225
1219
& 0 & 1 & 0 & 1 & 0 \\
1226
1220
\midrule
1227
1221
0 & 0 & 5 & 0 & 5 & 0 \\
@@ -1236,7 +1230,7 @@ def test_to_latex_multicolumn_default(self, multicolumn_frame):
1236
1230
assert result == expected
1237
1231
1238
1232
def test_to_latex_multicolumn_false (self , multicolumn_frame ):
1239
- result = multicolumn_frame .to_latex (multicolumn = False )
1233
+ result = multicolumn_frame .to_latex (multicolumn = False , multicolumn_format = "l" )
1240
1234
expected = _dedent (
1241
1235
r"""
1242
1236
\begin{tabular}{lrrrrr}
@@ -1323,11 +1317,11 @@ def test_to_latex_multiindex_names(self, name0, name1, axes):
1323
1317
else ""
1324
1318
)
1325
1319
col_names = [n if (bool (n ) and 1 in axes ) else "" for n in names ]
1326
- observed = df .to_latex ()
1320
+ observed = df .to_latex (multirow = False )
1327
1321
# pylint: disable-next=consider-using-f-string
1328
1322
expected = r"""\begin{tabular}{llrrrr}
1329
1323
\toprule
1330
- & %s & \multicolumn{2}{l }{1} & \multicolumn{2}{l }{2} \\
1324
+ & %s & \multicolumn{2}{r }{1} & \multicolumn{2}{r }{2} \\
1331
1325
& %s & 3 & 4 & 3 & 4 \\
1332
1326
%s\midrule
1333
1327
1 & 3 & -1 & -1 & -1 & -1 \\
@@ -1347,7 +1341,7 @@ def test_to_latex_multiindex_nans(self, one_row):
1347
1341
df = DataFrame ({"a" : [None , 1 ], "b" : [2 , 3 ], "c" : [4 , 5 ]})
1348
1342
if one_row :
1349
1343
df = df .iloc [[0 ]]
1350
- observed = df .set_index (["a" , "b" ]).to_latex ()
1344
+ observed = df .set_index (["a" , "b" ]).to_latex (multirow = False )
1351
1345
expected = _dedent (
1352
1346
r"""
1353
1347
\begin{tabular}{llr}
@@ -1369,7 +1363,7 @@ def test_to_latex_multiindex_nans(self, one_row):
1369
1363
def test_to_latex_non_string_index (self ):
1370
1364
# GH 19981
1371
1365
df = DataFrame ([[1 , 2 , 3 ]] * 2 ).set_index ([0 , 1 ])
1372
- result = df .to_latex ()
1366
+ result = df .to_latex (multirow = False )
1373
1367
expected = _dedent (
1374
1368
r"""
1375
1369
\begin{tabular}{llr}
0 commit comments