Skip to content

Commit

Permalink
TST added test for groupby agg on mulitlevel column (pandas-dev#29772) (
Browse files Browse the repository at this point in the history
  • Loading branch information
prakhar987 authored and proost committed Dec 19, 2019
1 parent 31b7518 commit 4259dc1
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions pandas/tests/groupby/aggregate/test_aggregate.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,25 @@ def test_groupby_aggregation_mixed_dtype():
tm.assert_frame_equal(result, expected)


def test_groupby_aggregation_multi_level_column():
# GH 29772
lst = [
[True, True, True, False],
[True, False, np.nan, False],
[True, True, np.nan, False],
[True, True, np.nan, False],
]
df = pd.DataFrame(
data=lst,
columns=pd.MultiIndex.from_tuples([("A", 0), ("A", 1), ("B", 0), ("B", 1)]),
)

result = df.groupby(level=1, axis=1).sum()
expected = pd.DataFrame({0: [2.0, 1, 1, 1], 1: [1, 0, 1, 1]})

tm.assert_frame_equal(result, expected)


def test_agg_apply_corner(ts, tsframe):
# nothing to group, all NA
grouped = ts.groupby(ts * np.nan)
Expand Down

0 comments on commit 4259dc1

Please sign in to comment.