@@ -52,8 +52,8 @@ def test_to_latex(self, frame):
52
52
\toprule
53
53
{} & a & b \\
54
54
\midrule
55
- 0 & 1 & b1 \\
56
- 1 & 2 & b2 \\
55
+ \textbf{0} & 1 & b1 \\
56
+ \textbf{1} & 2 & b2 \\
57
57
\bottomrule
58
58
\end{tabular}
59
59
"""
@@ -83,8 +83,8 @@ def test_to_latex_format(self, frame):
83
83
\toprule
84
84
{} & a & b \\
85
85
\midrule
86
- 0 & 1 & b1 \\
87
- 1 & 2 & b2 \\
86
+ \textbf{0} & 1 & b1 \\
87
+ \textbf{1} & 2 & b2 \\
88
88
\bottomrule
89
89
\end{tabular}
90
90
"""
@@ -110,9 +110,9 @@ def test_to_latex_with_formatters(self):
110
110
\toprule
111
111
{} & datetime64 & float & int & object \\
112
112
\midrule
113
- index: 0 & 2016-01 & [ 1.0] & 0x1 & -(1, 2)- \\
114
- index: 1 & 2016-02 & [ 2.0] & 0x2 & -True- \\
115
- index: 2 & 2016-03 & [ 3.0] & 0x3 & -False- \\
113
+ \textbf{ index: 0} & 2016-01 & [ 1.0] & 0x1 & -(1, 2)- \\
114
+ \textbf{ index: 1} & 2016-02 & [ 2.0] & 0x2 & -True- \\
115
+ \textbf{ index: 2} & 2016-03 & [ 3.0] & 0x3 & -False- \\
116
116
\bottomrule
117
117
\end{tabular}
118
118
"""
@@ -126,7 +126,7 @@ def test_to_latex_multiindex(self):
126
126
{} & x \\
127
127
{} & y \\
128
128
\midrule
129
- 0 & a \\
129
+ \textbf{0} & a \\
130
130
\bottomrule
131
131
\end{tabular}
132
132
"""
@@ -138,7 +138,7 @@ def test_to_latex_multiindex(self):
138
138
\toprule
139
139
& & 0 \\
140
140
\midrule
141
- x & y & a \\
141
+ \textbf{x} & \textbf{y} & a \\
142
142
\bottomrule
143
143
\end{tabular}
144
144
"""
@@ -157,11 +157,11 @@ def test_to_latex_multiindex(self):
157
157
\toprule
158
158
& & 0 & 1 & 2 & 3 \\
159
159
\midrule
160
- c1 & 0 & 0 & 1 & 2 & 3 \\
161
- & 1 & 4 & 5 & 6 & 7 \\
162
- c2 & 0 & 0 & 1 & 2 & 3 \\
163
- & 1 & 4 & 5 & 6 & 7 \\
164
- c3 & 0 & 0 & 1 & 2 & 3 \\
160
+ \textbf{c1} & \textbf{0} & 0 & 1 & 2 & 3 \\
161
+ & \textbf{1} & 4 & 5 & 6 & 7 \\
162
+ \textbf{c2} & \textbf{0} & 0 & 1 & 2 & 3 \\
163
+ & \textbf{1} & 4 & 5 & 6 & 7 \\
164
+ \textbf{c3} & \textbf{0} & 0 & 1 & 2 & 3 \\
165
165
\bottomrule
166
166
\end{tabular}
167
167
"""
@@ -174,13 +174,13 @@ def test_to_latex_multiindex(self):
174
174
result = df .to_latex ()
175
175
expected = r"""\begin{tabular}{lrrrrr}
176
176
\toprule
177
- a & \multicolumn{2}{l}{c1} & \multicolumn{2}{l}{c2} & c3 \\
178
- b & 0 & 1 & 0 & 1 & 0 \\
177
+ \textbf{a} & \multicolumn{2}{l}{c1} & \multicolumn{2}{l}{c2} & c3 \\
178
+ \textbf{b} & 0 & 1 & 0 & 1 & 0 \\
179
179
\midrule
180
- 0 & 0 & 4 & 0 & 4 & 0 \\
181
- 1 & 1 & 5 & 1 & 5 & 1 \\
182
- 2 & 2 & 6 & 2 & 6 & 2 \\
183
- 3 & 3 & 7 & 3 & 7 & 3 \\
180
+ \textbf{0} & 0 & 4 & 0 & 4 & 0 \\
181
+ \textbf{1} & 1 & 5 & 1 & 5 & 1 \\
182
+ \textbf{2} & 2 & 6 & 2 & 6 & 2 \\
183
+ \textbf{3} & 3 & 7 & 3 & 7 & 3 \\
184
184
\bottomrule
185
185
\end{tabular}
186
186
"""
@@ -194,12 +194,12 @@ def test_to_latex_multiindex(self):
194
194
expected = r"""\begin{tabular}{llr}
195
195
\toprule
196
196
& & c \\
197
- a & b & \\
197
+ \textbf{a} & \textbf{b} & \\
198
198
\midrule
199
- 0 & a & 1 \\
200
- & b & 2 \\
201
- 1 & a & 3 \\
202
- & b & 4 \\
199
+ \textbf{0} & \textbf{a} & 1 \\
200
+ & \textbf{b} & 2 \\
201
+ \textbf{1} & \textbf{a} & 3 \\
202
+ & \textbf{b} & 4 \\
203
203
\bottomrule
204
204
\end{tabular}
205
205
"""
@@ -211,10 +211,10 @@ def test_to_latex_multiindex(self):
211
211
\toprule
212
212
{} & \multicolumn{8}{l}{c} \\
213
213
{} & count & mean & std & min & 25\% & 50\% & 75\% & max \\
214
- a & & & & & & & & \\
214
+ \textbf{a} & & & & & & & & \\
215
215
\midrule
216
- 0 & 2.0 & 1.5 & 0.707107 & 1.0 & 1.25 & 1.5 & 1.75 & 2.0 \\
217
- 1 & 2.0 & 3.5 & 0.707107 & 3.0 & 3.25 & 3.5 & 3.75 & 4.0 \\
216
+ \textbf{0} & 2.0 & 1.5 & 0.707107 & 1.0 & 1.25 & 1.5 & 1.75 & 2.0 \\
217
+ \textbf{1} & 2.0 & 3.5 & 0.707107 & 3.0 & 3.25 & 3.5 & 3.75 & 4.0 \\
218
218
\bottomrule
219
219
\end{tabular}
220
220
"""
@@ -235,11 +235,11 @@ def test_to_latex_multicolumnrow(self):
235
235
{} & \multicolumn{2}{l}{c1} & \multicolumn{2}{l}{c2} & c3 \\
236
236
{} & 0 & 1 & 0 & 1 & 0 \\
237
237
\midrule
238
- 0 & 0 & 5 & 0 & 5 & 0 \\
239
- 1 & 1 & 6 & 1 & 6 & 1 \\
240
- 2 & 2 & 7 & 2 & 7 & 2 \\
241
- 3 & 3 & 8 & 3 & 8 & 3 \\
242
- 4 & 4 & 9 & 4 & 9 & 4 \\
238
+ \textbf{0} & 0 & 5 & 0 & 5 & 0 \\
239
+ \textbf{1} & 1 & 6 & 1 & 6 & 1 \\
240
+ \textbf{2} & 2 & 7 & 2 & 7 & 2 \\
241
+ \textbf{3} & 3 & 8 & 3 & 8 & 3 \\
242
+ \textbf{4} & 4 & 9 & 4 & 9 & 4 \\
243
243
\bottomrule
244
244
\end{tabular}
245
245
"""
@@ -251,11 +251,11 @@ def test_to_latex_multicolumnrow(self):
251
251
{} & c1 & & c2 & & c3 \\
252
252
{} & 0 & 1 & 0 & 1 & 0 \\
253
253
\midrule
254
- 0 & 0 & 5 & 0 & 5 & 0 \\
255
- 1 & 1 & 6 & 1 & 6 & 1 \\
256
- 2 & 2 & 7 & 2 & 7 & 2 \\
257
- 3 & 3 & 8 & 3 & 8 & 3 \\
258
- 4 & 4 & 9 & 4 & 9 & 4 \\
254
+ \textbf{0} & 0 & 5 & 0 & 5 & 0 \\
255
+ \textbf{1} & 1 & 6 & 1 & 6 & 1 \\
256
+ \textbf{2} & 2 & 7 & 2 & 7 & 2 \\
257
+ \textbf{3} & 3 & 8 & 3 & 8 & 3 \\
258
+ \textbf{4} & 4 & 9 & 4 & 9 & 4 \\
259
259
\bottomrule
260
260
\end{tabular}
261
261
"""
@@ -266,13 +266,13 @@ def test_to_latex_multicolumnrow(self):
266
266
\toprule
267
267
& & 0 & 1 & 2 & 3 & 4 \\
268
268
\midrule
269
- \multirow{2}{*}{c1} & 0 & 0 & 1 & 2 & 3 & 4 \\
270
- & 1 & 5 & 6 & 7 & 8 & 9 \\
269
+ \multirow{2}{*}{\textbf{ c1}} & \textbf{0} & 0 & 1 & 2 & 3 & 4 \\
270
+ & \textbf{1} & 5 & 6 & 7 & 8 & 9 \\
271
271
\cline{1-7}
272
- \multirow{2}{*}{c2} & 0 & 0 & 1 & 2 & 3 & 4 \\
273
- & 1 & 5 & 6 & 7 & 8 & 9 \\
272
+ \multirow{2}{*}{\textbf{ c2}} & \textbf{0} & 0 & 1 & 2 & 3 & 4 \\
273
+ & \textbf{1} & 5 & 6 & 7 & 8 & 9 \\
274
274
\cline{1-7}
275
- c3 & 0 & 0 & 1 & 2 & 3 & 4 \\
275
+ \textbf{c3} & \textbf{0} & 0 & 1 & 2 & 3 & 4 \\
276
276
\bottomrule
277
277
\end{tabular}
278
278
"""
@@ -286,13 +286,13 @@ def test_to_latex_multicolumnrow(self):
286
286
& & \multicolumn{2}{c}{c1} & \multicolumn{2}{c}{c2} & c3 \\
287
287
& & 0 & 1 & 0 & 1 & 0 \\
288
288
\midrule
289
- \multirow{2}{*}{c1} & 0 & 0 & 1 & 2 & 3 & 4 \\
290
- & 1 & 5 & 6 & 7 & 8 & 9 \\
289
+ \multirow{2}{*}{\textbf{ c1}} & \textbf{0} & 0 & 1 & 2 & 3 & 4 \\
290
+ & \textbf{1} & 5 & 6 & 7 & 8 & 9 \\
291
291
\cline{1-7}
292
- \multirow{2}{*}{c2} & 0 & 0 & 1 & 2 & 3 & 4 \\
293
- & 1 & 5 & 6 & 7 & 8 & 9 \\
292
+ \multirow{2}{*}{\textbf{ c2}} & \textbf{0} & 0 & 1 & 2 & 3 & 4 \\
293
+ & \textbf{1} & 5 & 6 & 7 & 8 & 9 \\
294
294
\cline{1-7}
295
- c3 & 0 & 0 & 1 & 2 & 3 & 4 \\
295
+ \textbf{c3} & \textbf{0} & 0 & 1 & 2 & 3 & 4 \\
296
296
\bottomrule
297
297
\end{tabular}
298
298
"""
@@ -315,8 +315,8 @@ def test_to_latex_escape(self):
315
315
\toprule
316
316
{} & co$e^x$ & co^l1 \\
317
317
\midrule
318
- a & a & a \\
319
- b & b & b \\
318
+ \textbf{a} & a & a \\
319
+ \textbf{b} & b & b \\
320
320
\bottomrule
321
321
\end{tabular}
322
322
'''
@@ -325,8 +325,8 @@ def test_to_latex_escape(self):
325
325
\toprule
326
326
{} & co\$e\textasciicircumx\$ & co\textasciicircuml1 \\
327
327
\midrule
328
- a & a & a \\
329
- b & b & b \\
328
+ \textbf{a} & a & a \\
329
+ \textbf{b} & b & b \\
330
330
\bottomrule
331
331
\end{tabular}
332
332
'''
@@ -351,8 +351,8 @@ def test_to_latex_longtable(self, frame):
351
351
352
352
\bottomrule
353
353
\endlastfoot
354
- 0 & 1 & b1 \\
355
- 1 & 2 & b2 \\
354
+ \textbf{0} & 1 & b1 \\
355
+ \textbf{1} & 2 & b2 \\
356
356
\end{longtable}
357
357
"""
358
358
@@ -387,16 +387,16 @@ def test_to_latex_escape_special_chars(self):
387
387
\toprule
388
388
{} & 0 \\
389
389
\midrule
390
- 0 & \& \\
391
- 1 & \% \\
392
- 2 & \$ \\
393
- 3 & \# \\
394
- 4 & \_ \\
395
- 5 & \{ \\
396
- 6 & \} \\
397
- 7 & \textasciitilde \\
398
- 8 & \textasciicircum \\
399
- 9 & \textbackslash \\
390
+ \textbf{0} & \& \\
391
+ \textbf{1} & \% \\
392
+ \textbf{2} & \$ \\
393
+ \textbf{3} & \# \\
394
+ \textbf{4} & \_ \\
395
+ \textbf{5} & \{ \\
396
+ \textbf{6} & \} \\
397
+ \textbf{7} & \textasciitilde \\
398
+ \textbf{8} & \textasciicircum \\
399
+ \textbf{9} & \textbackslash \\
400
400
\bottomrule
401
401
\end{tabular}
402
402
"""
@@ -409,8 +409,8 @@ def test_to_latex_no_header(self):
409
409
withindex_result = df .to_latex (header = False )
410
410
withindex_expected = r"""\begin{tabular}{lrl}
411
411
\toprule
412
- 0 & 1 & b1 \\
413
- 1 & 2 & b2 \\
412
+ \textbf{0} & 1 & b1 \\
413
+ \textbf{1} & 2 & b2 \\
414
414
\bottomrule
415
415
\end{tabular}
416
416
"""
@@ -436,8 +436,8 @@ def test_to_latex_specified_header(self):
436
436
\toprule
437
437
{} & AA & BB \\
438
438
\midrule
439
- 0 & 1 & b1 \\
440
- 1 & 2 & b2 \\
439
+ \textbf{0} & 1 & b1 \\
440
+ \textbf{1} & 2 & b2 \\
441
441
\bottomrule
442
442
\end{tabular}
443
443
"""
@@ -462,8 +462,8 @@ def test_to_latex_specified_header(self):
462
462
\toprule
463
463
{} & $A$ & $B$ \\
464
464
\midrule
465
- 0 & 1 & b1 \\
466
- 1 & 2 & b2 \\
465
+ \textbf{0} & 1 & b1 \\
466
+ \textbf{1} & 2 & b2 \\
467
467
\bottomrule
468
468
\end{tabular}
469
469
"""
@@ -484,8 +484,8 @@ def test_to_latex_decimal(self, frame):
484
484
\toprule
485
485
{} & a & b \\
486
486
\midrule
487
- 0 & 1,0 & b1 \\
488
- 1 & 2,1 & b2 \\
487
+ \textbf{0} & 1,0 & b1 \\
488
+ \textbf{1} & 2,1 & b2 \\
489
489
\bottomrule
490
490
\end{tabular}
491
491
"""
@@ -499,10 +499,40 @@ def test_to_latex_series(self):
499
499
\toprule
500
500
{} & 0 \\
501
501
\midrule
502
- 0 & a \\
503
- 1 & b \\
504
- 2 & c \\
502
+ \textbf{0} & a \\
503
+ \textbf{1} & b \\
504
+ \textbf{2} & c \\
505
505
\bottomrule
506
506
\end{tabular}
507
507
"""
508
508
assert withindex_result == withindex_expected
509
+
510
+ def test_to_latex_bold_rows (self ):
511
+ # GH 16707
512
+ df = DataFrame ({'a' : [1 , 2 ], 'b' : ['b1' , 'b2' ]})
513
+ observed = df .to_latex (bold_rows = True )
514
+ expected = r"""\begin{tabular}{lrl}
515
+ \toprule
516
+ \textbf{} & a & b \\
517
+ \midrule
518
+ \textbf{0} & 1 & b1 \\
519
+ \textbf{1} & 2 & b2 \\
520
+ \bottomrule
521
+ \end{tabular}
522
+ """
523
+ assert observed == expected
524
+
525
+ def test_to_latex_no_bold_rows (self ):
526
+ # GH 16707
527
+ df = DataFrame ({'a' : [1 , 2 ], 'b' : ['b1' , 'b2' ]})
528
+ observed = df .to_latex (bold_rows = False )
529
+ expected = r"""\begin{tabular}{lrl}
530
+ \toprule
531
+ {} & a & b \\
532
+ \midrule
533
+ 0 & 1 & b1 \\
534
+ 1 & 2 & b2 \\
535
+ \bottomrule
536
+ \end{tabular}
537
+ """
538
+ assert observed == expected
0 commit comments