@@ -1405,3 +1405,88 @@ def test_to_latex_multiindex_multirow(self):
1405
1405
"""
1406
1406
)
1407
1407
assert result == expected
1408
+
1409
+ def test_to_latex_multiindex_format_single_index_hidden (self ):
1410
+ # GH 52218
1411
+ df = DataFrame (
1412
+ {
1413
+ "A" : [1 , 2 ],
1414
+ "B" : [4 , 5 ],
1415
+ }
1416
+ )
1417
+ result = (
1418
+ df .style .hide (axis = "index" )
1419
+ .map_index (lambda v : "textbf:--rwrap;" , axis = "columns" )
1420
+ .to_latex ()
1421
+ )
1422
+ expected = _dedent (r"""
1423
+ \begin{tabular}{rr}
1424
+ \textbf{A} & \textbf{B} \\
1425
+ 1 & 4 \\
1426
+ 2 & 5 \\
1427
+ \end{tabular}
1428
+ """ )
1429
+ assert result == expected
1430
+
1431
+ def test_to_latex_multiindex_format_triple_index_two_hidden (self ):
1432
+ # GH 52218
1433
+ arrays = [
1434
+ ["A" , "A" , "B" , "B" ],
1435
+ ["one" , "two" , "one" , "two" ],
1436
+ ["x" , "x" , "y" , "y" ],
1437
+ ]
1438
+ index = pd .MultiIndex .from_arrays (
1439
+ arrays , names = ["Level 0" , "Level 1" , "Level 2" ]
1440
+ )
1441
+ df = DataFrame (
1442
+ [[0 , 0 , 0 ], [0 , 0 , 0 ], [0 , 0 , 0 ], [0 , 0 , 0 ]],
1443
+ index = index ,
1444
+ columns = ["C1" , "C2" , "C3" ],
1445
+ )
1446
+ result = (
1447
+ df .style .hide (axis = "index" , level = [0 , 1 ])
1448
+ .map_index (lambda v : "textbf:--rwrap;" , axis = "columns" )
1449
+ .to_latex ()
1450
+ )
1451
+ expected = _dedent (r"""
1452
+ \begin{tabular}{lrrr}
1453
+ & \textbf{C1} & \textbf{C2} & \textbf{C3} \\
1454
+ Level 2 & & & \\
1455
+ x & 0 & 0 & 0 \\
1456
+ x & 0 & 0 & 0 \\
1457
+ y & 0 & 0 & 0 \\
1458
+ y & 0 & 0 & 0 \\
1459
+ \end{tabular}
1460
+ """ )
1461
+ assert result == expected
1462
+
1463
+ def test_to_latex_multiindex_format_triple_index_all_hidden (self ):
1464
+ # GH 52218
1465
+ arrays = [
1466
+ ["A" , "A" , "B" , "B" ],
1467
+ ["one" , "two" , "one" , "two" ],
1468
+ ["x" , "x" , "y" , "y" ],
1469
+ ]
1470
+ index = pd .MultiIndex .from_arrays (
1471
+ arrays , names = ["Level 0" , "Level 1" , "Level 2" ]
1472
+ )
1473
+ df = DataFrame (
1474
+ [[0 , 0 , 0 ], [0 , 0 , 0 ], [0 , 0 , 0 ], [0 , 0 , 0 ]],
1475
+ index = index ,
1476
+ columns = ["C1" , "C2" , "C3" ],
1477
+ )
1478
+ result = (
1479
+ df .style .hide (axis = "index" , level = [0 , 1 , 2 ])
1480
+ .map_index (lambda v : "textbf:--rwrap;" , axis = "columns" )
1481
+ .to_latex ()
1482
+ )
1483
+ expected = _dedent (r"""
1484
+ \begin{tabular}{rrr}
1485
+ \textbf{C1} & \textbf{C2} & \textbf{C3} \\
1486
+ 0 & 0 & 0 \\
1487
+ 0 & 0 & 0 \\
1488
+ 0 & 0 & 0 \\
1489
+ 0 & 0 & 0 \\
1490
+ \end{tabular}
1491
+ """ )
1492
+ assert result == expected
0 commit comments