Skip to content

Commit 8d17eed

Browse files
committed
BUG: fix GH12941, Operations on NaT returning float instead of datetime64[ns]
1 parent a949cee commit 8d17eed

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

pandas/core/nanops.py

+9-4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
is_integer, is_complex, is_float_dtype,
1818
is_complex_dtype, is_integer_dtype,
1919
is_bool_dtype, is_object_dtype,
20+
is_numeric_dtype,
2021
is_datetime64_dtype, is_timedelta64_dtype,
2122
is_datetime_or_timedelta_dtype,
2223
is_int_or_datetime_dtype, is_any_int_dtype)
@@ -638,11 +639,15 @@ def _maybe_null_out(result, axis, mask):
638639
if axis is not None and getattr(result, 'ndim', False):
639640
null_mask = (mask.shape[axis] - mask.sum(axis)) == 0
640641
if np.any(null_mask):
641-
if np.iscomplexobj(result):
642-
result = result.astype('c16')
642+
if is_numeric_dtype(result):
643+
if np.iscomplexobj(result):
644+
result = result.astype('c16')
645+
else:
646+
result = result.astype('f8')
647+
result[null_mask] = np.nan
643648
else:
644-
result = result.astype('f8')
645-
result[null_mask] = np.nan
649+
# GH12941, use None to auto cast null
650+
result[null_mask] = None
646651
elif result is not tslib.NaT:
647652
null_mask = mask.size - mask.sum()
648653
if null_mask == 0:

0 commit comments

Comments
 (0)