diff --git a/doc/source/whatsnew/v0.24.0.txt b/doc/source/whatsnew/v0.24.0.txt index 51c398518c153..3b426937f7393 100644 --- a/doc/source/whatsnew/v0.24.0.txt +++ b/doc/source/whatsnew/v0.24.0.txt @@ -941,6 +941,8 @@ Removal of prior version deprecations/changes - Several private functions were removed from the (non-public) module ``pandas.core.common`` (:issue:`22001`) - Removal of the previously deprecated module ``pandas.core.datetools`` (:issue:`14105`, :issue:`14094`) - Strings passed into :meth:`DataFrame.groupby` that refer to both column and index levels will raise a ``ValueError`` (:issue:`14432`) +- Grouped, rolled, and resampled ``Series`` will now raise a ``ValueError`` when a dictionary is passed in during aggregation (:issue:`15931`) +- Grouped, rolled, and resampled ``DataFrame`` will now raise a ``ValueError`` when a nested dictionary is passed in during aggregation (:issue:`15931`) - :meth:`Index.repeat` and :meth:`MultiIndex.repeat` have renamed the ``n`` argument to ``repeats`` (:issue:`14645`) - Removal of the previously deprecated ``as_indexer`` keyword completely from ``str.match()`` (:issue:`22356`, :issue:`6581`) - Removed the ``pandas.formats.style`` shim for :class:`pandas.io.formats.style.Styler` (:issue:`16059`) diff --git a/pandas/core/base.py b/pandas/core/base.py index de368f52b6f00..10c07665c0d61 100644 --- a/pandas/core/base.py +++ b/pandas/core/base.py @@ -366,14 +366,10 @@ def _aggregate(self, arg, *args, **kwargs): obj = self._selected_obj - def nested_renaming_depr(level=4): - # deprecation of nested renaming - # GH 15931 - warnings.warn( - ("using a dict with renaming " - "is deprecated and will be removed in a future " - "version"), - FutureWarning, stacklevel=level) + def raise_on_dict_renaming(): + # Originally deprecated in gh-15931, now enforcing. + rename_msg_err = "Using a dict with renaming is not allowed" + raise ValueError(rename_msg_err) # if we have a dict of any non-scalars # eg. {'A' : ['mean']}, normalize all to @@ -403,10 +399,10 @@ def nested_renaming_depr(level=4): msg = ('cannot perform renaming for {key} with a ' 'nested dictionary').format(key=k) raise SpecificationError(msg) - nested_renaming_depr(4 + (_level or 0)) + raise_on_dict_renaming() elif isinstance(obj, ABCSeries): - nested_renaming_depr() + raise_on_dict_renaming() elif (isinstance(obj, ABCDataFrame) and k not in obj.columns): raise KeyError( @@ -420,7 +416,7 @@ def nested_renaming_depr(level=4): keys = list(compat.iterkeys(arg)) if (isinstance(obj, ABCDataFrame) and len(obj.columns.intersection(keys)) != len(keys)): - nested_renaming_depr() + raise_on_dict_renaming() from pandas.core.reshape.concat import concat diff --git a/pandas/core/groupby/generic.py b/pandas/core/groupby/generic.py index a832eecf87721..a631bb14ee609 100644 --- a/pandas/core/groupby/generic.py +++ b/pandas/core/groupby/generic.py @@ -8,7 +8,6 @@ import collections import copy -import warnings from functools import partial from textwrap import dedent @@ -785,15 +784,9 @@ def aggregate(self, func_or_funcs, *args, **kwargs): def _aggregate_multiple_funcs(self, arg, _level): if isinstance(arg, dict): - # show the deprecation, but only if we - # have not shown a higher level one - # GH 15931 - if isinstance(self._selected_obj, Series) and _level <= 1: - warnings.warn( - ("using a dict on a Series for aggregation\n" - "is deprecated and will be removed in a future " - "version"), - FutureWarning, stacklevel=3) + # Deprecated in gh-15931, now enforcing. + if isinstance(self._selected_obj, Series): + raise ValueError("Using a dict with renaming is not allowed") columns = list(arg.keys()) arg = list(arg.items()) diff --git a/pandas/tests/frame/test_apply.py b/pandas/tests/frame/test_apply.py index ca3469f34fee6..13b05a5cc4d3a 100644 --- a/pandas/tests/frame/test_apply.py +++ b/pandas/tests/frame/test_apply.py @@ -37,7 +37,7 @@ def int_frame_const_col(): return df -class TestDataFrameApply(): +class TestDataFrameApply(object): def test_apply(self, float_frame): with np.errstate(all='ignore'): @@ -948,12 +948,11 @@ def test_agg_multiple_mixed_no_warning(self): expected = expected[['D', 'C', 'B', 'A']] tm.assert_frame_equal(result, expected) - def test_agg_dict_nested_renaming_depr(self): - + def test_agg_dict_nested_renaming_fail(self): df = pd.DataFrame({'A': range(5), 'B': 5}) + msg = "Using a dict with renaming is not allowed" - # nested renaming - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): + with tm.assert_raises_regex(ValueError, msg): df.agg({'A': {'foo': 'min'}, 'B': {'bar': 'max'}}) diff --git a/pandas/tests/groupby/aggregate/test_aggregate.py b/pandas/tests/groupby/aggregate/test_aggregate.py index b0d6a0e83440a..74f0df0ea3729 100644 --- a/pandas/tests/groupby/aggregate/test_aggregate.py +++ b/pandas/tests/groupby/aggregate/test_aggregate.py @@ -241,49 +241,3 @@ def test_more_flexible_frame_multi_function(df): expected = grouped.aggregate(OrderedDict([['C', np.mean], ['D', [np.mean, np.std]]])) tm.assert_frame_equal(result, expected) - - def foo(x): - return np.mean(x) - - def bar(x): - return np.std(x, ddof=1) - - # this uses column selection & renaming - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - d = OrderedDict([['C', np.mean], - ['D', OrderedDict([['foo', np.mean], - ['bar', np.std]])]]) - result = grouped.aggregate(d) - - d = OrderedDict([['C', [np.mean]], ['D', [foo, bar]]]) - expected = grouped.aggregate(d) - - tm.assert_frame_equal(result, expected) - - -def test_multi_function_flexible_mix(df): - # GH #1268 - grouped = df.groupby('A') - - # Expected - d = OrderedDict([['C', OrderedDict([['foo', 'mean'], ['bar', 'std']])], - ['D', {'sum': 'sum'}]]) - # this uses column selection & renaming - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - expected = grouped.aggregate(d) - - # Test 1 - d = OrderedDict([['C', OrderedDict([['foo', 'mean'], ['bar', 'std']])], - ['D', 'sum']]) - # this uses column selection & renaming - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - result = grouped.aggregate(d) - tm.assert_frame_equal(result, expected) - - # Test 2 - d = OrderedDict([['C', OrderedDict([['foo', 'mean'], ['bar', 'std']])], - ['D', ['sum']]]) - # this uses column selection & renaming - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - result = grouped.aggregate(d) - tm.assert_frame_equal(result, expected) diff --git a/pandas/tests/groupby/aggregate/test_other.py b/pandas/tests/groupby/aggregate/test_other.py index c35405ad739c9..78d5d86b1ef66 100644 --- a/pandas/tests/groupby/aggregate/test_other.py +++ b/pandas/tests/groupby/aggregate/test_other.py @@ -195,76 +195,15 @@ def test_aggregate_api_consistency(): expected = pd.concat([d_sum, c_mean], axis=1) tm.assert_frame_equal(result, expected, check_like=True) - result = grouped.agg({'C': ['mean', 'sum'], - 'D': ['mean', 'sum']}) - expected = pd.concat([c_mean, c_sum, d_mean, d_sum], axis=1) - expected.columns = MultiIndex.from_product([['C', 'D'], - ['mean', 'sum']]) - - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - result = grouped[['D', 'C']].agg({'r': np.sum, - 'r2': np.mean}) - expected = pd.concat([d_sum, c_sum, d_mean, c_mean], axis=1) - expected.columns = MultiIndex.from_product([['r', 'r2'], - ['D', 'C']]) - tm.assert_frame_equal(result, expected, check_like=True) - - -def test_agg_dict_renaming_deprecation(): - # 15931 - df = pd.DataFrame({'A': [1, 1, 1, 2, 2], - 'B': range(5), - 'C': range(5)}) - - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False) as w: - df.groupby('A').agg({'B': {'foo': ['sum', 'max']}, - 'C': {'bar': ['count', 'min']}}) - assert "using a dict with renaming" in str(w[0].message) - - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - df.groupby('A')[['B', 'C']].agg({'ma': 'max'}) - - with tm.assert_produces_warning(FutureWarning) as w: - df.groupby('A').B.agg({'foo': 'count'}) - assert "using a dict on a Series for aggregation" in str(w[0].message) - - -def test_agg_compat(): - # GH 12334 - df = DataFrame({'A': ['foo', 'bar', 'foo', 'bar', - 'foo', 'bar', 'foo', 'foo'], - 'B': ['one', 'one', 'two', 'two', - 'two', 'two', 'one', 'two'], - 'C': np.random.randn(8) + 1.0, - 'D': np.arange(8)}) - - g = df.groupby(['A', 'B']) - - expected = pd.concat([g['D'].sum(), g['D'].std()], axis=1) - expected.columns = MultiIndex.from_tuples([('C', 'sum'), - ('C', 'std')]) - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - result = g['D'].agg({'C': ['sum', 'std']}) - tm.assert_frame_equal(result, expected, check_like=True) - - expected = pd.concat([g['D'].sum(), g['D'].std()], axis=1) - expected.columns = ['C', 'D'] - - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - result = g['D'].agg({'C': 'sum', 'D': 'std'}) - tm.assert_frame_equal(result, expected, check_like=True) - def test_agg_nested_dicts(): - # API change for disallowing these types of nested dicts + # API change for disallowing these types of nested dicts. df = DataFrame({'A': ['foo', 'bar', 'foo', 'bar', 'foo', 'bar', 'foo', 'foo'], 'B': ['one', 'one', 'two', 'two', 'two', 'two', 'one', 'two'], 'C': np.random.randn(8) + 1.0, 'D': np.arange(8)}) - g = df.groupby(['A', 'B']) msg = r'cannot perform renaming for r[1-2] with a nested dictionary' @@ -272,26 +211,10 @@ def test_agg_nested_dicts(): g.aggregate({'r1': {'C': ['mean', 'sum']}, 'r2': {'D': ['mean', 'sum']}}) - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - result = g.agg({'C': {'ra': ['mean', 'std']}, - 'D': {'rb': ['mean', 'std']}}) - expected = pd.concat([g['C'].mean(), g['C'].std(), - g['D'].mean(), g['D'].std()], - axis=1) - expected.columns = pd.MultiIndex.from_tuples( - [('ra', 'mean'), ('ra', 'std'), - ('rb', 'mean'), ('rb', 'std')]) - tm.assert_frame_equal(result, expected, check_like=True) - - # same name as the original column - # GH9052 - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - expected = g['D'].agg({'result1': np.sum, 'result2': np.mean}) - expected = expected.rename(columns={'result1': 'D'}) - - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - result = g['D'].agg({'D': np.sum, 'result2': np.mean}) - tm.assert_frame_equal(result, expected, check_like=True) + msg = "Using a dict with renaming is not allowed" + with tm.assert_raises_regex(ValueError, msg): + g.agg({'C': {'ra': ['mean', 'std']}, + 'D': {'rb': ['mean', 'std']}}) def test_agg_item_by_item_raise_typeerror(): diff --git a/pandas/tests/groupby/test_groupby.py b/pandas/tests/groupby/test_groupby.py index 3cdd0965ccfd0..fab15a44fcb34 100644 --- a/pandas/tests/groupby/test_groupby.py +++ b/pandas/tests/groupby/test_groupby.py @@ -61,11 +61,11 @@ def test_basic(dtype): check_index_type=False) # complex agg - agged = grouped.aggregate([np.mean, np.std]) + grouped.aggregate([np.mean, np.std]) - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - agged = grouped.aggregate({'one': np.mean, 'two': np.std}) + msg = "Using a dict with renaming is not allowed" + with tm.assert_raises_regex(ValueError, msg): + grouped.aggregate({'one': np.mean, 'two': np.std}) group_constants = {0: 10, 1: 20, 2: 30} agged = grouped.agg(lambda x: group_constants[x.name] + x.mean()) @@ -444,11 +444,6 @@ def test_frame_set_name_single(df): result = grouped['C'].agg([np.mean, np.std]) assert result.index.name == 'A' - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - result = grouped['C'].agg({'foo': np.mean, 'bar': np.std}) - assert result.index.name == 'A' - def test_multi_func(df): col1 = df['A'] @@ -553,15 +548,6 @@ def test_groupby_as_index_agg(df): expected2['D'] = grouped.sum()['D'] assert_frame_equal(result2, expected2) - grouped = df.groupby('A', as_index=True) - expected3 = grouped['C'].sum() - expected3 = DataFrame(expected3).rename(columns={'C': 'Q'}) - - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - result3 = grouped['C'].agg({'Q': np.sum}) - assert_frame_equal(result3, expected3) - # multi-key grouped = df.groupby(['A', 'B'], as_index=False) diff --git a/pandas/tests/series/test_apply.py b/pandas/tests/series/test_apply.py index 62a677b82aeb4..1f9beab273fda 100644 --- a/pandas/tests/series/test_apply.py +++ b/pandas/tests/series/test_apply.py @@ -15,7 +15,7 @@ from pandas.util.testing import assert_frame_equal, assert_series_equal -class TestSeriesApply(): +class TestSeriesApply(object): def test_apply(self, datetime_series): with np.errstate(all='ignore'): @@ -153,16 +153,17 @@ def f(x): exp = pd.Series(['Asia/Tokyo'] * 25, name='XX') tm.assert_series_equal(result, exp) - def test_apply_dict_depr(self): + def test_apply_dict_fail(self): + ts_df = pd.DataFrame(np.random.randn(10, 3), + columns=["A", "B", "C"], + index=pd.date_range("1/1/2000", periods=10)) + msg = "Using a dict with renaming is not allowed" - tsdf = pd.DataFrame(np.random.randn(10, 3), - columns=['A', 'B', 'C'], - index=pd.date_range('1/1/2000', periods=10)) - with tm.assert_produces_warning(FutureWarning): - tsdf.A.agg({'foo': ['sum', 'mean']}) + with tm.assert_raises_regex(ValueError, msg): + ts_df.A.agg({'foo': ['sum', 'mean']}) -class TestSeriesAggregate(): +class TestSeriesAggregate(object): def test_transform(self, string_series): # transforming functions @@ -245,29 +246,12 @@ def test_demo(self): expected = Series([0], index=['foo'], name='series') tm.assert_series_equal(result, expected) - # nested renaming - with tm.assert_produces_warning(FutureWarning): - result = s.agg({'foo': ['min', 'max']}) + def test_multiple_agg_nested_rename_fail(self): + msg = "Using a dict with renaming is not allowed" + s = Series(range(6), dtype="int64", name="series") - expected = DataFrame( - {'foo': [0, 5]}, - index=['min', 'max']).unstack().rename('series') - tm.assert_series_equal(result, expected) - - def test_multiple_aggregators_with_dict_api(self): - - s = Series(range(6), dtype='int64', name='series') - # nested renaming - with tm.assert_produces_warning(FutureWarning): - result = s.agg({'foo': ['min', 'max'], 'bar': ['sum', 'mean']}) - - expected = DataFrame( - {'foo': [5.0, np.nan, 0.0, np.nan], - 'bar': [np.nan, 2.5, np.nan, 15.0]}, - columns=['foo', 'bar'], - index=['max', 'mean', - 'min', 'sum']).unstack().rename('series') - tm.assert_series_equal(result.reindex_like(expected), expected) + with tm.assert_raises_regex(ValueError, msg): + s.agg({"foo": ["min", "max"], "bar": ["sum", "mean"]}) def test_agg_apply_evaluate_lambdas_the_same(self, string_series): # test that we are evaluating row-by-row first @@ -412,7 +396,7 @@ def test_agg_cython_table_raises(self, series, func, expected): series.agg(func) -class TestSeriesMap(): +class TestSeriesMap(object): def test_map(self, datetime_series): index, data = tm.getMixedTypeDict() diff --git a/pandas/tests/test_resample.py b/pandas/tests/test_resample.py index 5cd31e08e0a9b..b2bbef5e2dc53 100644 --- a/pandas/tests/test_resample.py +++ b/pandas/tests/test_resample.py @@ -261,22 +261,6 @@ def test_apply_without_aggregation(self): result = t.apply(lambda x: x) assert_series_equal(result, self.series) - def test_agg_consistency(self): - - # make sure that we are consistent across - # similar aggregations with and w/o selection list - df = DataFrame(np.random.randn(1000, 3), - index=pd.date_range('1/1/2012', freq='S', periods=1000), - columns=['A', 'B', 'C']) - - r = df.resample('3T') - - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - expected = r[['A', 'B', 'C']].agg({'r1': 'mean', 'r2': 'sum'}) - result = r.agg({'r1': 'mean', 'r2': 'sum'}) - assert_frame_equal(result, expected) - # TODO: once GH 14008 is fixed, move these tests into # `Base` test class def test_agg(self): @@ -332,27 +316,6 @@ def test_agg(self): result = t['A'].aggregate(['mean', 'sum']) assert_frame_equal(result, expected) - expected = pd.concat([a_mean, a_sum], axis=1) - expected.columns = pd.MultiIndex.from_tuples([('A', 'mean'), - ('A', 'sum')]) - for t in cases: - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - result = t.aggregate({'A': {'mean': 'mean', 'sum': 'sum'}}) - assert_frame_equal(result, expected, check_like=True) - - expected = pd.concat([a_mean, a_sum, b_mean, b_sum], axis=1) - expected.columns = pd.MultiIndex.from_tuples([('A', 'mean'), - ('A', 'sum'), - ('B', 'mean2'), - ('B', 'sum2')]) - for t in cases: - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - result = t.aggregate({'A': {'mean': 'mean', 'sum': 'sum'}, - 'B': {'mean2': 'mean', 'sum2': 'sum'}}) - assert_frame_equal(result, expected, check_like=True) - expected = pd.concat([a_mean, a_std, b_mean, b_std], axis=1) expected.columns = pd.MultiIndex.from_tuples([('A', 'mean'), ('A', 'std'), @@ -398,24 +361,6 @@ def test_agg_misc(self): expected = pd.concat([r['A'].sum(), rcustom], axis=1) assert_frame_equal(result, expected, check_like=True) - # agg with renamers - expected = pd.concat([t['A'].sum(), - t['B'].sum(), - t['A'].mean(), - t['B'].mean()], - axis=1) - expected.columns = pd.MultiIndex.from_tuples([('result1', 'A'), - ('result1', 'B'), - ('result2', 'A'), - ('result2', 'B')]) - - for t in cases: - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - result = t[['A', 'B']].agg(OrderedDict([('result1', np.sum), - ('result2', np.mean)])) - assert_frame_equal(result, expected, check_like=True) - # agg with different hows expected = pd.concat([t['A'].sum(), t['A'].std(), @@ -437,31 +382,6 @@ def test_agg_misc(self): 'B': ['mean', 'std']}) assert_frame_equal(result, expected, check_like=True) - # series like aggs - for t in cases: - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - result = t['A'].agg({'A': ['sum', 'std']}) - expected = pd.concat([t['A'].sum(), - t['A'].std()], - axis=1) - expected.columns = pd.MultiIndex.from_tuples([('A', 'sum'), - ('A', 'std')]) - assert_frame_equal(result, expected, check_like=True) - - expected = pd.concat([t['A'].agg(['sum', 'std']), - t['A'].agg(['mean', 'std'])], - axis=1) - expected.columns = pd.MultiIndex.from_tuples([('A', 'sum'), - ('A', 'std'), - ('B', 'mean'), - ('B', 'std')]) - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - result = t['A'].agg({'A': ['sum', 'std'], - 'B': ['mean', 'std']}) - assert_frame_equal(result, expected, check_like=True) - # errors # invalid names in the agg specification for t in cases: @@ -498,24 +418,6 @@ def f(): 'r2': {'B': ['mean', 'sum']}}) pytest.raises(ValueError, f) - for t in cases: - expected = pd.concat([t['A'].mean(), t['A'].std(), t['B'].mean(), - t['B'].std()], axis=1) - expected.columns = pd.MultiIndex.from_tuples([('ra', 'mean'), ( - 'ra', 'std'), ('rb', 'mean'), ('rb', 'std')]) - - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - result = t[['A', 'B']].agg({'A': {'ra': ['mean', 'std']}, - 'B': {'rb': ['mean', 'std']}}) - assert_frame_equal(result, expected, check_like=True) - - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - result = t.agg({'A': {'ra': ['mean', 'std']}, - 'B': {'rb': ['mean', 'std']}}) - assert_frame_equal(result, expected, check_like=True) - def test_try_aggregate_non_existing_column(self): # GH 16766 data = [ diff --git a/pandas/tests/test_window.py b/pandas/tests/test_window.py index 4b0c4d581a008..46b4abfbcbc87 100644 --- a/pandas/tests/test_window.py +++ b/pandas/tests/test_window.py @@ -128,7 +128,6 @@ def test_agg(self): a_sum = r['A'].sum() b_mean = r['B'].mean() b_std = r['B'].std() - b_sum = r['B'].sum() result = r.aggregate([np.mean, np.std]) expected = concat([a_mean, a_std, b_mean, b_std], axis=1) @@ -152,26 +151,6 @@ def test_agg(self): expected.columns = ['mean', 'sum'] tm.assert_frame_equal(result, expected) - with catch_warnings(record=True): - # using a dict with renaming - warnings.simplefilter("ignore", FutureWarning) - result = r.aggregate({'A': {'mean': 'mean', 'sum': 'sum'}}) - expected = concat([a_mean, a_sum], axis=1) - expected.columns = pd.MultiIndex.from_tuples([('A', 'mean'), - ('A', 'sum')]) - tm.assert_frame_equal(result, expected, check_like=True) - - with catch_warnings(record=True): - warnings.simplefilter("ignore", FutureWarning) - result = r.aggregate({'A': {'mean': 'mean', - 'sum': 'sum'}, - 'B': {'mean2': 'mean', - 'sum2': 'sum'}}) - expected = concat([a_mean, a_sum, b_mean, b_sum], axis=1) - exp_cols = [('A', 'mean'), ('A', 'sum'), ('B', 'mean2'), ('B', 'sum2')] - expected.columns = pd.MultiIndex.from_tuples(exp_cols) - tm.assert_frame_equal(result, expected, check_like=True) - result = r.aggregate({'A': ['mean', 'std'], 'B': ['mean', 'std']}) expected = concat([a_mean, a_std, b_mean, b_std], axis=1) @@ -218,26 +197,16 @@ def test_agg_nested_dicts(self): def f(): r.aggregate({'r1': {'A': ['mean', 'sum']}, 'r2': {'B': ['mean', 'sum']}}) - pytest.raises(SpecificationError, f) - expected = concat([r['A'].mean(), r['A'].std(), - r['B'].mean(), r['B'].std()], axis=1) - expected.columns = pd.MultiIndex.from_tuples([('ra', 'mean'), ( - 'ra', 'std'), ('rb', 'mean'), ('rb', 'std')]) - with catch_warnings(record=True): - warnings.simplefilter("ignore", FutureWarning) - result = r[['A', 'B']].agg({'A': {'ra': ['mean', 'std']}, - 'B': {'rb': ['mean', 'std']}}) - tm.assert_frame_equal(result, expected, check_like=True) + msg = "Using a dict with renaming is not allowed" + with tm.assert_raises_regex(ValueError, msg): + r[['A', 'B']].agg({'A': {'ra': ['mean', 'std']}, + 'B': {'rb': ['mean', 'std']}}) - with catch_warnings(record=True): - warnings.simplefilter("ignore", FutureWarning) - result = r.agg({'A': {'ra': ['mean', 'std']}, - 'B': {'rb': ['mean', 'std']}}) - expected.columns = pd.MultiIndex.from_tuples([('A', 'ra', 'mean'), ( - 'A', 'ra', 'std'), ('B', 'rb', 'mean'), ('B', 'rb', 'std')]) - tm.assert_frame_equal(result, expected, check_like=True) + with tm.assert_raises_regex(ValueError, msg): + r.agg({'A': {'ra': ['mean', 'std']}, + 'B': {'rb': ['mean', 'std']}}) def test_count_nonnumeric_types(self): # GH12541