Skip to content

Commit d87e564

Browse files
committed
docs & fix window test
1 parent 4fd24b4 commit d87e564

File tree

4 files changed

+36
-22
lines changed

4 files changed

+36
-22
lines changed

doc/source/whatsnew/v0.20.0.txt

+19-12
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,6 @@ Using ``.iloc``. Here we will get the location of the 'A' column, then use *posi
428428
df.iloc[[0, 2], df.columns.get_loc('A')]
429429

430430

431-
<<<<<<< c25fbde09272f369f280212e5216441d5975687c
432431
.. _whatsnew_0200.api_breaking.deprecate_panel:
433432

434433
Deprecate Panel
@@ -461,33 +460,41 @@ Convert to an xarray DataArray
461460
Deprecate groupby.agg() with a dictionary when renaming
462461
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
463462

464-
The ``.groupby(..).agg(..)`` syntax can accept a variable of inputs, including scalars, list, and a dictionary of column names to scalars or lists.
465-
This provides a useful syntax for constructing multiple (potentially different) aggregations for a groupby.
463+
The ``.groupby(..).agg(..)``, ``.rolling(..).agg(..)``, and ``.resample(..).agg(..)`` syntax can accept a variable of inputs, including scalars,
464+
list, and a dict of column names to scalars or lists. This provides a useful syntax for constructing multiple
465+
(potentially different) aggregations.
466466

467-
1) We are deprecating passing a dictionary to a grouped ``Series``. This allowed one to ``rename`` the resulting aggregation, but this had a completely different
468-
meaning that passing a dictionary to a grouped ``DataFrame``, which accepts column-to-aggregations.
469-
2) We are deprecating passing a dict-of-dict to a grouped ``DataFrame`` in a similar manner.
467+
However, ``.agg(..)`` can *also* accept a dict that allows 'renaming' of the result columns. This is a complicated and confusing syntax, as well as not consistent
468+
between ``Series`` and ``DataFrame``. We are deprecating this 'renaming' functionarility.
470469

471-
Here's an example of 1), passing a dict to a grouped ``Series``:
470+
1) We are deprecating passing a dict to a grouped/rolled/resampled ``Series``. This allowed
471+
one to ``rename`` the resulting aggregation, but this had a completely different
472+
meaning than passing a dictionary to a grouped ``DataFrame``, which accepts column-to-aggregations.
473+
2) We are deprecating passing a dict-of-dict to a grouped/rolled/resampled ``DataFrame`` in a similar manner.
474+
475+
This is an illustrative example:
472476

473477
.. ipython:: python
474478

475479
df = pd.DataFrame({'A': [1, 1, 1, 2, 2],
476480
'B': range(5),
477-
'C':range(5)})
481+
'C': range(5)})
478482
df
479483

480-
Aggregating a DataFrame with column selection.
484+
Here is a typical useful syntax for computing different aggregations for different columns. This
485+
is a natural (and useful) syntax. We aggregate from the dict-to-list by taking the specified
486+
columns and applying the list of functions. This returns a ``MultiIndex`` for the columns.
481487

482488
.. ipython:: python
483489

484490
df.groupby('A').agg({'B': ['sum', 'max'],
485491
'C': ['count', 'min']})
486492

487493

488-
We are deprecating the following
494+
Here's an example of the first deprecation (1), passing a dict to a grouped ``Series``. This
495+
is a combination aggregation & renaming:
489496

490-
.. code-block:: ipython. Which is a combination aggregation & renaming.
497+
.. code-block:: ipython
491498

492499
In [6]: df.groupby('A').B.agg({'foo': 'count'})
493500
FutureWarning: using a dictionary on a Series for aggregation
@@ -506,7 +513,7 @@ You can accomplish the same operation, more idiomatically by:
506513
df.groupby('A').B.agg(['count']).rename({'count': 'foo'})
507514

508515

509-
Here's an example of 2), passing a dict-of-dict to a grouped ``DataFrame``:
516+
Here's an example of the second deprecation (2), passing a dict-of-dict to a grouped ``DataFrame``:
510517

