@@ -67,7 +67,7 @@ cdef int64_t NPY_NAT = util.get_nat()
6767compat_NaT = np.array([NPY_NAT]).astype(' m8[ns]' ).item()
6868
6969# numpy actual nat object
70- np_NaT = np.datetime64(' NaT' , dtype = ' M8 ' )
70+ np_NaT = np.datetime64(' NaT' )
7171
7272try :
7373 basestring
@@ -892,8 +892,11 @@ cdef convert_to_tsobject(object ts, object tz, object unit):
892892 if ts is None or ts is NaT or ts is np_NaT:
893893 obj.value = NPY_NAT
894894 elif is_datetime64_object(ts):
895- obj.value = _get_datetime64_nanos(ts)
896- pandas_datetime_to_datetimestruct(obj.value, PANDAS_FR_ns, & obj.dts)
895+ if ts == np_NaT:
896+ obj.value = NPY_NAT
897+ else :
898+ obj.value = _get_datetime64_nanos(ts)
899+ pandas_datetime_to_datetimestruct(obj.value, PANDAS_FR_ns, & obj.dts)
897900 elif is_integer_object(ts):
898901 if ts == NPY_NAT:
899902 obj.value = NPY_NAT
@@ -1218,7 +1221,7 @@ def array_to_datetime(ndarray[object] values, raise_=False, dayfirst=False,
12181221 continue
12191222 raise
12201223 elif util.is_datetime64_object(val):
1221- if val is np_NaT or val.view(' i8' ) == iNaT:
1224+ if val == np_NaT or val.view(' i8' ) == iNaT:
12221225 iresult[i] = iNaT
12231226 else :
12241227 try :
@@ -1296,10 +1299,13 @@ def array_to_datetime(ndarray[object] values, raise_=False, dayfirst=False,
12961299 val = values[i]
12971300
12981301 # set as nan if is even a datetime NaT
1299- if _checknull_with_nat(val) or val is np_NaT :
1302+ if _checknull_with_nat(val):
13001303 oresult[i] = np.nan
13011304 elif util.is_datetime64_object(val):
1302- oresult[i] = val.item()
1305+ if val == np_NaT:
1306+ oresult[i] = np.nan
1307+ else :
1308+ oresult[i] = val.item()
13031309 else :
13041310 oresult[i] = val
13051311 return oresult
0 commit comments