Skip to content

Commit a7ff671

Browse files
committed
TST: unit test to verify #2396 fixed
1 parent bc3fcc6 commit a7ff671

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

pandas/io/tests/test_excel.py

+22-2
Original file line numberDiff line numberDiff line change
@@ -476,18 +476,38 @@ def _check_extension_indexlabels(self, ext):
476476
self.assertEqual(frame.index.names, recons.index.names)
477477

478478
#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',
480481
cols=['A', 'B', 'C', 'D'], index=False)
481482
#take 'A' and 'B' as indexes (they are in same row as cols 'C', 'D')
482483
df = self.frame.copy()
483484
df = df.set_index(['A', 'B'])
484485

485-
reader = ExcelFile('/tmp/tests.xls')
486+
reader = ExcelFile(path)
486487
recons = reader.parse('test1', index_col=[0, 1])
487488
tm.assert_frame_equal(df, recons)
488489

489490
os.remove(path)
490491

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+
491511
def test_excel_roundtrip_datetime(self):
492512
_skip_if_no_xlrd()
493513
_skip_if_no_xlwt()

0 commit comments

Comments
 (0)