summaryrefslogtreecommitdiff
path: root/numpy/core/src
diff options
context:
space:
mode:
authorSebastian Berg <sebastian@sipsolutions.net>2014-01-26 17:16:10 +0100
committerSebastian Berg <sebastian@sipsolutions.net>2014-05-04 21:06:17 +0200
commitf40831a53ff2d572f338b1445e40bc88a1167ce7 (patch)
tree3c48af9cc441a9c809d8ac995f659f391b81b6ce /numpy/core/src
parent17e9ff8fd67f41f0328b3963d46bbbe849bf7fbb (diff)
downloadnumpy-f40831a53ff2d572f338b1445e40bc88a1167ce7.tar.gz
MAINT: Comparison deprecation followup fixes
Makes the identity check `a = np.array([np.nan], dtype=object)` `a == a`, etc. a deprecation/futurewarning instead of just changing it. Also fixes some smaller things.
Diffstat (limited to 'numpy/core/src')
-rw-r--r--numpy/core/src/umath/loops.c.src25
1 files changed, 18 insertions, 7 deletions
diff --git a/numpy/core/src/umath/loops.c.src b/numpy/core/src/umath/loops.c.src
index c3abd02f8..d0374fc0a 100644
--- a/numpy/core/src/umath/loops.c.src
+++ b/numpy/core/src/umath/loops.c.src
@@ -2562,22 +2562,28 @@ NPY_NO_EXPORT void
/**begin repeat
* #kind = equal, not_equal, greater, greater_equal, less, less_equal#
* #OP = EQ, NE, GT, GE, LT, LE#
- * #identity = NPY_TRUE, NPY_FALSE, NPY_FALSE, NPY_TRUE, NPY_FALSE, NPY_TRUE#
+ * #identity = NPY_TRUE, NPY_FALSE, -1*4#
*/
NPY_NO_EXPORT void
OBJECT_@kind@(char **args, npy_intp *dimensions, npy_intp *steps, void *NPY_UNUSED(func)) {
BINARY_LOOP {
+ int ret;
+ PyObject *ret_obj;
PyObject *in1 = *(PyObject **)ip1;
PyObject *in2 = *(PyObject **)ip2;
+
in1 = in1 ? in1 : Py_None;
in2 = in2 ? in2 : Py_None;
+
/*
- * Do not use RichCompareBool because it includes an identity check.
- * But this is wrong for elementwise behaviour, since i.e. it says
- * that NaN can be equal to NaN, and an array is equal to itself.
+ * Do not use RichCompareBool because it includes an identity check
+ * (for == and !=).
+ * This is wrong for elementwise behaviour, since it means
+ * that NaN can be equal to NaN and an array is equal to itself.
*/
- PyObject *ret_obj = PyObject_RichCompare(in1, in2, Py_@OP@);
+ ret_obj = PyObject_RichCompare(in1, in2, Py_@OP@);
if (ret_obj == NULL) {
+#if @identity@ != -1
if (in1 == in2) {
PyErr_Clear();
if (DEPRECATE("numpy @kind@ will not check object identity "
@@ -2588,10 +2594,12 @@ OBJECT_@kind@(char **args, npy_intp *dimensions, npy_intp *steps, void *NPY_UNUS
*((npy_bool *)op1) = @identity@;
continue;
}
+#endif
return;
}
- int ret = PyObject_IsTrue(ret_obj);
+ ret = PyObject_IsTrue(ret_obj);
if (ret == -1) {
+#if @identity@ != -1
if (in1 == in2) {
PyErr_Clear();
if (DEPRECATE("numpy @kind@ will not check object identity "
@@ -2603,19 +2611,22 @@ OBJECT_@kind@(char **args, npy_intp *dimensions, npy_intp *steps, void *NPY_UNUS
*((npy_bool *)op1) = @identity@;
continue;
}
+#endif
return;
}
+#if @identity@ != -1
if ((in1 == in2) && ((npy_bool)ret != @identity@)) {
if (DEPRECATE_FUTUREWARNING(
"numpy @kind@ will not check object identity "
"in the future. The comparison did not return the "
- "same result as suggested by the identity "
+ "same result as suggested by the identity (`is`)) "
"and will change.") < 0) {
return;
}
*((npy_bool *)op1) = @identity@;
continue;
}
+#endif
*((npy_bool *)op1) = (npy_bool)ret;
}
}