@@ -476,18 +476,38 @@ def _check_extension_indexlabels(self, ext):
476
476
self .assertEqual (frame .index .names , recons .index .names )
477
477
478
478
#test index_labels in same row as column names
479
- self .frame .to_excel ('/tmp/tests.xls' , 'test1' ,
479
+ path = '%s.xls' % tm .rands (10 )
480
+ self .frame .to_excel (path , 'test1' ,
480
481
cols = ['A' , 'B' , 'C' , 'D' ], index = False )
481
482
#take 'A' and 'B' as indexes (they are in same row as cols 'C', 'D')
482
483
df = self .frame .copy ()
483
484
df = df .set_index (['A' , 'B' ])
484
485
485
- reader = ExcelFile ('/tmp/tests.xls' )
486
+ reader = ExcelFile (path )
486
487
recons = reader .parse ('test1' , index_col = [0 , 1 ])
487
488
tm .assert_frame_equal (df , recons )
488
489
489
490
os .remove (path )
490
491
492
+ def test_excel_roundtrip_indexname (self ):
493
+ path = '%s.xls' % tm .rands (10 )
494
+
495
+ df = DataFrame (np .random .randn (10 , 4 ))
496
+ df .index .name = 'foo'
497
+
498
+ df .to_excel (path )
499
+
500
+ xf = ExcelFile (path )
501
+ result = xf .parse (xf .sheet_names [0 ], index_col = 0 )
502
+
503
+ tm .assert_frame_equal (result , df )
504
+ self .assertEqual (result .index .name , 'foo' )
505
+
506
+ try :
507
+ os .remove (path )
508
+ except os .error :
509
+ pass
510
+
491
511
def test_excel_roundtrip_datetime (self ):
492
512
_skip_if_no_xlrd ()
493
513
_skip_if_no_xlwt ()
0 commit comments