Skip to content

Commit 9e21718

Browse files
committed
Merge pull request #5962 from cancan101/fix_nat_tz
BUG: Fixed to_datetime for array with both Tz-aware datetimes and NaTs
2 parents 4dd4e22 + 31537d1 commit 9e21718

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

doc/source/release.rst

+1
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ Bug Fixes
110110
``MultiIndex`` (:issue:`5402`).
111111
- Bug in ``pd.read_msgpack`` with inferring a ``DateTimeIndex`` frequencey
112112
incorrectly (:issue:`5947`)
113+
- Fixed ``to_datetime`` for array with both Tz-aware datetimes and ``NaT``s (:issue:`5961`)
113114
114115
pandas 0.13.0
115116
-------------

pandas/tseries/tests/test_timezones.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from pandas import (Index, Series, TimeSeries, DataFrame, isnull,
1111
date_range, Timestamp)
1212

13-
from pandas import DatetimeIndex, Int64Index, to_datetime
13+
from pandas import DatetimeIndex, Int64Index, to_datetime, NaT
1414

1515
from pandas.core.daterange import DateRange
1616
import pandas.core.datetools as datetools
@@ -671,6 +671,12 @@ def test_datetimeindex_tz(self):
671671
for other in [idx2, idx3, idx4]:
672672
self.assert_(idx1.equals(other))
673673

674+
def test_datetimeindex_tz_nat(self):
675+
idx = to_datetime([Timestamp("2013-1-1", tz='US/Eastern'), NaT])
676+
677+
self.assertTrue(isnull(idx[1]))
678+
self.assertTrue(idx[0].tzinfo is not None)
679+
674680

675681
class TestTimeZones(tm.TestCase):
676682
_multiprocess_can_split_ = True

pandas/tslib.pyx

+1-1
Original file line numberDiff line numberDiff line change
@@ -933,7 +933,7 @@ def datetime_to_datetime64(ndarray[object] values):
933933
iresult = result.view('i8')
934934
for i in range(n):
935935
val = values[i]
936-
if util._checknull(val):
936+
if util._checknull(val) or val is NaT:
937937
iresult[i] = iNaT
938938
elif PyDateTime_Check(val):
939939
if val.tzinfo is not None:

0 commit comments

Comments
 (0)