Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: Fix NaT handling in the PyArray_CompareFunc for datetime and timedelta #19607

Merged
merged 3 commits into from Aug 3, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
43 changes: 39 additions & 4 deletions numpy/core/src/multiarray/arraytypes.c.src
Expand Up @@ -2805,11 +2805,9 @@ BOOL_compare(npy_bool *ip1, npy_bool *ip2, PyArrayObject *NPY_UNUSED(ap))

/**begin repeat
* #TYPE = BYTE, UBYTE, SHORT, USHORT, INT, UINT,
* LONG, ULONG, LONGLONG, ULONGLONG,
* DATETIME, TIMEDELTA#
* LONG, ULONG, LONGLONG, ULONGLONG#
* #type = npy_byte, npy_ubyte, npy_short, npy_ushort, npy_int, npy_uint,
* npy_long, npy_ulong, npy_longlong, npy_ulonglong,
* npy_datetime, npy_timedelta#
* npy_long, npy_ulong, npy_longlong, npy_ulonglong#
*/

static int
Expand Down Expand Up @@ -2920,6 +2918,43 @@ C@TYPE@_compare(@type@ *pa, @type@ *pb)

/**end repeat**/

/**begin repeat
* #TYPE = DATETIME, TIMEDELTA#
* #type = npy_datetime, npy_timedelta#
*/

#define LT(a,b) ((a) < (b) || ((b) != (b) && (a) ==(a)))
asmeurer marked this conversation as resolved.
Show resolved Hide resolved

static int
@TYPE@_compare(@type@ *pa, @type@ *pb)
{
const @type@ a = *pa;
const @type@ b = *pb;
int ret;

printf("Calling @TYPE@_compare\n");
if (a == NPY_DATETIME_NAT) {
ret = 1;
asmeurer marked this conversation as resolved.
Show resolved Hide resolved
}
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;
}
return ret;
}

#undef LT

/**end repeat**/

static int
HALF_compare (npy_half *pa, npy_half *pb, PyArrayObject *NPY_UNUSED(ap))
{
Expand Down