You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
np.hstack([ ]) throws IndexError instead of ValueError #8790
Calling np.hstack([ ]) throws an IndexError. It takes a bit more work to find out the root cause of the error, ie: the empty list.
>>> import numpy as np
>>> np.hstack([ ])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3/dist-packages/numpy/core/shape_base.py", line 277, in hstack
if arrs[0].ndim == 1:
IndexError: list index out of range
np.vstack, on the other hand, throws a more appropriate error.
>>> np.vstack([ ])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3/dist-packages/numpy/core/shape_base.py", line 230, in vstack
return _nx.concatenate([atleast_2d(_m) for _m in tup], 0)
ValueError: need at least one array to concatenate
Activity
zixu-zhao commentedon Mar 20, 2017
I will take this. Thanks!
zixu-zhao commentedon Mar 20, 2017
@eric-wieser What error message would you prefer to use there?
How about
ValueError: need at least one element to concatenate?And if it is acceptable to add
if len(arrs) == 0: raise ValueError('need at least one element to concatenate')before the line if arrs[0].ndim == 1:?