@@ -455,6 +455,49 @@ def test_pandas_without_index():
455
455
raise SkipTest () # this test is optional
456
456
457
457
458
+ def test_pandas_rst_with_index ():
459
+ "Output: a pandas Dataframe with an index in ReStructuredText format"
460
+ try :
461
+ import pandas
462
+ df = pandas .DataFrame ([["one" , 1 ], ["two" , None ]],
463
+ columns = ["string" , "number" ],
464
+ index = ["a" , "b" ])
465
+ expected = "\n " .join (
466
+ ['=== ======== ========' ,
467
+ '- string number' ,
468
+ '=== ======== ========' ,
469
+ 'a one 1' ,
470
+ 'b two nan' ,
471
+ '=== ======== ========' ])
472
+ result = tabulate (df , tablefmt = "rst" , headers = "keys" )
473
+ assert_equal (expected , result )
474
+ except ImportError :
475
+ print ("test_pandas_rst_with_index is skipped" )
476
+ raise SkipTest () # this test is optional
477
+
478
+
479
+ def test_pandas_rst_with_named_index ():
480
+ "Output: a pandas Dataframe with a named index in ReStructuredText format"
481
+ try :
482
+ import pandas
483
+ index = pandas .Index (["a" , "b" ], name = 'index' )
484
+ df = pandas .DataFrame ([["one" , 1 ], ["two" , None ]],
485
+ columns = ["string" , "number" ],
486
+ index = index )
487
+ expected = "\n " .join (
488
+ ['======= ======== ========' ,
489
+ 'index string number' ,
490
+ '======= ======== ========' ,
491
+ 'a one 1' ,
492
+ 'b two nan' ,
493
+ '======= ======== ========' ])
494
+ result = tabulate (df , tablefmt = "rst" , headers = "keys" )
495
+ assert_equal (expected , result )
496
+ except ImportError :
497
+ print ("test_pandas_rst_with_index is skipped" )
498
+ raise SkipTest () # this test is optional
499
+
500
+
458
501
def test_dict_like_with_index ():
459
502
"Output: a table with a running index"
460
503
dd = {"b" : range (101 ,104 )}
0 commit comments