Skip to content

Commit d522415

Browse files
committed
COMPAT: make numpy NaT comparison use a view to avoid implicit conversions
1 parent 08ae4f7 commit d522415

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

pandas/tslib.pyx

+3-3
Original file line numberDiff line numberDiff line change
@@ -892,7 +892,7 @@ 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-
if ts == np_NaT:
895+
if ts.view('i8') == iNaT:
896896
obj.value = NPY_NAT
897897
else:
898898
obj.value = _get_datetime64_nanos(ts)
@@ -1222,7 +1222,7 @@ def array_to_datetime(ndarray[object] values, raise_=False, dayfirst=False,
12221222
continue
12231223
raise
12241224
elif util.is_datetime64_object(val):
1225-
if val == np_NaT or val.view('i8') == iNaT:
1225+
if val is np_NaT or val.view('i8') == iNaT:
12261226
iresult[i] = iNaT
12271227
else:
12281228
try:
@@ -1303,7 +1303,7 @@ def array_to_datetime(ndarray[object] values, raise_=False, dayfirst=False,
13031303
if _checknull_with_nat(val):
13041304
oresult[i] = np.nan
13051305
elif util.is_datetime64_object(val):
1306-
if val == np_NaT:
1306+
if val is np_NaT or val.view('i8') == iNaT:
13071307
oresult[i] = np.nan
13081308
else:
13091309
oresult[i] = val.item()

0 commit comments

Comments
 (0)