Skip to content

Commit

Permalink
BUG: read_csv regression, moved date parsing to before type conversio…
Browse files Browse the repository at this point in the history
…ns now so can parse yymmdd hhmm format now #1905
  • Loading branch information
Chang She committed Oct 4, 2012
1 parent 3a11f00 commit 431f4b4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
6 changes: 3 additions & 3 deletions pandas/io/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -833,6 +833,9 @@ def get_chunk(self, rows=None):
alldata = self._rows_to_cols(content)
data = self._exclude_implicit_index(alldata)

if self.parse_dates is not None:
data, columns = self._process_date_conversion(data)

# apply converters
for col, f in self.converters.iteritems():
if isinstance(col, int) and col not in self.orig_columns:
Expand All @@ -841,9 +844,6 @@ def get_chunk(self, rows=None):

data = _convert_to_ndarrays(data, self.na_values, self.verbose)

if self.parse_dates is not None:
data, columns = self._process_date_conversion(data)

if self.index_col is None:
numrows = len(content)
index = Index(np.arange(numrows))
Expand Down
16 changes: 15 additions & 1 deletion pandas/io/tests/test_parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from numpy import nan
import numpy as np

from pandas import DataFrame, Series, Index, isnull, MultiIndex
from pandas import DataFrame, Series, Index, isnull, MultiIndex, DatetimeIndex
import pandas.io.parsers as parsers
from pandas.io.parsers import (read_csv, read_table, read_fwf,
ExcelFile, TextParser)
Expand Down Expand Up @@ -667,6 +667,20 @@ def test_parse_dates_string(self):
'C': [2, 4, 5]}, idx)
assert_frame_equal(rs, xp)

def test_yy_format(self):
data = """date,time,B,C
090131,0010,1,2
090228,1020,3,4
090331,0830,5,6
"""
rs = read_csv(StringIO(data), index_col=0,
parse_dates=[['date', 'time']])
idx = DatetimeIndex([datetime(2009,1,31,0,10,0),
datetime(2009,2,28,10,20,0),
datetime(2009,3,31,8,30,0)]).asobject
idx.name = 'date'
xp = DataFrame({'B': [1, 3, 5], 'C': [2, 4, 6]}, idx)
assert_frame_equal(rs, xp)

def test_parse_dates_column_list(self):
from pandas.core.datetools import to_datetime
Expand Down

0 comments on commit 431f4b4

Please sign in to comment.