Skip to content

Allows optional axis argument in Dask Array squeeze method - #3261

Merged
mrocklin merged 5 commits into
dask:masterfrom
jakirkham:opt_axis_squeeze
Mar 9, 2018
Merged

mrocklin merged 5 commits into
dask:masterfrom
jakirkham:opt_axis_squeeze

Conversation

@jakirkham

Copy link
Copy Markdown
Member

Fixes #3259

@jakirkham

Copy link
Copy Markdown
Member Author

May need a changelog entry. If so, will handle after PR ( #3260 ) is merged.

@jakirkham
jakirkham force-pushed the opt_axis_squeeze branch 3 times, most recently from 6a8f6ca to ce87b98 Compare March 9, 2018 05:17
The `squeeze` method in NumPy takes an optional `axis` as does the
function. However we only support `axis` in the Dask Array function and
not the method. This brings the Dask Array `squeeze` method up to parity
with its NumPy counterpart by adding the optional `axis` argument.
@jakirkham
jakirkham force-pushed the opt_axis_squeeze branch 3 times, most recently from 614f451 to e528e03 Compare March 9, 2018 05:43
To generalize squeeze a bit and simplify it as well, just make use of
item selection to squeeze axes.
Comment thread dask/array/routines.py Outdated
axis = tuple(i for i, d in enumerate(a.shape) if d == 1)
b = a.map_blocks(partial(np.squeeze, axis=axis), dtype=a.dtype)
chunks = tuple(bd for bd in b.chunks if bd != (1,))
else:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do we need this else here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes, this handles both int and tuples of ints. It coerces the former into the latter first (maybe part of the confusion). Then applies some checks and normalizes the input data. None of these checks or normalization are required for None as the data is already constructed to meet our expectations.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I agree that the body of the else is useful. I think we should the normalization code regardless, just to reduce the code nesting.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Sure, fixed. :)

@mrocklin

mrocklin commented Mar 9, 2018

Copy link
Copy Markdown
Member

Small comment, otherwise seems good to me

@jakirkham

Copy link
Copy Markdown
Member Author

Alright, think this is ready to go in now. :)

@mrocklin
mrocklin merged commit 1af19fb into dask:master Mar 9, 2018
@jakirkham
jakirkham deleted the opt_axis_squeeze branch March 9, 2018 22:19
@jakirkham

Copy link
Copy Markdown
Member Author

Forgot a changelog entry. Adding in PR ( #3321 ).

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