Skip to content

Commit

Permalink
BUG: tools.parse_time_string does not parse intraday strings correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
changhiskhan committed Nov 26, 2012
1 parent ef04a60 commit b76fe2a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
2 changes: 1 addition & 1 deletion pandas/tseries/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -1539,7 +1539,7 @@ def _to_m8(key):
def _str_to_dt_array(arr, offset=None, dayfirst=None, yearfirst=None):
def parser(x):
result = parse_time_string(x, offset, dayfirst=dayfirst,
yearfirst=None)
yearfirst=yearfirst)
return result[0]

arr = np.asarray(arr, dtype=object)
Expand Down
4 changes: 4 additions & 0 deletions pandas/tseries/tests/test_timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,10 @@ def _check_rng(rng):
_check_rng(rng_eastern)
_check_rng(rng_utc)

def test_ctor_str_intraday(self):
rng = DatetimeIndex(['1-1-2000 00:00:01'])
self.assert_(rng[0].second == 1)

def test_series_ctor_plus_datetimeindex(self):
rng = date_range('20090415', '20090519', freq='B')
data = dict((k, 1) for k in rng)
Expand Down
9 changes: 2 additions & 7 deletions pandas/tseries/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,18 +235,13 @@ def parse_time_string(arg, freq=None, dayfirst=None, yearfirst=None):

repl = {}
reso = 'year'
stopped = False

for attr in ["year", "month", "day", "hour",
"minute", "second", "microsecond"]:
can_be_zero = ['hour', 'minute', 'second', 'microsecond']
value = getattr(parsed, attr)
if value is not None and value != 0: # or attr in can_be_zero):
repl[attr] = value
if not stopped:
reso = attr
else:
stopped = True
break
reso = attr
ret = default.replace(**repl)
return ret, parsed, reso # datetime, resolution

Expand Down

0 comments on commit b76fe2a

Please sign in to comment.