Skip to content

Commit

Permalink
Fix the implementation of DATETIME_compare
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
asmeurer authored and charris committed Oct 10, 2021
1 parent 9416e59 commit 73e7a12
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions numpy/core/src/multiarray/arraytypes.c.src
Expand Up @@ -2923,8 +2923,6 @@ C@TYPE@_compare(@type@ *pa, @type@ *pb)
* #type = npy_datetime, npy_timedelta#
*/

#define LT(a,b) ((a) < (b) || ((b) != (b) && (a) ==(a)))

static int
@TYPE@_compare(@type@ *pa, @type@ *pb)
{
Expand All @@ -2933,25 +2931,22 @@ static int
int ret;

if (a == NPY_DATETIME_NAT) {
ret = 1;
if (b == NPY_DATETIME_NAT) {
ret = 0;
}
else {
ret = 1;
}
}
else if (b == NPY_DATETIME_NAT) {
ret = -1;
}
else if (LT(a,b)) {
ret = -1;
}
else if (LT(b,a)) {
ret = 1;
}
else {
ret = 0;
ret = a < b ? -1 : a == b ? 0 : 1;
}
return ret;
}

#undef LT

/**end repeat**/

static int
Expand Down

0 comments on commit 73e7a12

Please sign in to comment.