@@ -435,6 +435,114 @@ def test_to_html_escape_disabled(self):
435
435
</table>"""
436
436
self .assertEqual (xp , rs )
437
437
438
+ def test_to_html_multiindex_sparsify_false_multi_sparse (self ):
439
+ with option_context ('display.multi_sparse' , False ):
440
+ index = pd .MultiIndex .from_arrays ([[0 , 0 , 1 , 1 ], [0 , 1 , 0 , 1 ]],
441
+ names = ['foo' , None ])
442
+
443
+ df = DataFrame ([[0 , 1 ], [2 , 3 ], [4 , 5 ], [6 , 7 ]], index = index )
444
+
445
+ result = df .to_html ()
446
+ expected = """\
447
+ <table border="1" class="dataframe">
448
+ <thead>
449
+ <tr style="text-align: right;">
450
+ <th></th>
451
+ <th></th>
452
+ <th>0</th>
453
+ <th>1</th>
454
+ </tr>
455
+ <tr>
456
+ <th>foo</th>
457
+ <th></th>
458
+ <th></th>
459
+ <th></th>
460
+ </tr>
461
+ </thead>
462
+ <tbody>
463
+ <tr>
464
+ <th>0</th>
465
+ <th>0</th>
466
+ <td> 0</td>
467
+ <td> 1</td>
468
+ </tr>
469
+ <tr>
470
+ <th>0</th>
471
+ <th>1</th>
472
+ <td> 2</td>
473
+ <td> 3</td>
474
+ </tr>
475
+ <tr>
476
+ <th>1</th>
477
+ <th>0</th>
478
+ <td> 4</td>
479
+ <td> 5</td>
480
+ </tr>
481
+ <tr>
482
+ <th>1</th>
483
+ <th>1</th>
484
+ <td> 6</td>
485
+ <td> 7</td>
486
+ </tr>
487
+ </tbody>
488
+ </table>"""
489
+ self .assertEquals (result , expected )
490
+
491
+ df = DataFrame ([[0 , 1 ], [2 , 3 ], [4 , 5 ], [6 , 7 ]],
492
+ columns = index [::2 ], index = index )
493
+
494
+ result = df .to_html ()
495
+ expected = """\
496
+ <table border="1" class="dataframe">
497
+ <thead>
498
+ <tr>
499
+ <th></th>
500
+ <th>foo</th>
501
+ <th>0</th>
502
+ <th>1</th>
503
+ </tr>
504
+ <tr>
505
+ <th></th>
506
+ <th></th>
507
+ <th>0</th>
508
+ <th>0</th>
509
+ </tr>
510
+ <tr>
511
+ <th>foo</th>
512
+ <th></th>
513
+ <th></th>
514
+ <th></th>
515
+ </tr>
516
+ </thead>
517
+ <tbody>
518
+ <tr>
519
+ <th>0</th>
520
+ <th>0</th>
521
+ <td> 0</td>
522
+ <td> 1</td>
523
+ </tr>
524
+ <tr>
525
+ <th>0</th>
526
+ <th>1</th>
527
+ <td> 2</td>
528
+ <td> 3</td>
529
+ </tr>
530
+ <tr>
531
+ <th>1</th>
532
+ <th>0</th>
533
+ <td> 4</td>
534
+ <td> 5</td>
535
+ </tr>
536
+ <tr>
537
+ <th>1</th>
538
+ <th>1</th>
539
+ <td> 6</td>
540
+ <td> 7</td>
541
+ </tr>
542
+ </tbody>
543
+ </table>"""
544
+ self .assertEquals (result , expected )
545
+
438
546
def test_to_html_multiindex_sparsify (self ):
439
547
index = pd .MultiIndex .from_arrays ([[0 , 0 , 1 , 1 ], [0 , 1 , 0 , 1 ]],
440
548
names = ['foo' , None ])
0 commit comments