diff options
author | Jay Bourque <jay.bourque@continuum.io> | 2015-01-21 13:08:50 -0600 |
---|---|---|
committer | Jay Bourque <jay.bourque@continuum.io> | 2015-01-21 13:08:50 -0600 |
commit | c51770d6c553f9c69ceda324a2e7c7a249185366 (patch) | |
tree | 03088af2e9a71f029e106439594efc13adf4d7db /numpy | |
parent | 960433e8f5f39587d10c60ed1d3f50591434a82b (diff) | |
download | numpy-c51770d6c553f9c69ceda324a2e7c7a249185366.tar.gz |
BUG: Fix #3926: pickling empty string fails
Diffstat (limited to 'numpy')
-rw-r--r-- | numpy/core/src/multiarray/multiarraymodule.c | 8 | ||||
-rw-r--r-- | numpy/core/tests/test_regression.py | 7 |
2 files changed, 10 insertions, 5 deletions
diff --git a/numpy/core/src/multiarray/multiarraymodule.c b/numpy/core/src/multiarray/multiarraymodule.c index e6b317ed1..32b4f0555 100644 --- a/numpy/core/src/multiarray/multiarraymodule.c +++ b/numpy/core/src/multiarray/multiarraymodule.c @@ -1959,11 +1959,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) { @@ -1973,6 +1968,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(); diff --git a/numpy/core/tests/test_regression.py b/numpy/core/tests/test_regression.py index c7eaad984..431f80534 100644 --- a/numpy/core/tests/test_regression.py +++ b/numpy/core/tests/test_regression.py @@ -2103,6 +2103,13 @@ class TestRegression(TestCase): 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() |