Skip to content

Commit 3186fef

Browse files
conquistador1492jreback
authored andcommitted
BUG: pd.to_datetime doesn't raises AttributeError with specific inputs when errors='ignore'(#12424) (#13909)
1 parent e5ee5d2 commit 3186fef

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
@@ -876,6 +876,7 @@ Bug Fixes
876876
- Bug in ``factorize`` raises ``AmbiguousTimeError`` if data contains datetime near DST boundary (:issue:`13750`)
877877
- Bug in ``.set_index`` raises ``AmbiguousTimeError`` if new index contains DST boundary and multi levels (:issue:`12920`)
878878
- 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`)
879+
- Bug in ``pd.to_datetime()`` raise ``AttributeError`` with NaN and the other string is not valid when errors='ignore' (:issue:`12424`)
879880

880881

881882
- 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)