From f40831a53ff2d572f338b1445e40bc88a1167ce7 Mon Sep 17 00:00:00 2001 From: Sebastian Berg Date: Sun, 26 Jan 2014 17:16:10 +0100 Subject: 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. --- numpy/core/src/umath/loops.c.src | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) (limited to 'numpy/core/src') 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; } } -- cgit v1.2.1