Skip to content

Default chunks=None creates unusable array #415

Closed

Description

@JDWarner

When using dask[array], most commands to create array objects claim to require a chunks= kwarg in the docs. However, a dask array object is successfully created with the default chunks=None. Then it fails when .compute() is called, with a less than informative traceback.

Minimal example:

import dask.array as da

has_chunks = da.random.random(size=(100, 100), chunks=(100, 100))
no_chunks = da.random.random(size=(100, 100))  # chunks left at default (None), succeeds

has_chunks.mean(axis=0).compute()  # succeeds
no_chunks.mean(axis=0).compute()  # fails - traceback not particularly informative (see below)

Unless some future functionality is intended to automatically set chunks if chunks=None, I'd propose this workflow should fail earlier at the point chunks is not provided to be consistent with the docs. Alternatively, the error when .compute() is called on an array with chunks=None could be more informative.

Traceback:

---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-22-f80a4f9b0fcd> in <module>()
      1 nparr = np.random.random(size=(100, 100))
      2 darr = da.ones((100, 100))
----> 3 darr.mean(axis=0).compute()

/src/anaconda/lib/python2.7/site-packages/dask/array/core.pyc in compute(self, **kwargs)
    721     @wraps(compute)
    722     def compute(self, **kwargs):
--> 723         result, = compute(self, **kwargs)
    724         return result
    725 

/src/anaconda/lib/python2.7/site-packages/dask/array/core.pyc in compute(*args, **kwargs)
    514 
    515     results2 = tuple(concatenate3(x) if arg.shape else unpack_singleton(x)
--> 516                      for x, arg in zip(results, args))
    517     return results2
    518 

/src/anaconda/lib/python2.7/site-packages/dask/array/core.pyc in <genexpr>((x, arg))
    514 
    515     results2 = tuple(concatenate3(x) if arg.shape else unpack_singleton(x)
--> 516                      for x, arg in zip(results, args))
    517     return results2
    518 

/src/anaconda/lib/python2.7/site-packages/dask/array/core.pyc in concatenate3(arrays)
   2035     """
   2036     arrays = concrete(arrays)
-> 2037     ndim = ndimlist(arrays)
   2038     if not ndim:
   2039         return arrays

/src/anaconda/lib/python2.7/site-packages/dask/array/core.pyc in ndimlist(seq)
   2014         return 0
   2015     else:
-> 2016         return 1 + ndimlist(seq[0])
   2017 
   2018 

IndexError: list index out of range

Activity

  1. mrocklin commented on Jul 11, 2015

    @mrocklin
    Member

    Oh yes, indeed. I can see how that would trip up almost any incoming user.

  2. JDWarner commented on Jul 11, 2015

    @JDWarner
    Author

    This definitely didn't just happen to me...

  3. mrocklin commented on Jul 11, 2015

    @mrocklin
    Member

    On it.

  4. JDWarner commented on Jul 11, 2015

    @JDWarner
    Author

    Since it appears dask_arr.chunks can dynamically be changed after creation, the best approach is probably to fail gracefully on computation.

  5. added a commit that references this issue on Jul 11, 2015
    2099bf5
  6. mrocklin commented on Jul 11, 2015

    @mrocklin
    Member

    Fixed in #416

    Regarding chunks changing after creation, I don't think I've ever seen this happen. I also have a hard time thinking of a situation in which it wouldn't be catastrophic. In my mind chunks is immutable. This isn't at all enforced but I have yet to encounter a person who has tried to change it. I suppose we could hook this up into a property that calls rechunk, but I'd rather wait until the person comes along who trips on this.

  7. JDWarner commented on Jul 11, 2015

    @JDWarner
    Author

    Thanks, @mrocklin!

    Re: chunks changing after creation I just tried to do exactly that - the chunks property accepts any tuple then fails in a different, nasty way on .compute().

  8. mrocklin commented on Jul 11, 2015

    @mrocklin
    Member

    Sounds like that person just came along. Changing to property + private variable

  9. mrocklin commented on Jul 11, 2015

    @mrocklin
    Member
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions