Skip to content

Commit 76c6351

Browse files
author
Chang She
committed
BUG/TST: typo caused read_csv to lose index name #1536
1 parent f89ced4 commit 76c6351

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

pandas/io/parsers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,7 @@ def _get_index_name(self, columns=None):
662662
index_name = None
663663
elif np.isscalar(self.index_col):
664664
if isinstance(self.index_col, basestring):
665-
index_names = self.index_col
665+
index_name = self.index_col
666666
for i, c in enumerate(list(columns)):
667667
if c == self.index_col:
668668
self.index_col = i

pandas/io/tests/test_parsers.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,23 @@ def test_index_col_named(self):
334334
self.assertRaises(ValueError, read_csv, StringIO(no_header),
335335
index_col='ID')
336336

337+
data = """\
338+
1,2,3,4,hello
339+
5,6,7,8,world
340+
9,10,11,12,foo
341+
"""
342+
names = ['a', 'b', 'c', 'd', 'message']
343+
xp = DataFrame({'a' : [1, 5, 9], 'b' : [2, 6, 10], 'c' : [3, 7, 11],
344+
'd' : [4, 8, 12]},
345+
index=Index(['hello', 'world', 'foo'], name='message'))
346+
rs = read_csv(StringIO(data), names=names, index_col=['message'])
347+
assert_frame_equal(xp, rs)
348+
self.assert_(xp.index.name == rs.index.name)
349+
350+
rs = read_csv(StringIO(data), names=names, index_col='message')
351+
assert_frame_equal(xp, rs)
352+
self.assert_(xp.index.name == rs.index.name)
353+
337354
def test_multiple_skts_example(self):
338355
data = "year, month, a, b\n 2001, 01, 0.0, 10.\n 2001, 02, 1.1, 11."
339356
pass

0 commit comments

Comments
 (0)