Skip to content

Commit 58d3d19

Browse files
BUG: pd.to_datetime doesn't raises AttributeError with specific inputs when errors='ignore'(#12424)
1 parent 0be0d67 commit 58d3d19

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

doc/source/whatsnew/v0.19.0.txt

+1
Original file line numberDiff line numberDiff line change
@@ -858,6 +858,7 @@ Bug Fixes
858858
- Bug in ``factorize`` raises ``AmbiguousTimeError`` if data contains datetime near DST boundary (:issue:`13750`)
859859
- Bug in ``.set_index`` raises ``AmbiguousTimeError`` if new index contains DST boundary and multi levels (:issue:`12920`)
860860
- Bug in ``pd.read_hdf()`` returns incorrect result when a ``DataFrame`` with a ``categorical`` column and a query which doesn't match any values (:issue:`13792`)
861+
- Bug in ``pd.to_datetime()`` raise ``AttributeError`` with NaN and the other string is not valid when errors='ignore' (:issue:`12424`)
861862

862863

863864
- Bug in ``Series`` comparison operators when dealing with zero dim NumPy arrays (:issue:`13006`)

pandas/tests/test_algos.py

+6
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,12 @@ def test_value_counts_datetime_outofbounds(self):
568568
exp = pd.Series([3, 2, 1], index=exp_index)
569569
tm.assert_series_equal(res, exp)
570570

571+
# GH 12424
572+
res = pd.to_datetime(pd.Series(['2362-01-01', np.nan]),
573+
errors='ignore')
574+
exp = pd.Series(['2362-01-01', np.nan], dtype=object)
575+
tm.assert_series_equal(res, exp)
576+
571577
def test_categorical(self):
572578
s = Series(pd.Categorical(list('aaabbc')))
573579
result = s.value_counts()

pandas/tslib.pyx

+3-3
Original file line numberDiff line numberDiff line change
@@ -2396,10 +2396,10 @@ cpdef array_to_datetime(ndarray[object] values, errors='raise',
23962396

23972397
# set as nan except if its a NaT
23982398
if _checknull_with_nat(val):
2399-
if val.view('i8') == NPY_NAT:
2400-
oresult[i] = NaT
2401-
else:
2399+
if PyFloat_Check(val):
24022400
oresult[i] = np.nan
2401+
else:
2402+
oresult[i] = NaT
24032403
elif util.is_datetime64_object(val):
24042404
if get_datetime64_value(val) == NPY_NAT:
24052405
oresult[i] = NaT

0 commit comments

Comments
 (0)