Skip to content

REF: more distinctive names for BaseGrouper.aggregate, transform #38161

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

Merged
merged 1 commit into from
Nov 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pandas/core/groupby/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1063,8 +1063,8 @@ def cast_agg_result(result, values: ArrayLike, how: str) -> ArrayLike:
def blk_func(bvalues: ArrayLike) -> ArrayLike:

try:
result, _ = self.grouper.aggregate(
bvalues, how, axis=1, min_count=min_count
result, _ = self.grouper._cython_operation(
"aggregate", bvalues, how, axis=1, min_count=min_count
)
except NotImplementedError:
# generally if we have numeric_only=False
Expand Down
13 changes: 9 additions & 4 deletions pandas/core/groupby/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -982,16 +982,21 @@ def _transform_should_cast(self, func_nm: str) -> bool:
assert filled_series is not None
return filled_series.gt(0).any() and func_nm not in base.cython_cast_blocklist

def _cython_transform(self, how: str, numeric_only: bool = True, **kwargs):
def _cython_transform(
self, how: str, numeric_only: bool = True, axis: int = 0, **kwargs
):
output: Dict[base.OutputKey, np.ndarray] = {}

for idx, obj in enumerate(self._iterate_slices()):
name = obj.name
is_numeric = is_numeric_dtype(obj.dtype)
if numeric_only and not is_numeric:
continue

try:
result, _ = self.grouper.transform(obj.values, how, **kwargs)
result, _ = self.grouper._cython_operation(
"transform", obj.values, how, axis, **kwargs
)
except NotImplementedError:
continue

Expand Down Expand Up @@ -1067,8 +1072,8 @@ def _cython_agg_general(
if numeric_only and not is_numeric:
continue

result, agg_names = self.grouper.aggregate(
obj._values, how, min_count=min_count
result, agg_names = self.grouper._cython_operation(
"aggregate", obj._values, how, axis=0, min_count=min_count
)

if agg_names:
Expand Down
10 changes: 0 additions & 10 deletions pandas/core/groupby/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -588,16 +588,6 @@ def _cython_operation(

return result, names

def aggregate(
self, values, how: str, axis: int = 0, min_count: int = -1
) -> Tuple[np.ndarray, Optional[List[str]]]:
return self._cython_operation(
"aggregate", values, how, axis, min_count=min_count
)

def transform(self, values, how: str, axis: int = 0, **kwargs):
return self._cython_operation("transform", values, how, axis, **kwargs)

def _aggregate(
self, result, counts, values, comp_ids, agg_func, min_count: int = -1
):
Expand Down