-
Notifications
You must be signed in to change notification settings - Fork 651
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for grouping by multiple columns when doing a reduct… (#987)
* Resolves #75 * Adds support for grouping by multiple columns. * Does this grouping by broadcasting the columns. * A preliminary performance evaluation shows that it is significantly faster than before, but still has some room for improvement. * Minimal code changes to add this new feature. * We still default to pandas when the user is looping over the dataframe * Even though this is common, it is exceptionally hard to optimize, and out of scope for this PR.
- Loading branch information
1 parent
7874281
commit 08f9af5
Showing
4 changed files
with
51 additions
and
24 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -410,20 +410,28 @@ def groupby( | |
else: | ||
by = self.__getitem__(by)._query_compiler | ||
elif is_list_like(by): | ||
if isinstance(by, Series): | ||
idx_name = by.name | ||
by = by.values | ||
mismatch = len(by) != len(self.axes[axis]) | ||
if mismatch and all( | ||
obj in self | ||
or (hasattr(self.index, "names") and obj in self.index.names) | ||
for obj in by | ||
): | ||
# In the future, we will need to add logic to handle this, but for now | ||
# we default to pandas in this case. | ||
pass | ||
elif mismatch: | ||
raise KeyError(next(x for x in by if x not in self)) | ||
# fastpath for multi column groupby | ||
if axis == 0 and all(o in self for o in by): | ||
warnings.warn( | ||
"Multi-column groupby is a new feature. " | ||
"Please report any bugs/issues to [email protected]." | ||
) | ||
by = self.__getitem__(by)._query_compiler | ||
else: | ||
if isinstance(by, Series): | ||
idx_name = by.name | ||
by = by.values | ||
mismatch = len(by) != len(self.axes[axis]) | ||
if mismatch and all( | ||
obj in self | ||
or (hasattr(self.index, "names") and obj in self.index.names) | ||
for obj in by | ||
): | ||
# In the future, we will need to add logic to handle this, but for now | ||
# we default to pandas in this case. | ||
pass | ||
elif mismatch: | ||
raise KeyError(next(x for x in by if x not in self)) | ||
|
||
from .groupby import DataFrameGroupBy | ||
|
||
|
This file contains 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
This file contains 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