diff options
author | Sebastian Berg <sebastian@sipsolutions.net> | 2014-01-26 01:55:06 +0100 |
---|---|---|
committer | Sebastian Berg <sebastian@sipsolutions.net> | 2014-05-04 18:14:11 +0200 |
commit | 17e9ff8fd67f41f0328b3963d46bbbe849bf7fbb (patch) | |
tree | e2282c0e5e8453b05666f26c1b2f44d1234cdda7 /numpy | |
parent | ad0b9753c063cad065882eb8b6b80f8f99afc47f (diff) | |
download | numpy-17e9ff8fd67f41f0328b3963d46bbbe849bf7fbb.tar.gz |
DEP: Deprecate identity check in comparisons (not just removing)
Instead of just removing it, raise Deprecation/Future warnings
when the comparison object ufunc and the identity check do not
coincide.
Diffstat (limited to 'numpy')
-rw-r--r-- | numpy/core/src/umath/loops.c.src | 39 |
1 files changed, 36 insertions, 3 deletions
diff --git a/numpy/core/src/umath/loops.c.src b/numpy/core/src/umath/loops.c.src index c1e2dc1c5..c3abd02f8 100644 --- a/numpy/core/src/umath/loops.c.src +++ b/numpy/core/src/umath/loops.c.src @@ -2562,27 +2562,60 @@ 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# */ NPY_NO_EXPORT void OBJECT_@kind@(char **args, npy_intp *dimensions, npy_intp *steps, void *NPY_UNUSED(func)) { BINARY_LOOP { 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. */ - PyObject *ret_obj = PyObject_RichCompare( - in1 ? in1 : Py_None, - in2 ? in2 : Py_None, Py_@OP@); + PyObject *ret_obj = PyObject_RichCompare(in1, in2, Py_@OP@); if (ret_obj == NULL) { + if (in1 == in2) { + PyErr_Clear(); + if (DEPRECATE("numpy @kind@ will not check object identity " + "in the future. The comparison error will " + "be raised.") < 0) { + return; + } + *((npy_bool *)op1) = @identity@; + continue; + } return; } int ret = PyObject_IsTrue(ret_obj); if (ret == -1) { + if (in1 == in2) { + PyErr_Clear(); + if (DEPRECATE("numpy @kind@ will not check object identity " + "in the future. The error trying to get the " + "boolean value of the comparison result will " + "be raised.") < 0) { + return; + } + *((npy_bool *)op1) = @identity@; + continue; + } return; } + 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 " + "and will change.") < 0) { + return; + } + *((npy_bool *)op1) = @identity@; + continue; + } *((npy_bool *)op1) = (npy_bool)ret; } } |