Skip to content

Commit

Permalink
FEAT-#2375: removed unnecessary 'drop' in '_apply_agg_function'
Browse files Browse the repository at this point in the history
Signed-off-by: Dmitry Chigarev <[email protected]>
  • Loading branch information
dchigarev committed Dec 8, 2020
1 parent db5ab68 commit 047ec19
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 30 deletions.
11 changes: 4 additions & 7 deletions modin/backends/base/query_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -1408,13 +1408,10 @@ def groupby_agg(
groupby_kwargs,
drop=False,
):
if is_multi_by:
if isinstance(by, type(self)) and len(by.columns) == 1:
by = by.columns[0] if drop else by.to_pandas().squeeze()
elif isinstance(by, type(self)):
by = list(by.columns)
else:
by = by.to_pandas().squeeze() if isinstance(by, type(self)) else by
if isinstance(by, type(self)) and len(by.columns) == 1:
by = by.columns[0] if drop else by.to_pandas().squeeze()
elif isinstance(by, type(self)):
by = list(by.columns)

return GroupByDefault.register(pandas.core.groupby.DataFrameGroupBy.aggregate)(
self,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,6 @@ def fn(
):
by = cls.validate_by(by)

if not is_multi_by:
groupby_args = groupby_args.copy()
as_index = groupby_args.pop("as_index", True)
groupby_args["as_index"] = True

grp = df.groupby(by, axis=axis, **groupby_args)
agg_func = cls.get_func(grp, key, **kwargs)
result = (
Expand All @@ -88,15 +83,7 @@ def fn(
else agg_func(grp, **agg_args)
)

if not is_multi_by:
if as_index:
return result
else:
if result.index.name is None or result.index.name in result.columns:
drop = False
return result.reset_index(drop=not drop)
else:
return result
return result

return fn

Expand Down
10 changes: 1 addition & 9 deletions modin/pandas/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -900,15 +900,7 @@ def _apply_agg_function(self, f, drop=True, *args, **kwargs):
f, dict
), "'{0}' object is not callable and not a dict".format(type(f))

# For aggregations, pandas behavior does this for the result.
# For other operations it does not, so we wait until there is an aggregation to
# actually perform this operation.
if not self._is_multi_by and self._idx_name is not None and drop and self._drop:
groupby_qc = self._query_compiler.drop(columns=[self._idx_name])
else:
groupby_qc = self._query_compiler

new_manager = groupby_qc.groupby_agg(
new_manager = self._query_compiler.groupby_agg(
by=self._by,
is_multi_by=self._is_multi_by,
axis=self._axis,
Expand Down

0 comments on commit 047ec19

Please sign in to comment.