Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slice by 0-dimensional np.array #3406

Open
crusaderky opened this issue Apr 15, 2018 · 4 comments · May be fixed by #9558
Open

Slice by 0-dimensional np.array #3406

crusaderky opened this issue Apr 15, 2018 · 4 comments · May be fixed by #9558
Labels
array good first issue Clearly described and easy to accomplish. Good for beginners to the project.

Comments

@crusaderky
Copy link
Collaborator

As of the current git head:

>>>> a = da.arange(2, chunks=2)
>>>> idx = np.array(0)
>>>> a[idx]

---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
<ipython-input-4-013759abffed> in <module>()
      3 a = da.arange(2, chunks=2)
      4 idx = np.array(0)
----> 5 a[idx]

~/anaconda3/lib/python3.6/site-packages/dask/array/core.py in __getitem__(self, index)
   1306 
   1307         out = 'getitem-' + tokenize(self, index2)
-> 1308         dsk, chunks = slice_array(out, self.name, self.chunks, index2)
   1309 
   1310         dsk2 = sharedict.merge(self.dask, (out, dsk))

~/anaconda3/lib/python3.6/site-packages/dask/array/slicing.py in slice_array(out_name, in_name, blockdims, index)
    155 
    156     # Pass down to next function
--> 157     dsk_out, bd_out = slice_with_newaxes(out_name, in_name, blockdims, index)
    158 
    159     bd_out = tuple(map(tuple, bd_out))

~/anaconda3/lib/python3.6/site-packages/dask/array/slicing.py in slice_with_newaxes(out_name, in_name, blockdims, index)
    177 
    178     # Pass down and do work
--> 179     dsk, blockdims2 = slice_wrap_lists(out_name, in_name, blockdims, index2)
    180 
    181     if where_none:

~/anaconda3/lib/python3.6/site-packages/dask/array/slicing.py in slice_wrap_lists(out_name, in_name, blockdims, index)
    232     # No lists, hooray! just use slice_slices_and_integers
    233     if not where_list:
--> 234         return slice_slices_and_integers(out_name, in_name, blockdims, index)
    235 
    236     # Replace all lists with full slices  [3, 1, 0] -> slice(None, None, None)

~/anaconda3/lib/python3.6/site-packages/dask/array/slicing.py in slice_slices_and_integers(out_name, in_name, blockdims, index)
    279             raise ValueError("Arrays chunk sizes are unknown: %s", shape)
    280 
--> 281     assert all(isinstance(ind, (slice, Integral)) for ind in index)
    282     assert len(index) == len(blockdims)
    283 
@crusaderky
Copy link
Collaborator Author

Still an issue in dask 1.2.0

@davidsebfischer
Copy link

Also observing this in dask 2.6.0.

@mrocklin
Copy link
Member

mrocklin commented Nov 7, 2019

If someone is able to fix this, that would be welcome.

@GenevieveBuckley GenevieveBuckley added array good first issue Clearly described and easy to accomplish. Good for beginners to the project. labels Oct 12, 2021
@sadielbartholomew
Copy link

Hi Dask team, please could I take this issue on for Hacktoberfest 2021? If so, I will put up a PR shortly, aiming to have it up within the next few days. (I just want to check nobody is working on it already.)

FYI, I have checked and the deficiency at hand is still present with the latest main (as pulled down from your repo upstream about 10 minutes previous to the timestamp on this comment):

$ conda list | grep dask
dask                      2021.10.0                 dev_0    <develop>
>>> import numpy as np
>>> import dask.array as da
>>> a = da.arange(2, chunks=2)
>>> idx = np.array(0)
>>> a[idx]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/sadie/dask/dask/array/core.py", line 1800, in __getitem__
    dsk, chunks = slice_array(out, self.name, self.chunks, index2, self.itemsize)
  File "/home/sadie/dask/dask/array/slicing.py", line 174, in slice_array
    dsk_out, bd_out = slice_with_newaxes(out_name, in_name, blockdims, index, itemsize)
  File "/home/sadie/dask/dask/array/slicing.py", line 196, in slice_with_newaxes
    dsk, blockdims2 = slice_wrap_lists(out_name, in_name, blockdims, index2, itemsize)
  File "/home/sadie/dask/dask/array/slicing.py", line 252, in slice_wrap_lists
    return slice_slices_and_integers(out_name, in_name, blockdims, index)
  File "/home/sadie/dask/dask/array/slicing.py", line 305, in slice_slices_and_integers
    assert all(isinstance(ind, (slice, Integral)) for ind in index)
AssertionError

@fandreuz fandreuz linked a pull request Oct 8, 2022 that will close this issue
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
array good first issue Clearly described and easy to accomplish. Good for beginners to the project.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants