Skip to content

IndexError when slicing dask Array with unknown chunk sizes. #6586

Closed

Description

@TomAugspurger

When doing fancy indexing on an index with missing chunks we raise an IndexError.

In [21]: a = da.ones((10, 5), chunks=5)

In [22]: a._chunks = ((np.nan, np.nan), (5,))

In [23]: a[[0, 5]].compute()
---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-23-314b1b59b481> in <module>
----> 1 a[[0, 5]].compute()

~/sandbox/dask/dask/dask/base.py in compute(self, **kwargs)
    165         dask.base.compute
    166         """
--> 167         (result,) = compute(self, traverse=False, **kwargs)
    168         return result
    169

~/sandbox/dask/dask/dask/base.py in compute(*args, **kwargs)
    450         postcomputes.append(x.__dask_postcompute__())
    451
--> 452     results = schedule(dsk, keys, **kwargs)
    453     return repack([f(r, *a) for r, (f, a) in zip(results, postcomputes)])
    454

~/sandbox/dask/dask/dask/threaded.py in get(dsk, result, cache, num_workers, pool, **kwargs)
     74                 pools[thread][num_workers] = pool
     75
---> 76     results = get_async(
     77         pool.apply_async,
     78         len(pool._pool),

~/sandbox/dask/dask/dask/local.py in get_async(apply_async, num_workers, dsk, result, cache, get_id, rerun_exceptions_locally, pack_exception, raise_exception, callbacks, dumps, loads, **kwargs)
    484                         _execute_task(task, data)  # Re-execute locally
    485                     else:
--> 486                         raise_exception(exc, tb)
    487                 res, worker_id = loads(res_info)
    488                 state["cache"][key] = res

~/sandbox/dask/dask/dask/local.py in reraise(exc, tb)
    314     if exc.__traceback__ is not tb:
    315         raise exc.with_traceback(tb)
--> 316     raise exc
    317
    318

~/sandbox/dask/dask/dask/local.py in execute_task(key, task_info, dumps, loads, get_id, pack_exception)
    220     try:
    221         task, data = loads(task_info)
--> 222         result = _execute_task(task, data)
    223         id = get_id()
    224         result = dumps((result, id))

~/sandbox/dask/dask/dask/core.py in _execute_task(arg, cache, dsk)
    119         # temporaries by their reference count and can execute certain
    120         # operations in-place.
--> 121         return func(*(_execute_task(a, cache) for a in args))
    122     elif not ishashable(arg):
    123         return arg

IndexError: index 5 is out of bounds for axis 0 with size 5

It actually works if the indexer happens to slice from just the first chunk.

In [24]: a[[0, 4]].compute()
Out[24]:
array([[1., 1., 1., 1., 1.],
       [1., 1., 1., 1., 1.]])

I'm not sure what's best to do here. I can imagine a few things that might work but would be slow. Perhaps we just raise when people try to do fancy indexing on an array with unknown chunk sizes?

Activity

  1. mrocklin commented on Sep 1, 2020

    @mrocklin
    Member
  2. added
    good first issue
    on Oct 13, 2021
  3. shubhamranjan12 commented on Mar 24, 2022

    @shubhamranjan12

    hi,
    Can I work on this issue please ?

  4. ian-r-rose commented on Mar 25, 2022

    @ian-r-rose
    Collaborator

    Hi @shubhamranjan12 . Sure! You might do something similar to what @douglasdavis did in #8436

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

Metadata

Metadata

Labels

arraygood first issue

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions