summaryrefslogtreecommitdiff
path: root/numpy/core/shape_base.py
diff options
context:
space:
mode:
authorMark Harfouche <mark.harfouche@gmail.com>2018-09-18 12:46:57 -0400
committerMark Harfouche <mark.harfouche@gmail.com>2018-09-19 11:44:35 -0400
commit2beafe73822cd6b47b4138ab83359585e0caa6b8 (patch)
tree4ccaedd1caf7a2d26ef1f3f8ba7ed2793ce1988b /numpy/core/shape_base.py
parent7fcba417b106d49efa93f0306dd508487929bf42 (diff)
downloadnumpy-2beafe73822cd6b47b4138ab83359585e0caa6b8.tar.gz
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
Diffstat (limited to 'numpy/core/shape_base.py')
-rw-r--r--numpy/core/shape_base.py9
1 files changed, 8 insertions, 1 deletions
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