|
8 | 8 | from pandas.core.index import Index, MultiIndex
|
9 | 9 | from pandas.core.common import rands
|
10 | 10 | from pandas.core.api import Categorical, DataFrame
|
11 |
| -from pandas.core.groupby import GroupByError |
| 11 | +from pandas.core.groupby import GroupByError, SpecificationError, DataError |
12 | 12 | from pandas.core.series import Series
|
13 | 13 | from pandas.util.testing import (assert_panel_equal, assert_frame_equal,
|
14 | 14 | assert_series_equal, assert_almost_equal)
|
@@ -252,11 +252,10 @@ def test_agg_apply_corner(self):
|
252 | 252 |
|
253 | 253 | # DataFrame
|
254 | 254 | grouped = self.tsframe.groupby(self.tsframe['A'] * np.nan)
|
255 |
| - assert_frame_equal(grouped.sum(), |
256 |
| - DataFrame(columns=self.tsframe.columns)) |
257 |
| - assert_frame_equal(grouped.agg(np.sum), |
258 |
| - DataFrame(columns=self.tsframe.columns)) |
259 |
| - assert_frame_equal(grouped.apply(np.sum), DataFrame({})) |
| 255 | + exp_df = DataFrame(columns=self.tsframe.columns, dtype=float) |
| 256 | + assert_frame_equal(grouped.sum(), exp_df) |
| 257 | + assert_frame_equal(grouped.agg(np.sum), exp_df) |
| 258 | + assert_frame_equal(grouped.apply(np.sum), DataFrame({}, dtype=float)) |
260 | 259 |
|
261 | 260 | def test_agg_grouping_is_list_tuple(self):
|
262 | 261 | from pandas.core.groupby import Grouping
|
@@ -1078,11 +1077,11 @@ def test_cython_agg_boolean(self):
|
1078 | 1077 | def test_cython_agg_nothing_to_agg(self):
|
1079 | 1078 | frame = DataFrame({'a': np.random.randint(0, 5, 50),
|
1080 | 1079 | 'b': ['foo', 'bar'] * 25})
|
1081 |
| - self.assertRaises(GroupByError, frame.groupby('a')['b'].mean) |
| 1080 | + self.assertRaises(DataError, frame.groupby('a')['b'].mean) |
1082 | 1081 |
|
1083 | 1082 | frame = DataFrame({'a': np.random.randint(0, 5, 50),
|
1084 | 1083 | 'b': ['foo', 'bar'] * 25})
|
1085 |
| - self.assertRaises(GroupByError, frame[['b']].groupby(frame['a']).mean) |
| 1084 | + self.assertRaises(DataError, frame[['b']].groupby(frame['a']).mean) |
1086 | 1085 |
|
1087 | 1086 | def test_wrap_aggregated_output_multindex(self):
|
1088 | 1087 | df = self.mframe.T
|
@@ -1847,6 +1846,12 @@ def test_multiple_functions_tuples_and_non_tuples(self):
|
1847 | 1846 | expected = self.df.groupby('A').agg(ex_funcs)
|
1848 | 1847 | assert_frame_equal(result, expected)
|
1849 | 1848 |
|
| 1849 | + def test_agg_multiple_functions_too_many_lambdas(self): |
| 1850 | + grouped = self.df.groupby('A') |
| 1851 | + funcs = ['mean', lambda x: x.mean(), lambda x: x.std()] |
| 1852 | + |
| 1853 | + self.assertRaises(SpecificationError, grouped.agg, funcs) |
| 1854 | + |
1850 | 1855 | def test_more_flexible_frame_multi_function(self):
|
1851 | 1856 | from pandas import concat
|
1852 | 1857 |
|
|
0 commit comments