Skip to content

Commit 1a6b967

Browse files
committed
Merge pull request #4166 from jorisvandenbossche/bug-microsecond-parsing
BUG: wrong parsing of microseconds with format arg (#4152)
2 parents b96ab6b + 1cea6bb commit 1a6b967

File tree

4 files changed

+14
-5
lines changed

4 files changed

+14
-5
lines changed

doc/source/release.rst

+2-1
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,8 @@ pandas 0.12
321321
object Series/Frame was not converting properly (:issue:`4119`)
322322
- Fixed bugs in multi-index selection with column multi-index and duplicates
323323
(:issue:`4145`, :issue:`4146`)
324-
324+
- Fixed bug in the parsing of microseconds when using the ``format``
325+
argument in ``to_datetime`` (:issue:`4152`)
325326

326327
pandas 0.11.0
327328
=============

doc/source/v0.12.0.txt

+3-1
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,9 @@ Bug Fixes
459459
(:issue:`4089`)
460460
- Fixed bug in ``DataFrame.replace`` where a nested dict wasn't being
461461
iterated over when regex=False (:issue:`4115`)
462-
462+
- Fixed bug in the parsing of microseconds when using the ``format``
463+
argument in ``to_datetime`` (:issue:`4152`)
464+
463465
See the :ref:`full release notes
464466
<release>` or issue tracker
465467
on GitHub for a complete list.

pandas/tseries/tests/test_timeseries.py

+7
Original file line numberDiff line numberDiff line change
@@ -805,6 +805,13 @@ def _parse_format(fmt, values):
805805
expected = _parse_format(fmt, values)
806806
self.assert_(result.equals(expected))
807807

808+
def test_to_datetime_format_microsecond(self):
809+
val = '01-Apr-2011 00:00:01.978'
810+
format = '%d-%b-%Y %H:%M:%S.%f'
811+
result = to_datetime(val, format=format)
812+
exp = dt.datetime.strptime(val, format)
813+
self.assert_(result == exp)
814+
808815
def test_to_datetime_on_datetime64_series(self):
809816
# #2699
810817
s = Series(date_range('1/1/2000', periods=10))

pandas/tslib.pyx

+2-3
Original file line numberDiff line numberDiff line change
@@ -1049,8 +1049,7 @@ def array_strptime(ndarray[object] values, object fmt):
10491049
Py_ssize_t i, n = len(values)
10501050
pandas_datetimestruct dts
10511051
ndarray[int64_t] iresult
1052-
int year, month, day, minute, hour, second, weekday, julian
1053-
float64_t fraction
1052+
int year, month, day, minute, hour, second, fraction, weekday, julian
10541053

10551054
global _TimeRE_cache, _regex_cache
10561055
with _cache_lock:
@@ -1247,7 +1246,7 @@ def array_strptime(ndarray[object] values, object fmt):
12471246
dts.hour = hour
12481247
dts.min = minute
12491248
dts.sec = second
1250-
dts.us = int(fraction * 1000000)
1249+
dts.us = fraction
12511250

12521251
iresult[i] = pandas_datetimestruct_to_datetime(PANDAS_FR_ns, &dts)
12531252
_check_dts_bounds(iresult[i], &dts)

0 commit comments

Comments
 (0)