Skip to content

Commit

Permalink
improve informative error around columns
Browse files Browse the repository at this point in the history
  • Loading branch information
mrocklin committed Jul 6, 2015
1 parent 0ad5a04 commit 8ad9a4c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
3 changes: 2 additions & 1 deletion dask/dataframe/io.py
Expand Up @@ -495,7 +495,8 @@ def from_dask_array(x, columns=None):
if columns is None:
raise ValueError("Must provide columns for DataFrame")
if len(columns) != x.shape[1]:
raise ValueError("Columns must be the same length as array width")
raise ValueError("Columns must be the same length as array width\n"
" columns: %s\n width: %d" % (str(columns), x.shape[1]))
if len(x.chunks[1]) > 1:
x = x.rechunk({1: x.shape[1]})
dsk = dict(((name, i), (pd.DataFrame, chunk[0], ind, columns))
Expand Down
9 changes: 9 additions & 0 deletions dask/dataframe/tests/test_io.py
Expand Up @@ -361,3 +361,12 @@ def test_from_dask_array_raises():

x = da.ones((10, 3), chunks=(3, 3))
pytest.raises(ValueError, lambda: from_dask_array(x)) # no columns

# Not enough columns
pytest.raises(ValueError, lambda: from_dask_array(x, columns=['a']))

try:
from_dask_array(x, columns=['hello'])
except Exception as e:
assert 'hello' in str(e)
assert '3' in str(e)

0 comments on commit 8ad9a4c

Please sign in to comment.