summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAllan Haldane <allan.haldane@gmail.com>2019-08-31 15:30:32 -0400
committerAllan Haldane <allan.haldane@gmail.com>2019-08-31 17:16:56 -0400
commit7c3adfb7436a37d995721f1c793e5e3ced6d9b7e (patch)
tree97aa8d8d41692111e73ad82baa20d5122d84dace
parent9b740ef1f7ccb8f5e0b5d018eb5fa4c26c7f0712 (diff)
downloadnumpy-7c3adfb7436a37d995721f1c793e5e3ced6d9b7e.tar.gz
BUG: Fix comparison of fieldless structured arrays
-rw-r--r--doc/source/reference/c-api/array.rst3
-rw-r--r--numpy/core/src/multiarray/arrayobject.c12
-rw-r--r--numpy/core/tests/test_dtype.py6
3 files changed, 16 insertions, 5 deletions
diff --git a/doc/source/reference/c-api/array.rst b/doc/source/reference/c-api/array.rst
index a2b56cee7..215584b62 100644
--- a/doc/source/reference/c-api/array.rst
+++ b/doc/source/reference/c-api/array.rst
@@ -997,6 +997,9 @@ argument must be a :c:type:`PyObject *<PyObject>` that can be directly interpret
called on flexible dtypes. Types that are attached to an array will always
be sized, hence the array form of this macro not existing.
+ ..versionchanged:: 1.18.0
+ For structured datatypes with no fields this function now return False.
+
.. c:function:: PyTypeNum_ISUSERDEF(num)
.. c:function:: PyDataType_ISUSERDEF(descr)
diff --git a/numpy/core/src/multiarray/arrayobject.c b/numpy/core/src/multiarray/arrayobject.c
index 4676c40d5..05e1d3011 100644
--- a/numpy/core/src/multiarray/arrayobject.c
+++ b/numpy/core/src/multiarray/arrayobject.c
@@ -1201,15 +1201,17 @@ _void_compare(PyArrayObject *self, PyArrayObject *other, int cmp_op)
}
if (res == NULL && !PyErr_Occurred()) {
/* these dtypes had no fields */
- return cmp_op == Py_EQ ? Py_True : Py_False;
+ res = PyArray_NewLikeArray(self, NPY_ANYORDER,
+ PyArray_DescrFromType(NPY_BOOL), 1);
+ if (res) {
+ PyArray_FILLWBYTE((PyArrayObject*)res,
+ cmp_op == Py_EQ ? 1 : 0);
+ }
}
return res;
}
else {
- /*
- * compare as a string. Assumes self and
- * other have same descr->type
- */
+ /* compare as a string. Assumes self and other have same descr->type */
return _strings_richcompare(self, other, cmp_op, 0);
}
}
diff --git a/numpy/core/tests/test_dtype.py b/numpy/core/tests/test_dtype.py
index 14c1857b4..6230b27b7 100644
--- a/numpy/core/tests/test_dtype.py
+++ b/numpy/core/tests/test_dtype.py
@@ -438,6 +438,12 @@ class TestRecord(object):
assert_raises(ValueError, np.dtype, ([], 'f8'))
assert_raises(ValueError, np.zeros(1, dtype='i4').view, [])
+ assert_equal(np.zeros(2, dtype=[]) == np.zeros(2, dtype=[]),
+ np.ones(2, dtype=bool))
+
+ assert_equal(np.zeros(2, dtype=[]) == a,
+ np.ones(2, dtype=bool))
+
class TestSubarray(object):
def test_single_subarray(self):