diff options
-rw-r--r-- | doc/source/reference/c-api/array.rst | 3 | ||||
-rw-r--r-- | numpy/core/src/multiarray/arrayobject.c | 12 | ||||
-rw-r--r-- | numpy/core/tests/test_dtype.py | 6 |
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): |