File tree Expand file tree Collapse file tree 2 files changed +24
-1
lines changed Expand file tree Collapse file tree 2 files changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -288,7 +288,10 @@ def _get_index_name(self):
288
288
index_name = None
289
289
if implicit_first_cols > 0 :
290
290
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 )
292
295
index_name = None
293
296
elif np .isscalar (self .index_col ):
294
297
index_name = columns .pop (self .index_col )
Original file line number Diff line number Diff line change @@ -110,6 +110,17 @@ def test_csv_custom_parser(self):
110
110
expected = read_csv (StringIO (data ), parse_dates = True )
111
111
assert_frame_equal (df , expected )
112
112
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
+
113
124
def test_no_header (self ):
114
125
data = """1,2,3,4,5
115
126
6,7,8,9,10
@@ -222,6 +233,15 @@ def test_infer_index_col(self):
222
233
data = read_csv (StringIO (data ))
223
234
self .assert_ (data .index .equals (Index (['foo' , 'bar' , 'baz' ])))
224
235
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
+
225
245
def test_read_nrows (self ):
226
246
df = read_csv (StringIO (self .data1 ), nrows = 3 )
227
247
expected = read_csv (StringIO (self .data1 ))[:3 ]
You can’t perform that action at this time.
0 commit comments