@@ -1844,6 +1844,67 @@ def test_to_html_no_index_max_rows(self):
18441844 </table>""" )
18451845 assert result == expected
18461846
1847+ def test_to_html_multiindex_max_cols (self ):
1848+ # GH 6131
1849+ index = MultiIndex (levels = [['ba' , 'bb' , 'bc' ], ['ca' , 'cb' , 'cc' ]],
1850+ labels = [[0 , 1 , 2 ], [0 , 1 , 2 ]],
1851+ names = ['b' , 'c' ])
1852+ columns = MultiIndex (levels = [['d' ], ['aa' , 'ab' , 'ac' ]],
1853+ labels = [[0 , 0 , 0 ], [0 , 1 , 2 ]],
1854+ names = [None , 'a' ])
1855+ data = np .array (
1856+ [[1. , np .nan , np .nan ], [np .nan , 2. , np .nan ], [np .nan , np .nan , 3. ]])
1857+ df = DataFrame (data , index , columns )
1858+ result = df .to_html (max_cols = 2 )
1859+ expected = dedent ("""\
1860+ <table border="1" class="dataframe">
1861+ <thead>
1862+ <tr>
1863+ <th></th>
1864+ <th></th>
1865+ <th colspan="3" halign="left">d</th>
1866+ </tr>
1867+ <tr>
1868+ <th></th>
1869+ <th>a</th>
1870+ <th>aa</th>
1871+ <th>...</th>
1872+ <th>ac</th>
1873+ </tr>
1874+ <tr>
1875+ <th>b</th>
1876+ <th>c</th>
1877+ <th></th>
1878+ <th></th>
1879+ <th></th>
1880+ </tr>
1881+ </thead>
1882+ <tbody>
1883+ <tr>
1884+ <th>ba</th>
1885+ <th>ca</th>
1886+ <td>1.0</td>
1887+ <td>...</td>
1888+ <td>NaN</td>
1889+ </tr>
1890+ <tr>
1891+ <th>bb</th>
1892+ <th>cb</th>
1893+ <td>NaN</td>
1894+ <td>...</td>
1895+ <td>NaN</td>
1896+ </tr>
1897+ <tr>
1898+ <th>bc</th>
1899+ <th>cc</th>
1900+ <td>NaN</td>
1901+ <td>...</td>
1902+ <td>3.0</td>
1903+ </tr>
1904+ </tbody>
1905+ </table>""" )
1906+ assert result == expected
1907+
18471908 def test_to_html_notebook_has_style (self ):
18481909 df = pd .DataFrame ({"A" : [1 , 2 , 3 ]})
18491910 result = df .to_html (notebook = True )
0 commit comments