diff --git a/numpy/_core/src/umath/loops.c.src b/numpy/_core/src/umath/loops.c.src index 3928d2a0d0c4..141676a8a768 100644 --- a/numpy/_core/src/umath/loops.c.src +++ b/numpy/_core/src/umath/loops.c.src @@ -687,8 +687,9 @@ NPY_NO_EXPORT void TIMEDELTA_sign(char **args, npy_intp const *dimensions, npy_intp const *steps, void *NPY_UNUSED(func)) { UNARY_LOOP { + /* Sign of NaT is NaT */ const npy_timedelta in1 = *(npy_timedelta *)ip1; - *((npy_timedelta *)op1) = in1 > 0 ? 1 : (in1 < 0 ? -1 : 0); + *((npy_timedelta *)op1) = in1 == NPY_DATETIME_NAT ? NPY_DATETIME_NAT : (in1 > 0 ? 1 : (in1 < 0 ? -1 : 0)); } }