8000 backport #5475 by cowlicks · Pull Request #5720 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

backport #5475 #5720

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 25, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions numpy/core/src/multiarray/multiarraymodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -1843,11 +1843,6 @@ array_scalar(PyObject *NPY_UNUSED(ignored), PyObject *args, PyObject *kwds)
&PyArrayDescr_Type, &typecode, &obj)) {
return NULL;
}
if (typecode->elsize == 0) {
PyErr_SetString(PyExc_ValueError,
"itemsize cannot be zero");
return NULL;
}

if (PyDataType_FLAGCHK(typecode, NPY_ITEM_IS_POINTER)) {
if (obj == NULL) {
Expand All @@ -1857,6 +1852,9 @@ array_scalar(PyObject *NPY_UNUSED(ignored), PyObject *args, PyObject *kwds)
}
else {
if (obj == NULL) {
if (typecode->elsize == 0) {
typecode->elsize = 1;
}
dptr = PyArray_malloc(typecode->elsize);
if (dptr == NULL) {
return PyErr_NoMemory();
Expand Down
7 changes: 7 additions & 0 deletions numpy/core/tests/test_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -2103,6 +2103,13 @@ def __eq__(self, other):
assert_equal(np.int32(10) == x, "OK")
assert_equal(np.array([10]) == x, "OK")

def test_pickle_empty_string(self):
# gh-3926

import pickle
test_string = np.string_('')
assert_equal(pickle.loads(pickle.dumps(test_string)), test_string)


if __name__ == "__main__":
run_module_suite()
0