|
13 | 13 | from pandas.util.testing import (assert_panel_equal, assert_frame_equal,
|
14 | 14 | assert_series_equal, assert_almost_equal)
|
15 | 15 | from pandas.core.panel import Panel
|
| 16 | +from pandas.tools.merge import concat |
16 | 17 | from collections import defaultdict
|
17 | 18 | import pandas._tseries as lib
|
18 | 19 | import pandas.core.datetools as dt
|
@@ -564,6 +565,30 @@ def test_multi_key_multiple_functions(self):
|
564 | 565 | 'std' : grouped.agg(np.std)})
|
565 | 566 | assert_frame_equal(agged, expected)
|
566 | 567 |
|
| 568 | + def test_frame_multi_key_function_list(self): |
| 569 | + data = DataFrame({'A' : ['foo', 'foo', 'foo', 'foo', |
| 570 | + 'bar', 'bar', 'bar', 'bar', |
| 571 | + 'foo', 'foo', 'foo'], |
| 572 | + 'B' : ['one', 'one', 'one', 'two', |
| 573 | + 'one', 'one', 'one', 'two', |
| 574 | + 'two', 'two', 'one'], |
| 575 | + 'C' : ['dull', 'dull', 'shiny', 'dull', |
| 576 | + 'dull', 'shiny', 'shiny', 'dull', |
| 577 | + 'shiny', 'shiny', 'shiny'], |
| 578 | + 'D' : np.random.randn(11), |
| 579 | + 'E' : np.random.randn(11), |
| 580 | + 'F' : np.random.randn(11)}) |
| 581 | + |
| 582 | + grouped = data.groupby(['A', 'B']) |
| 583 | + funcs = [np.mean, np.std] |
| 584 | + agged = grouped.agg(funcs) |
| 585 | + expected = concat([grouped['D'].agg(funcs), grouped['E'].agg(funcs), |
| 586 | + grouped['F'].agg(funcs)], |
| 587 | + keys=['D', 'E', 'F'], axis=1) |
| 588 | + assert(isinstance(agged.index, MultiIndex)) |
| 589 | + assert(isinstance(expected.index, MultiIndex)) |
| 590 | + assert_frame_equal(agged, expected) |
| 591 | + |
567 | 592 | def test_groupby_multiple_columns(self):
|
568 | 593 | data = self.df
|
569 | 594 | grouped = data.groupby(['A', 'B'])
|
|
0 commit comments