511518
.. code-block:: python
512519

pandas/core/base.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,7 @@ def _aggregate(self, arg, *args, **kwargs):
497497
'dictionary'.format(k))
498498

499499
# deprecation of nested renaming
500+
# GH 15931
500501
warnings.warn(
501502
("using a dict with renaming "
502503
"is deprecated and will be removed in a future "
@@ -506,7 +507,8 @@ def _aggregate(self, arg, *args, **kwargs):
506507
arg = new_arg
507508

508509
else:
509-
# we may have renaming keys
510+
# deprecation of renaming keys
511+
# GH 15931
510512
keys = list(compat.iterkeys(arg))
511513
if (isinstance(obj, ABCDataFrame) and
512514
len(obj.columns.intersection(keys)) != len(keys)):

pandas/core/groupby.py

+1
Original file line numberDiff line numberDiff line change
@@ -2837,6 +2837,7 @@ def _aggregate_multiple_funcs(self, arg, _level):
28372837

28382838
# show the deprecation, but only if we
28392839
# have not shown a higher level one
2840+
# GH 15931
28402841
if isinstance(self._selected_obj, Series) and _level <= 1:
28412842
warnings.warn(
28422843
("using a dict on a Series for aggregation\n"

pandas/tests/test_window.py

+13-9
Original file line numberDiff line numberDiff line change
@@ -134,16 +134,18 @@ def test_agg(self):
134134
expected.columns = ['mean', 'sum']
135135
tm.assert_frame_equal(result, expected)
136136

137-
result = r.aggregate({'A': {'mean': 'mean', 'sum': 'sum'}})
137+
with catch_warnings(record=True):
138+
result = r.aggregate({'A': {'mean': 'mean', 'sum': 'sum'}})
138139
expected = pd.concat([a_mean, a_sum], axis=1)
139140
expected.columns = pd.MultiIndex.from_tuples([('A', 'mean'),
140141
('A', 'sum')])
141142
tm.assert_frame_equal(result, expected, check_like=True)
142143

143-
result = r.aggregate({'A': {'mean': 'mean',
144-
'sum': 'sum'},
145-
'B': {'mean2': 'mean',
146-
'sum2': 'sum'}})
144+
with catch_warnings(record=True):
145+
result = r.aggregate({'A': {'mean': 'mean',
146+
'sum': 'sum'},
147+
'B': {'mean2': 'mean',
148+
'sum2': 'sum'}})
147149
expected = pd.concat([a_mean, a_sum, b_mean, b_sum], axis=1)
148150
exp_cols = [('A', 'mean'), ('A', 'sum'), ('B', 'mean2'), ('B', 'sum2')]
149151
expected.columns = pd.MultiIndex.from_tuples(exp_cols)
@@ -195,12 +197,14 @@ def f():
195197
r['B'].std()], axis=1)
196198
expected.columns = pd.MultiIndex.from_tuples([('ra', 'mean'), (
197199
'ra', 'std'), ('rb', 'mean'), ('rb', 'std')])
198-
result = r[['A', 'B']].agg({'A': {'ra': ['mean', 'std']},
199-
'B': {'rb': ['mean', 'std']}})
200+
with catch_warnings(record=True):
201+
result = r[['A', 'B']].agg({'A': {'ra': ['mean', 'std']},
202+
'B': {'rb': ['mean', 'std']}})
200203
tm.assert_frame_equal(result, expected, check_like=True)
201204

202-
result = r.agg({'A': {'ra': ['mean', 'std']},
203-
'B': {'rb': ['mean', 'std']}})
205+
with catch_warnings(record=True):
206+
result = r.agg({'A': {'ra': ['mean', 'std']},
207+
'B': {'rb': ['mean', 'std']}})
204208
expected.columns = pd.MultiIndex.from_tuples([('A', 'ra', 'mean'), (
205209
'A', 'ra', 'std'), ('B', 'rb', 'mean'), ('B', 'rb', 'std')])
206210
tm.assert_frame_equal(result, expected, check_like=True)

0 commit comments

Comments
 (0)