diff options
-rw-r--r-- | numpy/core/src/multiarray/arraytypes.c.src | 2 | ||||
-rw-r--r-- | numpy/core/tests/test_dtype.py | 4 |
2 files changed, 5 insertions, 1 deletions
diff --git a/numpy/core/src/multiarray/arraytypes.c.src b/numpy/core/src/multiarray/arraytypes.c.src index 8e22afa31..ffd741dea 100644 --- a/numpy/core/src/multiarray/arraytypes.c.src +++ b/numpy/core/src/multiarray/arraytypes.c.src @@ -426,7 +426,7 @@ STRING_getitem(char *ip, PyArrayObject *ap) int size = PyArray_DESCR(ap)->elsize; ptr = ip + size - 1; - while (*ptr-- == '\0' && size > 0) { + while (size > 0 && *ptr-- == '\0') { size--; } return PyBytes_FromStringAndSize(ip,size); diff --git a/numpy/core/tests/test_dtype.py b/numpy/core/tests/test_dtype.py index 2e98b2cf8..18660351c 100644 --- a/numpy/core/tests/test_dtype.py +++ b/numpy/core/tests/test_dtype.py @@ -496,6 +496,10 @@ class TestString(TestCase): # Issue gh-2798 a = np.array(['a'], dtype="O").astype(("O", [("name", "O")])) + def test_empty_string_to_object(self): + # Pull request #4722 + np.array(["", ""]).astype(object) + class TestDtypeAttributeDeletion(object): def test_dtype_non_writable_attributes_deletion(self): |