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

Conversation

philippjfr
Copy link
Member

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 added type: bug Something isn't correct or isn't working tag: component: data labels 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

Choose a reason for hiding this comment

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

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

Choose a reason for hiding this comment

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

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

Choose a reason for hiding this comment

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

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

Copy link
Member Author

@philippjfr philippjfr Feb 12, 2017

Choose a reason for hiding this comment

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

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

Choose a reason for hiding this comment

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

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

Copy link
Contributor

Choose a reason for hiding this comment

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

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

@jlstevens
Copy link
Contributor

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

@philippjfr
Copy link
Member Author

Ready to merge.

@jlstevens jlstevens merged commit 511a550 into master Feb 13, 2017
@philippjfr philippjfr deleted the grid_interface_multi_groupby branch February 13, 2017 17:04
@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
Labels
tag: component: data type: bug Something isn't correct or isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants