Skip to content
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
Merged

Conversation

@philippjfr
Copy link
Member

@philippjfr 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 Grid interface multi groupby 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))):
Copy link
Contributor

@jlstevens jlstevens Feb 12, 2017

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...

Copy link
Contributor

@jlstevens jlstevens Feb 12, 2017

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...

Copy link
Member Author

@philippjfr philippjfr Feb 12, 2017

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

Copy link
Member Author

@philippjfr philippjfr Feb 12, 2017

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.

Copy link
Member Author

@philippjfr philippjfr Feb 12, 2017

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

Copy link
Contributor

@jlstevens jlstevens Feb 12, 2017

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

@jlstevens
Copy link
Contributor

@jlstevens 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 philippjfr force-pushed the grid_interface_multi_groupby branch from adbf888 to ade9734 Feb 12, 2017
@philippjfr
Copy link
Member Author

@philippjfr philippjfr commented Feb 13, 2017

Ready to merge.

@jlstevens jlstevens merged commit 511a550 into master Feb 13, 2017
4 checks passed
@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
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants