diff options
-rw-r--r-- | doc/release/upcoming_changes/14393.c_api.rst | 5 | ||||
-rw-r--r-- | doc/source/reference/c-api/array.rst | 5 | ||||
-rw-r--r-- | numpy/core/src/multiarray/arrayobject.c | 18 | ||||
-rw-r--r-- | numpy/core/tests/test_dtype.py | 4 |
4 files changed, 24 insertions, 8 deletions
diff --git a/doc/release/upcoming_changes/14393.c_api.rst b/doc/release/upcoming_changes/14393.c_api.rst new file mode 100644 index 000000000..0afd27584 --- /dev/null +++ b/doc/release/upcoming_changes/14393.c_api.rst @@ -0,0 +1,5 @@ +PyDataType_ISUNSIZED(descr) now returns False for structured datatypes +---------------------------------------------------------------------- +Previously this returned True for any datatype of itemsize 0, but now this +returns false for the non-flexible datatype with itemsize 0, ``np.dtype([])``. + diff --git a/doc/source/reference/c-api/array.rst b/doc/source/reference/c-api/array.rst index 215584b62..8936a4752 100644 --- a/doc/source/reference/c-api/array.rst +++ b/doc/source/reference/c-api/array.rst @@ -997,8 +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. + .. versionchanged:: 1.18 + + For structured datatypes with no fields this function now returns False. .. c:function:: PyTypeNum_ISUSERDEF(num) diff --git a/numpy/core/src/multiarray/arrayobject.c b/numpy/core/src/multiarray/arrayobject.c index 05e1d3011..074496dee 100644 --- a/numpy/core/src/multiarray/arrayobject.c +++ b/numpy/core/src/multiarray/arrayobject.c @@ -1200,11 +1200,21 @@ _void_compare(PyArrayObject *self, PyArrayObject *other, int cmp_op) } } if (res == NULL && !PyErr_Occurred()) { - /* these dtypes had no fields */ - res = PyArray_NewLikeArray(self, NPY_ANYORDER, - PyArray_DescrFromType(NPY_BOOL), 1); + /* these dtypes had no fields. Use a MultiIter to broadcast them + * to an output array, and fill with True (for EQ)*/ + PyArrayMultiIterObject *mit = (PyArrayMultiIterObject *) + PyArray_MultiIterNew(2, self, other); + if (mit == NULL) { + return NULL; + } + + res = PyArray_NewFromDescr(&PyArray_Type, + PyArray_DescrFromType(NPY_BOOL), + mit->nd, mit->dimensions, + NULL, NULL, 0, NULL); + Py_DECREF(mit); if (res) { - PyArray_FILLWBYTE((PyArrayObject*)res, + PyArray_FILLWBYTE((PyArrayObject *)res, cmp_op == Py_EQ ? 1 : 0); } } diff --git a/numpy/core/tests/test_dtype.py b/numpy/core/tests/test_dtype.py index 6230b27b7..f5ca775ef 100644 --- a/numpy/core/tests/test_dtype.py +++ b/numpy/core/tests/test_dtype.py @@ -441,8 +441,8 @@ class TestRecord(object): 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)) + assert_equal(np.zeros((1, 2), dtype=[]) == a, + np.ones((1, 2), dtype=bool)) class TestSubarray(object): |