Skip to content

Commit

Permalink
Merge pull request #8971 from juliantaylor/uninitialized-empty
Browse files Browse the repository at this point in the history
BUG: do not change size 0 description when viewing data
  • Loading branch information
charris committed Apr 23, 2017
2 parents 704c9cc + 6373dc0 commit 4408f74
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
4 changes: 3 additions & 1 deletion numpy/core/src/multiarray/ctors.c
Expand Up @@ -937,7 +937,9 @@ PyArray_NewFromDescr_int(PyTypeObject *subtype, PyArray_Descr *descr, int nd,
PyErr_SetString(PyExc_TypeError, "Empty data-type");
Py_DECREF(descr);
return NULL;
} else if (PyDataType_ISSTRING(descr) && !allow_emptystring) {
}
else if (PyDataType_ISSTRING(descr) && !allow_emptystring &&
data == NULL) {
PyArray_DESCR_REPLACE(descr);
if (descr == NULL) {
return NULL;
Expand Down
3 changes: 3 additions & 0 deletions numpy/core/tests/test_multiarray.py
Expand Up @@ -1073,6 +1073,9 @@ def test_zero_width_string(self):
xx = x['S'].reshape((2, 2))
assert_equal(xx.itemsize, 0)
assert_equal(xx, [[b'', b''], [b'', b'']])
# check for no uninitialized memory due to viewing S0 array
assert_equal(xx[:].dtype, xx.dtype)
assert_array_equal(eval(repr(xx), dict(array=np.array)), xx)

b = io.BytesIO()
np.save(b, xx)
Expand Down

0 comments on commit 4408f74

Please sign in to comment.