Skip to content

BUG: wrong parsing of microseconds with format arg (#4152) #4166

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 9, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion doc/source/release.rst
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,8 @@ pandas 0.12
object Series/Frame was not converting properly (:issue:`4119`)
- Fixed bugs in multi-index selection with column multi-index and duplicates
(:issue:`4145`, :issue:`4146`)

- Fixed bug in the parsing of microseconds when using the ``format``
argument in ``to_datetime`` (:issue:`4152`)

pandas 0.11.0
=============
Expand Down
4 changes: 3 additions & 1 deletion doc/source/v0.12.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,9 @@ Bug Fixes
(:issue:`4089`)
- Fixed bug in ``DataFrame.replace`` where a nested dict wasn't being
iterated over when regex=False (:issue:`4115`)

- Fixed bug in the parsing of microseconds when using the ``format``
argument in ``to_datetime`` (:issue:`4152`)

See the :ref:`full release notes
<release>` or issue tracker
on GitHub for a complete list.
7 changes: 7 additions & 0 deletions pandas/tseries/tests/test_timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -805,6 +805,13 @@ def _parse_format(fmt, values):
expected = _parse_format(fmt, values)
self.assert_(result.equals(expected))

def test_to_datetime_format_microsecond(self):
val = '01-Apr-2011 00:00:01.978'
format = '%d-%b-%Y %H:%M:%S.%f'
result = to_datetime(val, format=format)
exp = dt.datetime.strptime(val, format)
self.assert_(result == exp)

def test_to_datetime_on_datetime64_series(self):
# #2699
s = Series(date_range('1/1/2000', periods=10))
Expand Down
5 changes: 2 additions & 3 deletions pandas/tslib.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1049,8 +1049,7 @@ def array_strptime(ndarray[object] values, object fmt):
Py_ssize_t i, n = len(values)
pandas_datetimestruct dts
ndarray[int64_t] iresult
int year, month, day, minute, hour, second, weekday, julian
float64_t fraction
int year, month, day, minute, hour, second, fraction, weekday, julian

global _TimeRE_cache, _regex_cache
with _cache_lock:
Expand Down Expand Up @@ -1247,7 +1246,7 @@ def array_strptime(ndarray[object] values, object fmt):
dts.hour = hour
dts.min = minute
dts.sec = second
dts.us = int(fraction * 1000000)
dts.us = fraction

iresult[i] = pandas_datetimestruct_to_datetime(PANDAS_FR_ns, &dts)
_check_dts_bounds(iresult[i], &dts)
Expand Down