summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authorJulian Taylor <jtaylor.debian@googlemail.com>2014-07-28 21:08:21 +0200
committerJulian Taylor <jtaylor.debian@googlemail.com>2014-07-28 21:08:21 +0200
commit84a9ab0136ed49dac1d43cb7319497861919e0a9 (patch)
tree61fb4377740d21a26abbeaac9e8ba1ea6b05f8d4 /numpy
parentbc4a583d19fc694659d33c59e16b4cedd6307432 (diff)
parent8624924833603fa6c6410d68c778481dbb5c29d7 (diff)
downloadnumpy-84a9ab0136ed49dac1d43cb7319497861919e0a9.tar.gz
Merge pull request #4910 from seberg/scalar-none-cmp
BUG: None comparison deprecation does not affect scalars
Diffstat (limited to 'numpy')
-rw-r--r--numpy/core/src/multiarray/scalartypes.c.src18
-rw-r--r--numpy/core/tests/test_deprecations.py22
2 files changed, 39 insertions, 1 deletions
diff --git a/numpy/core/src/multiarray/scalartypes.c.src b/numpy/core/src/multiarray/scalartypes.c.src
index 110bef248..4fa634098 100644
--- a/numpy/core/src/multiarray/scalartypes.c.src
+++ b/numpy/core/src/multiarray/scalartypes.c.src
@@ -1078,6 +1078,24 @@ gentype_richcompare(PyObject *self, PyObject *other, int cmp_op)
{
PyObject *arr, *ret;
+ /*
+ * If the other object is None, False is always right. This avoids
+ * the array None comparison, at least until deprecation it is fixed.
+ * After that, this may be removed and numpy false would be returned.
+ *
+ * NOTE: np.equal(NaT, None) evaluates to TRUE! This is an
+ * an inconsistency, which may has to be considered
+ * when the deprecation is finished.
+ */
+ if (other == Py_None) {
+ if (cmp_op == Py_EQ) {
+ Py_RETURN_FALSE;
+ }
+ if (cmp_op == Py_NE) {
+ Py_RETURN_TRUE;
+ }
+ }
+
arr = PyArray_FromScalar(self, NULL);
if (arr == NULL) {
return NULL;
diff --git a/numpy/core/tests/test_deprecations.py b/numpy/core/tests/test_deprecations.py
index 1c11abb91..ef56766f5 100644
--- a/numpy/core/tests/test_deprecations.py
+++ b/numpy/core/tests/test_deprecations.py
@@ -12,7 +12,7 @@ from nose.plugins.skip import SkipTest
import numpy as np
from numpy.testing import (dec, run_module_suite, assert_raises,
- assert_warns, assert_array_equal)
+ assert_warns, assert_array_equal, assert_)
class _DeprecationTestCase(object):
@@ -434,6 +434,26 @@ class TestComparisonDepreactions(_DeprecationTestCase):
assert_raises(FutureWarning, operator.eq, np.arange(3), None)
assert_raises(FutureWarning, operator.ne, np.arange(3), None)
+ def test_scalar_none_comparison(self):
+ # Scalars should still just return false and not give a warnings.
+ with warnings.catch_warnings(record=True) as w:
+ warnings.filterwarnings('always', '', FutureWarning)
+ assert_(not np.float32(1) == None)
+ assert_(not np.str_('test') == None)
+ # This is dubious (see below):
+ assert_(not np.datetime64('NaT') == None)
+
+ assert_(np.float32(1) != None)
+ assert_(np.str_('test') != None)
+ # This is dubious (see below):
+ assert_(np.datetime64('NaT') != None)
+ assert_(len(w) == 0)
+
+ # For documentaiton purpose, this is why the datetime is dubious.
+ # At the time of deprecation this was no behaviour change, but
+ # it has to be considered when the deprecations is done.
+ assert_(np.equal(np.datetime64('NaT'), None))
+
class TestIdentityComparisonDepreactions(_DeprecationTestCase):
"""This tests the equal and not_equal object ufuncs identity check