diff options
Diffstat (limited to 'numpy')
-rw-r--r-- | numpy/core/src/multiarray/methods.c | 4 | ||||
-rw-r--r-- | numpy/core/tests/test_regression.py | 8 |
2 files changed, 10 insertions, 2 deletions
diff --git a/numpy/core/src/multiarray/methods.c b/numpy/core/src/multiarray/methods.c index c4147eff2..119056c56 100644 --- a/numpy/core/src/multiarray/methods.c +++ b/numpy/core/src/multiarray/methods.c @@ -1587,8 +1587,8 @@ array_setstate(PyArrayObject *self, PyObject *args) /* Check that the string is not interned */ if (!_IsAligned(self) || swap || PyString_CHECK_INTERNED(rawdata)) { #else - /* Bytes are never interned */ - if (!_IsAligned(self) || swap) { + /* Bytes must always be considered immutable */ + if (1) { #endif npy_intp num = PyArray_NBYTES(self); fa->data = PyDataMem_NEW(num); diff --git a/numpy/core/tests/test_regression.py b/numpy/core/tests/test_regression.py index ac36aa479..492a4f64b 100644 --- a/numpy/core/tests/test_regression.py +++ b/numpy/core/tests/test_regression.py @@ -1601,6 +1601,14 @@ class TestRegression(TestCase): s = re.sub("a(.)", "\x01\\1", "a_") assert_equal(s[0], "\x01") + def test_pickle_bytes_overwrite(self): + if sys.version_info[0] >= 3: + data = np.array([1], dtype='b') + data = pickle.loads(pickle.dumps(data)) + data[0] = 0xdd + bytestring = "\x01 ".encode('ascii') + assert_equal(bytestring[0:1], '\x01'.encode('ascii')) + def test_structured_type_to_object(self): a_rec = np.array([(0,1), (3,2)], dtype='i4,i8') a_obj = np.empty((2,), dtype=object) |