Skip to content

Commit a57d59d

Browse files
committed
Merge pull request #5157 from danbirken/gh4928
BUG: Fix to_datetime() uncaught error with unparseable inputs #4928
2 parents 35b0b0e + 47ffef3 commit a57d59d

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

doc/source/release.rst

+1
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,7 @@ Bug Fixes
576576
function (:issue:`5150`).
577577
- Fix a bug with ``NDFrame.replace()`` which made replacement appear as
578578
though it was (incorrectly) using regular expressions (:issue:`5143`).
579+
- Fix better error message for to_datetime (:issue:`4928`)
579580

580581
pandas 0.12.0
581582
-------------

pandas/tseries/tests/test_timeseries.py

+10
Original file line numberDiff line numberDiff line change
@@ -931,6 +931,16 @@ def test_to_datetime_types(self):
931931
### expected = to_datetime('2012')
932932
### self.assert_(result == expected)
933933

934+
def test_to_datetime_unprocessable_input(self):
935+
# GH 4928
936+
self.assert_(
937+
np.array_equal(
938+
to_datetime([1, '1']),
939+
np.array([1, '1'], dtype='O')
940+
)
941+
)
942+
self.assertRaises(TypeError, to_datetime, [1, '1'], errors='raise')
943+
934944
def test_to_datetime_other_datetime64_units(self):
935945
# 5/25/2012
936946
scalar = np.int64(1337904000000000).view('M8[us]')

pandas/tslib.pyx

+5-1
Original file line numberDiff line numberDiff line change
@@ -1055,7 +1055,7 @@ def array_to_datetime(ndarray[object] values, raise_=False, dayfirst=False,
10551055
val = values[i]
10561056
if util._checknull(val):
10571057
oresult[i] = val
1058-
else:
1058+
elif util.is_string_object(val):
10591059
if len(val) == 0:
10601060
# TODO: ??
10611061
oresult[i] = 'NaT'
@@ -1069,6 +1069,10 @@ def array_to_datetime(ndarray[object] values, raise_=False, dayfirst=False,
10691069
raise
10701070
return values
10711071
# oresult[i] = val
1072+
else:
1073+
if raise_:
1074+
raise
1075+
return values
10721076

10731077
return oresult
10741078

0 commit comments

Comments
 (0)