Skip to content

Clarify differences in boolean indexing between dask and numpy arrays#6764

Merged
jsignell merged 3 commits intodask:masterfrom
Illviljan:Illviljan-boolarraysnumpyvsdask
Oct 26, 2020
Merged

Clarify differences in boolean indexing between dask and numpy arrays#6764
jsignell merged 3 commits intodask:masterfrom
Illviljan:Illviljan-boolarraysnumpyvsdask

Conversation

@Illviljan
Copy link
Contributor

@Illviljan Illviljan commented Oct 22, 2020

Dask arrays does boolean indexing differently compared to numpy arrays.
Add a hint how it's done in the error, the hint is displayed when some shape is nan.

Related issue: #6711

dask does boolean indexing differently compared to numpy, add a hint how it's done in the error. 
Make if-condition a little easier to read.
Copy link
Member

@jsignell jsignell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for opening this! Now that I've seen it, I think the hint should live in the __setitem__ method. That way we don't need to change the logic in broadcast_shapes, we can just add an extra hint to the original error message. Something like this:

            try:
                y = where(key, value, self)
            except ValueError as e:
                raise ValueError(
                    "Boolean index assignment in Dask "
                    "expects equally shaped arrays. Example: da1[da2] = da3"
                    "where da1.shape == (4,) and da3.shape == (4,)."
                ) from e

here:

y = where(key, value, self)

@Illviljan
Copy link
Contributor Author

Thanks! I didn't know about chaining errors like that. The error looks like this now:

(...)
ValueError: Boolean index assignment in Dask expects equally shaped arrays.
Example: da1[da2] = da3 where da1.shape == (4,), da2.shape == (4,) and da3.shape == (4,).

Copy link
Member

@jsignell jsignell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this! It looks great!

@jsignell jsignell merged commit 9dae034 into dask:master Oct 26, 2020
kumarprabhu1988 pushed a commit to kumarprabhu1988/dask that referenced this pull request Oct 29, 2020
…dask#6764)

* Hint how to do boolean indexing

dask does boolean indexing differently compared to numpy, add a hint how it's done in the error. 
Make if-condition a little easier to read.

* Undo condition changes

* Move error tot setitem instead.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants