Skip to content

REF: remove _transform_item_by_item #51224

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
Feb 8, 2023
Merged
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
14 changes: 1 addition & 13 deletions pandas/core/groupby/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1558,9 +1558,8 @@ def _transform_general(self, func, *args, **kwargs):
object.__setattr__(group, "name", name)
try:
path, res = self._choose_path(fast_path, slow_path, group)
except TypeError:
return self._transform_item_by_item(obj, fast_path)
except ValueError as err:
# e.g. test_transform_with_non_scalar_group
msg = "transform must return a scalar value for each group"
raise ValueError(msg) from err
if group.size > 0:
Expand Down Expand Up @@ -1693,17 +1692,6 @@ def _choose_path(self, fast_path: Callable, slow_path: Callable, group: DataFram

return path, res

def _transform_item_by_item(self, obj: DataFrame, wrapper) -> DataFrame:
# iterate through columns, see test_transform_exclude_nuisance
# gets here with non-unique columns
output = {}
for i, (colname, sgb) in enumerate(self._iterate_column_groupbys(obj)):
output[i] = sgb.transform(wrapper)

result = self.obj._constructor(output, index=obj.index)
result.columns = obj.columns
return result

def filter(self, func, dropna: bool = True, *args, **kwargs):
"""
Filter elements from groups that don't satisfy a criterion.
Expand Down