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
WIP
  • Loading branch information
rhshadrach committed Mar 5, 2024
commit 0849e1cba4f36b63dd88ec0de9b25543ea0ea413
2 changes: 1 addition & 1 deletion pandas/core/groupby/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1714,7 +1714,7 @@ def _python_agg_general(self, func, *args, **kwargs):

obj = self._obj_with_exclusions

if not len(obj.columns):
if self._grouper._is_resample and not len(obj.columns):
# e.g. test_margins_no_values_no_cols
return self._python_apply_general(f, self._selected_obj)

Expand Down
11 changes: 9 additions & 2 deletions pandas/tests/reshape/test_pivot.py
Original file line number Diff line number Diff line change
Expand Up @@ -1198,8 +1198,15 @@ 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]
expected = DataFrame(
index=MultiIndex(
levels=[["bar", "foo", "All"], ["one", "two", ""]],
codes=[[0, 0, 1, 1, 2], [0, 1, 0, 1, 2]],
names=["A", "B"],
),
columns=Index([]),
)
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