Skip to content

Commit

Permalink
TST added test for groupby agg on mulitlevel column (#29772) (#29866)
Browse files Browse the repository at this point in the history
  • Loading branch information
prakhar987 authored and simonjayhawkins committed Nov 27, 2019
1 parent d338b94 commit d7328d3
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 d7328d3

Please sign in to comment.