Skip to content

Commit

Permalink
BUG/TST: typo caused read_csv to lose index name pandas-dev#1536
Browse files Browse the repository at this point in the history
  • Loading branch information
Chang She committed Jun 27, 2012
1 parent f89ced4 commit 76c6351
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pandas/io/parsers.py
Expand Up @@ -662,7 +662,7 @@ def _get_index_name(self, columns=None):
index_name = None
elif np.isscalar(self.index_col):
if isinstance(self.index_col, basestring):
index_names = self.index_col
index_name = self.index_col
for i, c in enumerate(list(columns)):
if c == self.index_col:
self.index_col = i
Expand Down
17 changes: 17 additions & 0 deletions pandas/io/tests/test_parsers.py
Expand Up @@ -334,6 +334,23 @@ def test_index_col_named(self):
self.assertRaises(ValueError, read_csv, StringIO(no_header),
index_col='ID')

data = """\
1,2,3,4,hello
5,6,7,8,world
9,10,11,12,foo
"""
names = ['a', 'b', 'c', 'd', 'message']
xp = DataFrame({'a' : [1, 5, 9], 'b' : [2, 6, 10], 'c' : [3, 7, 11],
'd' : [4, 8, 12]},
index=Index(['hello', 'world', 'foo'], name='message'))
rs = read_csv(StringIO(data), names=names, index_col=['message'])
assert_frame_equal(xp, rs)
self.assert_(xp.index.name == rs.index.name)

rs = read_csv(StringIO(data), names=names, index_col='message')
assert_frame_equal(xp, rs)
self.assert_(xp.index.name == rs.index.name)

def test_multiple_skts_example(self):
data = "year, month, a, b\n 2001, 01, 0.0, 10.\n 2001, 02, 1.1, 11."
pass
Expand Down

0 comments on commit 76c6351

Please sign in to comment.