8000 BUG: groupby.agg should always agg by rhshadrach · Pull Request #57706 · pandas-dev/pandas · GitHub
[go: up one dir, main page]

Skip to content

BUG: groupby.agg should always agg #57706

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

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Test fixup
  • Loading branch information
rhshadrach committed Mar 3, 2024
commit 87d32aebb4e97be8db9d06be2c9d8c312a06138e
4 changes: 3 additions & 1 deletion pandas/core/groupby/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1716,7 +1716,9 @@ def _python_agg_general(self, func, *args, **kwargs):

if not len(obj.columns):
# e.g. test_margins_no_values_no_cols
return self._python_apply_general(f, self._selected_obj)
return obj._constructor(
index=self._grouper.result_index, columns=obj.columns
)

output: dict[int, ArrayLike] = {}
for idx, (name, ser) in enumerate(obj.items()):
Expand Down
9 changes: 7 additions & 2 deletions pandas/tests/reshape/test_pivot.py
Original file line number Diff line number Diff line change
Expand Up @@ -1198,8 +1198,13 @@ def test_margins_no_values_no_cols(self, data):
result = data[["A", "B"]].pivot_table(
index=["A", "B"], aggfunc=len, margins=True
)
result_list = result.tolist()
assert sum(result_list[:-1]) == result_list[-1]
index = MultiIndex(
levels=[["bar", "foo", "All"], ["one", "two", ""]],
codes=[[0, 0, 1, 1, 2], [0, 1, 0, 1, 2]],
names=["A", "B"],
)
expected = DataFrame(index=index, columns=[])
tm.assert_frame_equal(result, expected)

def test_margins_no_values_two_rows(self, data):
# Regression test on pivot table: no values passed but rows are a
Expand Down
0