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