Skip to content

Commit 7262515

Browse files
committed
docs & fix window test
1 parent 29f3ae6 commit 7262515

File tree

4 files changed

+36
-22
lines changed

4 files changed

+36
-22
lines changed

doc/source/whatsnew/v0.20.0.txt

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

431431

432-
<<<<<<< c25fbde09272f369f280212e5216441d5975687c
433432
.. _whatsnew_0200.api_breaking.deprecate_panel:
434433

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

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

468-
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
469-
meaning that passing a dictionary to a grouped ``DataFrame``, which accepts column-to-aggregations.
470-
2) We are deprecating passing a dict-of-dict to a grouped ``DataFrame`` in a similar manner.
468+
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
469+
between ``Series`` and ``DataFrame``. We are deprecating this 'renaming' functionarility.
471470

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

474478
.. ipython:: python
475479

476480
df = pd.DataFrame({'A': [1, 1, 1, 2, 2],
477481
'B': range(5),
478-
'C':range(5)})
482+
'C': range(5)})
479483
df
480484

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

483489
.. ipython:: python
484490

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

488494

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

491-
.. code-block:: ipython. Which is a combination aggregation & renaming.
498+
.. code-block:: ipython
492499

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

509516

510-
Here's an example of 2), passing a dict-of-dict to a grouped ``DataFrame``:
517+
Here's an example of the second deprecation (2), passing a dict-of-dict to a grouped ``DataFrame``:
511518

512519
.. code-block:: python
513520

pandas/core/base.py

Lines changed: 3 additions & 1 deletion
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 13 additions & 9 deletions
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)