From 2beafe73822cd6b47b4138ab83359585e0caa6b8 Mon Sep 17 00:00:00 2001 From: Mark Harfouche Date: Tue, 18 Sep 2018 12:46:57 -0400 Subject: MAINT: Ensure that block returns a new array In the case that a user calls np.block(array), the old block function would return a view into the array. This ensures that a new array is returned --- numpy/core/shape_base.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'numpy/core/shape_base.py') diff --git a/numpy/core/shape_base.py b/numpy/core/shape_base.py index 30919ed7e..d10bce608 100644 --- a/numpy/core/shape_base.py +++ b/numpy/core/shape_base.py @@ -620,4 +620,11 @@ def block(arrays): _block_format_index(bottom_index) ) ) - return _block(arrays, list_ndim, max(arr_ndim, list_ndim)) + result = _block(arrays, list_ndim, max(arr_ndim, list_ndim)) + if list_ndim == 0: + # Catch an edge case where _block returns a view because + # `arrays` is a single numpy array and not a list of numpy arrays. + # This might copy scalars or lists twice, but this isn't a likely + # usecase for those interested in performance + result = result.copy() + return result -- cgit v1.2.1