Skip to content

Commit b133013

Browse files
committed
BUG: could not parse dates with implicit first column
1 parent fd4c4c9 commit b133013

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

pandas/io/parsers.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,10 @@ def _get_index_name(self):
288288
index_name = None
289289
if implicit_first_cols > 0:
290290
if self.index_col is None:
291-
self.index_col = range(implicit_first_cols)
291+
if implicit_first_cols == 1:
292+
self.index_col = 0
293+
else:
294+
self.index_col = range(implicit_first_cols)
292295
index_name = None
293296
elif np.isscalar(self.index_col):
294297
index_name = columns.pop(self.index_col)

pandas/io/tests/test_parsers.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,17 @@ def test_csv_custom_parser(self):
110110
expected = read_csv(StringIO(data), parse_dates=True)
111111
assert_frame_equal(df, expected)
112112

113+
def test_parse_dates_implicit_first_col(self):
114+
data = """A,B,C
115+
20090101,a,1,2
116+
20090102,b,3,4
117+
20090103,c,4,5
118+
"""
119+
df = read_csv(StringIO(data), parse_dates=True)
120+
expected = read_csv(StringIO(data), index_col=0, parse_dates=True)
121+
self.assert_(isinstance(df.index[0], datetime))
122+
assert_frame_equal(df, expected)
123+
113124
def test_no_header(self):
114125
data = """1,2,3,4,5
115126
6,7,8,9,10
@@ -222,6 +233,15 @@ def test_infer_index_col(self):
222233
data = read_csv(StringIO(data))
223234
self.assert_(data.index.equals(Index(['foo', 'bar', 'baz'])))
224235

236+
def test_sniff_delimiter(self):
237+
data = """index|A|B|C
238+
foo|1|2|3
239+
bar|4|5|6
240+
baz|7|8|9
241+
"""
242+
data = read_csv(StringIO(data), index_col=0)
243+
self.assert_(data.index.equals(Index(['foo', 'bar', 'baz'])))
244+
225245
def test_read_nrows(self):
226246
df = read_csv(StringIO(self.data1), nrows=3)
227247
expected = read_csv(StringIO(self.data1))[:3]

0 commit comments

Comments
 (0)