Repository navigation
Use mask selection in compress - #4548
Merged
Merged
Conversation
If the `condition` is shorter than the Dask Array, treat it as if it is filled with `False` values at the end. In other words, trim the Dask Array down to the length of the `condition`. This works just as well when the `condition` is a Dask Array as when it is a NumPy array.
As masked selection is supported by Dask Arrays, NumPy arrays, and other array types, go ahead and change the `compress` code to use masked selection in all cases. Should make it easier for other array types to benefit from this code. Simplifies our code and removes a branch as well.
jakirkham
force-pushed
the
use_mask_compress
branch
from
March 6, 2019 00:01
c796322 to
1e9f445
Compare
If the length of `condition` is shorter, the array will be shortened with or without this check. Otherwise if the length of `condition` is the same, then this will be a no-op (and we already test for this). In the rare event `condition` is longer than our array, this will do nothing, but we will generate an error later.
Uses the same comprehension trick for truncating the Dask Array above when slicing with the mask.
Member
Indeed :) Merging tomorrow if there are no further comments |
Member
|
Oh wow, that was quick, and the code is much cleaner now! Thanks @jakirkham! |
jorge-pessoa
pushed a commit
to jorge-pessoa/dask
that referenced
this pull request
May 14, 2019
* Trim Dask Array that extends past condition If the `condition` is shorter than the Dask Array, treat it as if it is filled with `False` values at the end. In other words, trim the Dask Array down to the length of the `condition`. This works just as well when the `condition` is a Dask Array as when it is a NumPy array. * Use masked selection to implement compress As masked selection is supported by Dask Arrays, NumPy arrays, and other array types, go ahead and change the `compress` code to use masked selection in all cases. Should make it easier for other array types to benefit from this code. Simplifies our code and removes a branch as well. * Coerce `compress` arguments to Dask Arrays * Drop unneeded check with `condition` in `compress` * Swap `condition` and `axis` checks in `compress` * Drop `condition` length check If the length of `condition` is shorter, the array will be shortened with or without this check. Otherwise if the length of `condition` is the same, then this will be a no-op (and we already test for this). In the rare event `condition` is longer than our array, this will do nothing, but we will generate an error later. * Simplify slicing with `condition` Uses the same comprehension trick for truncating the Dask Array above when slicing with the mask.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #4497
Rewrites
compressto leverage mask selection in its implementation. This simplifies the code a bit as it benefits from existing mask selection support for Dask Arrays ( #2658 ), which works just as well for NumPy arrays or other similar arrays.cc @pentschev @mrocklin
flake8 dask