summaryrefslogtreecommitdiff
path: root/numpy/core
diff options
context:
space:
mode:
authorjbrockmendel <jbrockmendel@gmail.com>2023-02-13 10:57:28 -0800
committerGitHub <noreply@github.com>2023-02-13 19:57:28 +0100
commit80d5aeb986a885b8cc43b27839477a15677bcac8 (patch)
treeaceecbf3d1afb7c5fb019be5df890e1732414d90 /numpy/core
parent829a43f044528389de4a80438aa419a283d435cb (diff)
downloadnumpy-80d5aeb986a885b8cc43b27839477a15677bcac8.tar.gz
BUG: datetime64/timedelta64 comparisons return NotImplemented (#23201)
* BUG: datetime64/timedelta64 comparisons return NotImplemented * typo fixup * Update numpy/core/src/multiarray/scalartypes.c.src Co-authored-by: Sebastian Berg <sebastian@sipsolutions.net> * Update numpy/core/src/multiarray/scalartypes.c.src --------- Co-authored-by: Sebastian Berg <sebastian@sipsolutions.net>
Diffstat (limited to 'numpy/core')
-rw-r--r--numpy/core/src/multiarray/scalartypes.c.src2
-rw-r--r--numpy/core/tests/test_datetime.py20
2 files changed, 22 insertions, 0 deletions
diff --git a/numpy/core/src/multiarray/scalartypes.c.src b/numpy/core/src/multiarray/scalartypes.c.src
index bddfbf536..17163ef09 100644
--- a/numpy/core/src/multiarray/scalartypes.c.src
+++ b/numpy/core/src/multiarray/scalartypes.c.src
@@ -1078,6 +1078,8 @@ gentype_richcompare(PyObject *self, PyObject *other, int cmp_op)
}
}
+ RICHCMP_GIVE_UP_IF_NEEDED(self, other);
+
arr = PyArray_FromScalar(self, NULL);
if (arr == NULL) {
return NULL;
diff --git a/numpy/core/tests/test_datetime.py b/numpy/core/tests/test_datetime.py
index 948911f1c..2b56d4824 100644
--- a/numpy/core/tests/test_datetime.py
+++ b/numpy/core/tests/test_datetime.py
@@ -2529,3 +2529,23 @@ class TestDateTimeData:
dt = np.datetime64('2000', '5μs')
assert np.datetime_data(dt.dtype) == ('us', 5)
+
+
+def test_comparisons_return_not_implemented():
+ # GH#17017
+
+ class custom:
+ __array_priority__ = 10000
+
+ obj = custom()
+
+ dt = np.datetime64('2000', 'ns')
+ td = dt - dt
+
+ for item in [dt, td]:
+ assert item.__eq__(obj) is NotImplemented
+ assert item.__ne__(obj) is NotImplemented
+ assert item.__le__(obj) is NotImplemented
+ assert item.__lt__(obj) is NotImplemented
+ assert item.__ge__(obj) is NotImplemented
+ assert item.__gt__(obj) is NotImplemented