diff options
-rw-r--r-- | numpy/core/src/multiarray/ctors.c | 2 | ||||
-rw-r--r-- | numpy/core/src/multiarray/methods.c | 2 | ||||
-rw-r--r-- | numpy/core/tests/test_regression.py | 12 | ||||
-rw-r--r-- | numpy/lib/utils.py | 5 |
4 files changed, 17 insertions, 4 deletions
diff --git a/numpy/core/src/multiarray/ctors.c b/numpy/core/src/multiarray/ctors.c index 066cfe251..5bdd5b552 100644 --- a/numpy/core/src/multiarray/ctors.c +++ b/numpy/core/src/multiarray/ctors.c @@ -1385,7 +1385,7 @@ fail: * npy_intp dims[NPY_MAXDIMS]; * * if (PyArray_GetArrayParamsFromObject(op, NULL, 1, &dtype, - * &ndim, &dims, &arr, NULL) < 0) { + * &ndim, dims, &arr, NULL) < 0) { * return NULL; * } * if (arr == NULL) { diff --git a/numpy/core/src/multiarray/methods.c b/numpy/core/src/multiarray/methods.c index bb4f34247..66d68e5b3 100644 --- a/numpy/core/src/multiarray/methods.c +++ b/numpy/core/src/multiarray/methods.c @@ -1457,7 +1457,7 @@ array_deepcopy(PyArrayObject *self, PyObject *args) Py_DECREF(deepcopy); Py_DECREF(it); } - return PyArray_Return(ret); + return ret; } /* Convert Array to flat list (using getitem) */ diff --git a/numpy/core/tests/test_regression.py b/numpy/core/tests/test_regression.py index 05336ac20..7a295d79c 100644 --- a/numpy/core/tests/test_regression.py +++ b/numpy/core/tests/test_regression.py @@ -1,5 +1,6 @@ from __future__ import division, absolute_import, print_function +import copy import pickle import sys import platform @@ -1952,6 +1953,17 @@ class TestRegression(TestCase): formatted = '{0}'.format(arr[0]) assert_equal(formatted, str(arr[0])) + def test_deepcopy_on_0d_array(self): + # Ticket #3311. + arr = np.array(3) + arr_cp = copy.deepcopy(arr) + + assert_equal(arr, arr_cp) + assert_equal(arr.shape, arr_cp.shape) + assert_equal(int(arr), int(arr_cp)) + self.assertTrue(arr is not arr_cp) + self.assertTrue(isinstance(arr_cp, type(arr))) + if __name__ == "__main__": run_module_suite() diff --git a/numpy/lib/utils.py b/numpy/lib/utils.py index 1f1cdfc8a..791f271b1 100644 --- a/numpy/lib/utils.py +++ b/numpy/lib/utils.py @@ -210,8 +210,9 @@ def byte_bounds(a): a_data = ai['data'][0] astrides = ai['strides'] ashape = ai['shape'] - bytes_a = int(ai['typestr'][2:]) - + + bytes_a = asarray(a).dtype.itemsize + a_low = a_high = a_data if astrides is None: # contiguous case a_high += a.size * bytes_a |