From d9dbff08983745189bec122ccc252e6e8ecffaac Mon Sep 17 00:00:00 2001 From: Mohit Deoli Date: Tue, 5 Aug 2025 01:12:23 +0530 Subject: [PATCH] BUG: add support for NaT (Not-a-Time) handling in nummpy.sign ufunc. --- numpy/_core/src/umath/loops.c.src | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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)); } }