Skip to content

BUG: Fixed to_datetime for array with both Tz-aware datetimes and NaTs #5962

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
Jan 16, 2014
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 @@ -110,6 +110,7 @@ Bug Fixes
``MultiIndex`` (:issue:`5402`).
- Bug in ``pd.read_msgpack`` with inferring a ``DateTimeIndex`` frequencey
incorrectly (:issue:`5947`)
- Fixed ``to_datetime`` for array with both Tz-aware datetimes and ``NaT``s (:issue:`5961`)

pandas 0.13.0
-------------
Expand Down
8 changes: 7 additions & 1 deletion pandas/tseries/tests/test_timezones.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from pandas import (Index, Series, TimeSeries, DataFrame, isnull,
date_range, Timestamp)

from pandas import DatetimeIndex, Int64Index, to_datetime
from pandas import DatetimeIndex, Int64Index, to_datetime, NaT

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

def test_datetimeindex_tz_nat(self):
idx = to_datetime([Timestamp("2013-1-1", tz='US/Eastern'), NaT])

self.assertTrue(isnull(idx[1]))
self.assertTrue(idx[0].tzinfo is not None)


class TestTimeZones(tm.TestCase):
_multiprocess_can_split_ = True
Expand Down
2 changes: 1 addition & 1 deletion pandas/tslib.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -933,7 +933,7 @@ def datetime_to_datetime64(ndarray[object] values):
iresult = result.view('i8')
for i in range(n):
val = values[i]
if util._checknull(val):
if util._checknull(val) or val is NaT:
iresult[i] = iNaT
elif PyDateTime_Check(val):
if val.tzinfo is not None:
Expand Down