Skip to content

Commit

Permalink
Raise ValueError if concatenate is given no arrays (dask#4927)
Browse files Browse the repository at this point in the history
* Raise `ValueError` if `concatenate` gets no arrays

NumPy will raise if no arrays are provided to concatenate as it is
unclear what to do. This adds a similar exception for Dask Arrays. Also
this short circuits handling unusual cases later. Plus raises a clearer
exception than one might see if this weren't raised.

* Test `concatenate` raises when no arrays are given
  • Loading branch information
jakirkham authored Jun 12, 2019
1 parent ce2f866 commit abc86d3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
4 changes: 4 additions & 0 deletions dask/array/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2982,6 +2982,10 @@ def concatenate(seq, axis=0, allow_unknown_chunksizes=False):
seq = [asarray(a) for a in seq]

n = len(seq)

if n == 0:
raise ValueError("Need array(s) to concatenate")

ndim = len(seq[0].shape)

if axis < 0:
Expand Down
1 change: 1 addition & 0 deletions dask/array/tests/test_array_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ def test_concatenate():
assert (concatenate([a, b, c], axis=-1).chunks ==
concatenate([a, b, c], axis=1).chunks)

pytest.raises(ValueError, lambda: concatenate([]))
pytest.raises(ValueError, lambda: concatenate([a, b, c], axis=2))


Expand Down

0 comments on commit abc86d3

Please sign in to comment.