8000 Merge pull request #5720 from cowlicks/backport-3926 · numpy/numpy@54e3834 · GitHub
[go: up one dir, main page]

Skip to content

Commit 54e3834

Browse files
committed
Merge pull request #5720 from cowlicks/backport-3926
backport #5475
2 parents 762c6f1 + 9a0d851 commit 54e3834

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

numpy/core/src/multiarray/multiarraymodule.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1843,11 +1843,6 @@ array_scalar(PyObject *NPY_UNUSED(ignored), PyObject *args, PyObject *kwds)
18431843
&PyArrayDescr_Type, &typecode, &obj)) {
18441844
return NULL;
18451845
}
1846-
if (typecode->elsize == 0) {
1847-
PyErr_SetString(PyExc_ValueError,
1848-
"itemsize cannot be zero");
1849-
return NULL;
1850-
}
18511846

18521847
if (PyDataType_FLAGCHK(typecode, NPY_ITEM_IS_POINTER)) {
18531848
if (obj == NULL) {
@@ -1857,6 +1852,9 @@ array_scalar(PyObject *NPY_UNUSED(ignored), PyObject *args, PyObject *kwds)
18571852
}
18581853
else {
18591854
if (obj == NULL) {
1855+
if (typecode->elsize == 0) {
1856+
typecode->elsize = 1;
1857+
}
18601858
dptr = PyArray_malloc(typecode->elsize);
18611859
if (dptr == NULL) {
18621860
return PyErr_NoMemory();

numpy/core/tests/test_regression.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2103,6 +2103,13 @@ def __eq__(self, other):
21032103
assert_equal(np.int32(10) == x, "OK")
21042104
assert_equal(np.array([10]) == x, "OK")
21052105

2106+
def test_pickle_empty_string(self):
2107+
# gh-3926
2108+
2109+
import pickle
2110+
test_string = np.string_('')
2111+
assert_equal(pickle.loads(pickle.dumps(test_string)), test_string)
2112+
21062113

21072114
if __name__ == "__main__":
21082115
run_module_suite()

0 commit comments

Comments
 (0)
0