diff options
author | Matti Picus <matti.picus@gmail.com> | 2018-10-09 13:31:20 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-09 13:31:20 +0300 |
commit | db5f9d3a61d639b4fdb95c161012678ea8847424 (patch) | |
tree | f57717d29b797fd9a8d44ecc9a0647bf2e4d5325 /numpy/core/shape_base.py | |
parent | 86a7acc8582923604fac849bb19f0b08efc0a91a (diff) | |
parent | 2beafe73822cd6b47b4138ab83359585e0caa6b8 (diff) | |
download | numpy-db5f9d3a61d639b4fdb95c161012678ea8847424.tar.gz |
Merge pull request #11979 from hmaarrfk/block_single_array_copy_test
MAINT: Ensure that a copy of the array is returned when calling `block`.
Diffstat (limited to 'numpy/core/shape_base.py')
-rw-r--r-- | numpy/core/shape_base.py | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/numpy/core/shape_base.py b/numpy/core/shape_base.py index 52717abda..feb1605bc 100644 --- a/numpy/core/shape_base.py +++ b/numpy/core/shape_base.py @@ -617,4 +617,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 |