Skip to content

Commit 0849e1c

Browse files
committed
WIP
1 parent 711fcb6 commit 0849e1c

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

pandas/core/groupby/generic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1714,7 +1714,7 @@ def _python_agg_general(self, func, *args, **kwargs):
17141714

17151715
obj = self._obj_with_exclusions
17161716

1717-
if not len(obj.columns):
1717+
if self._grouper._is_resample and not len(obj.columns):
17181718
# e.g. test_margins_no_values_no_cols
17191719
return self._python_apply_general(f, self._selected_obj)
17201720

pandas/tests/reshape/test_pivot.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1198,8 +1198,15 @@ def test_margins_no_values_no_cols(self, data):
11981198
result = data[["A", "B"]].pivot_table(
11991199
index=["A", "B"], aggfunc=len, margins=True
12001200
)
1201-
result_list = result.tolist()
1202-
assert sum(result_list[:-1]) == result_list[-1]
1201+
expected = DataFrame(
1202+
index=MultiIndex(
1203+
levels=[["bar", "foo", "All"], ["one", "two", ""]],
1204+
codes=[[0, 0, 1, 1, 2], [0, 1, 0, 1, 2]],
1205+
names=["A", "B"],
1206+
),
1207+
columns=Index([]),
1208+
)
1209+
tm.assert_frame_equal(result, expected)
12031210

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

0 commit comments

Comments
 (0)