Skip to content

BUG: Fix to_datetime() uncaught error with unparseable inputs #4928 #5157

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
Oct 8, 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
1 change: 1 addition & 0 deletions doc/source/release.rst
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,7 @@ Bug Fixes
function (:issue:`5150`).
- Fix a bug with ``NDFrame.replace()`` which made replacement appear as
though it was (incorrectly) using regular expressions (:issue:`5143`).
- Fix better error message for to_datetime (:issue:`4928`)

pandas 0.12.0
-------------
Expand Down
10 changes: 10 additions & 0 deletions pandas/tseries/tests/test_timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -931,6 +931,16 @@ def test_to_datetime_types(self):
### expected = to_datetime('2012')
### self.assert_(result == expected)

def test_to_datetime_unprocessable_input(self):
# GH 4928
self.assert_(
np.array_equal(
to_datetime([1, '1']),
np.array([1, '1'], dtype='O')
)
)
self.assertRaises(TypeError, to_datetime, [1, '1'], errors='raise')

def test_to_datetime_other_datetime64_units(self):
# 5/25/2012
scalar = np.int64(1337904000000000).view('M8[us]')
Expand Down
6 changes: 5 additions & 1 deletion pandas/tslib.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1055,7 +1055,7 @@ def array_to_datetime(ndarray[object] values, raise_=False, dayfirst=False,
val = values[i]
if util._checknull(val):
oresult[i] = val
else:
elif util.is_string_object(val):
if len(val) == 0:
# TODO: ??
oresult[i] = 'NaT'
Expand All @@ -1069,6 +1069,10 @@ def array_to_datetime(ndarray[object] values, raise_=False, dayfirst=False,
raise
return values
# oresult[i] = val
else:
if raise_:
raise
return values

return oresult

Expand Down