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

Fix GridInterface multi-dimensional groupby #1130

Merged
merged 3 commits into from Feb 13, 2017

Conversation

Projects
None yet
2 participants
@philippjfr
Member

philippjfr commented Feb 12, 2017

As @basnijholt originally reported there was an issue for multi-dimensional groupbys in the GridInterface. This PR fixes the bug and adds a unit test.

@philippjfr philippjfr requested a review from jlstevens Feb 12, 2017

@philippjfr philippjfr changed the title from Grid interface multi groupby to Fix GridInterface multi-dimensional groupby Feb 12, 2017

# Iterate over the unique entries applying selection masks
grouped_data = []
for unique_key in zip(*util.cartesian_product(keys)):
for unique_key in zip(*(arr.flat for arr in util.cartesian_product(keys))):

This comment has been minimized.

@jlstevens

jlstevens Feb 12, 2017

Member

The definition of cartesian_product(arrays) is simply np.broadcast_arrays(*np.ix_(*arrays)). I'm wondering if it might be useful behavior to always output an iterator over flattened/flat arrays...

This comment has been minimized.

@jlstevens

jlstevens Feb 12, 2017

Member

I should mention that I am assuming that we are almost always doing cartesian products over keys which we want to iterate over. I haven't checked where else cartesian_product maybe used... e.g elsewhere in the data API...

This comment has been minimized.

@philippjfr

philippjfr Feb 12, 2017

Member

Right, they're actually always flattened, I'll make that fix.

This comment has been minimized.

@philippjfr

philippjfr Feb 12, 2017

Member

Ah, I remember now the issue is the difference between flat and flatten. Often flat is enough other times you need to flatten to make a copy. I'll give the function a copy kwarg.

This comment has been minimized.

@philippjfr

philippjfr Feb 12, 2017

Member

Hmm, actually there is one usage where it's not flat. Should I also have a flat kwarg?

This comment has been minimized.

@jlstevens

jlstevens Feb 12, 2017

Member

Yes, a flat kwarg would be good and a copy kwarg also makes sense (should probably default to False).

@jlstevens

This comment has been minimized.

Member

jlstevens commented Feb 12, 2017

Made one comment about cartesian_product. Otherwise looks good and I am happy to merge once the tests pass.

@philippjfr

This comment has been minimized.

Member

philippjfr commented Feb 13, 2017

Ready to merge.

@jlstevens jlstevens merged commit 511a550 into master Feb 13, 2017

4 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details
coverage/coveralls Coverage increased (+0.03%) to 78.198%
Details
s3-reference-data-cache Test data is cached.
Details

@philippjfr philippjfr deleted the grid_interface_multi_groupby branch Feb 13, 2017

@philippjfr philippjfr added this to the v1.7.0 milestone Feb 28, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment