@@ -67,7 +67,7 @@ cdef int64_t NPY_NAT = util.get_nat()
67
67
compat_NaT = np.array([NPY_NAT]).astype(' m8[ns]' ).item()
68
68
69
69
# numpy actual nat object
70
- np_NaT = np.datetime64(' NaT' , dtype = ' M8 ' )
70
+ np_NaT = np.datetime64(' NaT' )
71
71
72
72
try :
73
73
basestring
@@ -892,8 +892,11 @@ cdef convert_to_tsobject(object ts, object tz, object unit):
892
892
if ts is None or ts is NaT or ts is np_NaT:
893
893
obj.value = NPY_NAT
894
894
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)
897
900
elif is_integer_object(ts):
898
901
if ts == NPY_NAT:
899
902
obj.value = NPY_NAT
@@ -1218,7 +1221,7 @@ def array_to_datetime(ndarray[object] values, raise_=False, dayfirst=False,
1218
1221
continue
1219
1222
raise
1220
1223
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:
1222
1225
iresult[i] = iNaT
1223
1226
else :
1224
1227
try :
@@ -1296,10 +1299,13 @@ def array_to_datetime(ndarray[object] values, raise_=False, dayfirst=False,
1296
1299
val = values[i]
1297
1300
1298
1301
# 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):
1300
1303
oresult[i] = np.nan
1301
1304
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()
1303
1309
else :
1304
1310
oresult[i] = val
1305
1311
return oresult
0 commit comments