diff options
author | Sebastian Berg <sebastian@sipsolutions.net> | 2013-07-25 16:10:54 +0200 |
---|---|---|
committer | Sebastian Berg <sebastian@sipsolutions.net> | 2014-05-04 18:14:11 +0200 |
commit | 9b8f6c72caea0c6f3fa08b304135239636e4f165 (patch) | |
tree | b3418650ed740be1bb369f5ab2979749d4d27919 /numpy/core/src | |
parent | 84831ca7b7926bf1c73e1702201e7591c55588a3 (diff) | |
download | numpy-9b8f6c72caea0c6f3fa08b304135239636e4f165.tar.gz |
DEP: Deprecate that comparisons ignore errors.
This means that for example broadcasting errors get raised.
The array_equiv function is changed to explicitely test
if broadcasting is possible. It may be nice to do this
test differently, but I am not sure if that is possible.
Create a FutureWarning for comparisons to None, which
should result in areal elementwise (object) comparisons.
Slightly adepted a wrong test.
Poly changes: Some changes in the polycode was necessary,
the one is probably a bug fix, the other needs to be
thought over, since len check is not perfect maybe, since
it is more liekly to raise raise an error.
Closes gh-3759 and gh-1608
Diffstat (limited to 'numpy/core/src')
-rw-r--r-- | numpy/core/src/multiarray/arrayobject.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/numpy/core/src/multiarray/arrayobject.c b/numpy/core/src/multiarray/arrayobject.c index a09e0e3b9..cd0912510 100644 --- a/numpy/core/src/multiarray/arrayobject.c +++ b/numpy/core/src/multiarray/arrayobject.c @@ -1292,6 +1292,10 @@ array_richcompare(PyArrayObject *self, PyObject *other, int cmp_op) break; case Py_EQ: if (other == Py_None) { + if (DEPRECATE_FUTUREWARNING("comparison to `None` will result in " + "an elementwise object comparison in the future.") < 0) { + return NULL; + } Py_INCREF(Py_False); return Py_False; } @@ -1347,13 +1351,26 @@ array_richcompare(PyArrayObject *self, PyObject *other, int cmp_op) * indicate that */ if (result == NULL) { + /* + * Comparisons should raise errors when element-wise comparison + * is not possible. + */ PyErr_Clear(); + if (DEPRECATE("elementwise comparison failed; " + "this will raise the error in the future.") < 0) { + return NULL; + } + Py_INCREF(Py_NotImplemented); return Py_NotImplemented; } break; case Py_NE: if (other == Py_None) { + if (DEPRECATE_FUTUREWARNING("comparison to `None` will result in " + "an elementwise object comparison in the future.") < 0) { + return NULL; + } Py_INCREF(Py_True); return Py_True; } @@ -1404,7 +1421,16 @@ array_richcompare(PyArrayObject *self, PyObject *other, int cmp_op) } if (result == NULL) { + /* + * Comparisons should raise errors when element-wise comparison + * is not possible. + */ PyErr_Clear(); + if (DEPRECATE("elementwise comparison failed; " + "this will raise the error in the future.") < 0) { + return NULL; + } + Py_INCREF(Py_NotImplemented); return Py_NotImplemented; } |