Repository navigation
Dask array slicing with boolean arrays - #2658
Conversation
|
As noted in the associated issue, it may be worth running |
4e5a1d5 to
752e194
Compare
|
I've added an implementation. However I had forgotten that NumPy does some odd things when slicing with boolean arrays. In particular it seems to prefer to bring that axis to the front. |
|
Not sure what to do here. |
Sorry not following. Do you have an example? |
|
I'm finding this behavior to be confusing: import numpy as np
x = np.ones((10, 10, 10, 10))
x[1:9, 4, :, np.array([True, False, False, True, False, False, True, True, True, False])].shape
# (5, 8, 10)This PR has an xfailed test that includes this situation |
|
This is numpy's confusing mixed basic/advanced indexing rules again. You get the same sort of behavior with integer instead of boolean arrays. |
|
One way to resolve this is to add a dedicated |
|
Have to say am a bit perplexed by that example as well. Would have to agree that it looks like it is transposing things when it shouldn't. Are we sure it isn't a bug? |
|
Definitely not a bug, but you're not the only one who's confused by it. (There have been long discussions about the numpy mailing list about this.) |
e72e012 to
195b095
Compare
|
This is ready for review |
TomAugspurger
left a comment
There was a problem hiding this comment.
I think this looks good. I ran my tests dask-ml that needed the boolean filtering, and all those passed.
|
|
||
| if any(isinstance(ind, Array) and ind.dtype == bool and ind.ndim != 1 | ||
| for ind in index): | ||
| raise NotImplementedError("Slicing with dask.array only permitted for " |
There was a problem hiding this comment.
I found this error message a bit confusing, I think the "only permitted for dimension 1 and dimension n". Maybe something like "only permitted when the indexer has 1 dimension, or the dimensions of the indexer match the dimensions of the array being sliced."? It's a bit wordier.
* Support slicing with boolean dask arrays * add failing test for boolean slicing * squash * Partially support indexing with dimension 1 < ... < n * remove cases other than 1 and all dimensions * update error message
Currently we support this:
But not this
This PR attempts to fix this, but currently fails.
see #2651 and #2430
cc @TomAugspurger