Skip to content

Commit c8fc0e8

Browse files
committed
Fix the implementation of DATETIME_compare
I accidentally based it off the float compare template instead of the integer compare template. It also now properly handles the case when both arguments are NaT.
1 parent 1d0dda1 commit c8fc0e8

1 file changed

Lines changed: 7 additions & 12 deletions

File tree

‎numpy/core/src/multiarray/arraytypes.c.src‎

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2923,8 +2923,6 @@ C@TYPE@_compare(@type@ *pa, @type@ *pb)
29232923
* #type = npy_datetime, npy_timedelta#
29242924
*/
29252925

2926-
#define LT(a,b) ((a) < (b) || ((b) != (b) && (a) ==(a)))
2927-
29282926
static int
29292927
@TYPE@_compare(@type@ *pa, @type@ *pb)
29302928
{
@@ -2933,25 +2931,22 @@ static int
29332931
int ret;
29342932

29352933
if (a == NPY_DATETIME_NAT) {
2936-
ret = 1;
2934+
if (b == NPY_DATETIME_NAT) {
2935+
ret = 0;
2936+
}
2937+
else {
2938+
ret = 1;
2939+
}
29372940
}
29382941
else if (b == NPY_DATETIME_NAT) {
29392942
ret = -1;
29402943
}
2941-
else if (LT(a,b)) {
2942-
ret = -1;
2943-
}
2944-
else if (LT(b,a)) {
2945-
ret = 1;
2946-
}
29472944
else {
2948-
ret = 0;
2945+
ret = a < b ? -1 : a == b ? 0 : 1;
29492946
}
29502947
return ret;
29512948
}
29522949

2953-
#undef LT
2954-
29552950
/**end repeat**/
29562951

29572952
static int

0 commit comments

Comments
 (0)