Skip to content

Commit 8cf618f

Browse files
DOC Modify docs for CR comments
1 parent d73f332 commit 8cf618f

File tree

2 files changed

+19
-59
lines changed

2 files changed

+19
-59
lines changed

doc/source/whatsnew/v0.18.1.txt

+17-59
Original file line numberDiff line numberDiff line change
@@ -77,77 +77,35 @@ API changes
7777

7878
- Using ``apply`` on resampling groupby operations (e.g. ``df.groupby(pd.TimeGrouper(freq='M', key='date')).apply(...)``) now has the same output types as similar ``apply``s on other groupby operations (e.g. ``df.groupby(pd.Grouper(key='color')).apply(...)``). (:issue:`11742`).
7979

80+
81+
New Behavior:
82+
83+
.. ipython:: python
84+
85+
df = pd.DataFrame({'date': pd.to_datetime(['10/10/2000', '11/10/2000']), 'value': [10, 13]})
86+
df
87+
# Output is a Series
88+
df.groupby(pd.TimeGrouper(key='date', freq='M')).apply(lambda x: x.value.sum())
89+
# Output is a DataFrame
90+
df.groupby(pd.TimeGrouper(key='date', freq='M')).apply(lambda x: x[['value']].sum())
91+
8092
Previous behavior:
8193

8294
.. code-block:: python
8395

84-
In [1]: df = pd.DataFrame({'date': pd.to_datetime(['10/10/2000', '11/10/2000']), 'value': [10, 13]})
85-
86-
In [2]: df.groupby(pd.TimeGrouper(key='date', freq='M')).apply(lambda x: x.value.sum())
87-
Out[2]:
96+
In [1]: df.groupby(pd.TimeGrouper(key='date', freq='M')).apply(lambda x: x.value.sum())
97+
Out[1]:
8898
...
8999
TypeError: cannot concatenate a non-NDFrame object
90100

91-
In [3]: df.groupby(pd.TimeGrouper(key='date', freq='M')).apply(lambda x: x[['value']].sum())
92-
Out[3]:
101+
# Output is a Series
102+
In [2]: df.groupby(pd.TimeGrouper(key='date', freq='M')).apply(lambda x: x[['value']].sum())
103+
Out[2]:
93104
date
94105
2000-10-31 value 10
95106
2000-11-30 value 13
96107
dtype: int64
97108

98-
In [3]: type(df.groupby(pd.TimeGrouper(key='date', freq='M')).apply(lambda x: x[['value']].sum()))
99-
Out[3]: pandas.core.series.Series
100-
101-
102-
In [4]: df.groupby(pd.Grouper(key='date')).apply(lambda x: x.value.sum())
103-
Out[4]:
104-
date
105-
2000-10-10 10
106-
2000-11-10 13
107-
dtype: int64
108-
109-
In [5]: type(df.groupby(pd.Grouper(key='date')).apply(lambda x: x.value.sum()))
110-
Out[5]: pandas.core.series.Series
111-
112-
113-
In [6]: df.groupby(pd.Grouper(key='date')).apply(lambda x: x[['value']].sum())
114-
Out[6]:
115-
value
116-
date
117-
2000-10-10 10
118-
2000-11-10 13
119-
120-
In [7]: type(df.groupby(pd.Grouper(key='date')).apply(lambda x: x[['value']].sum()))
121-
Out[7]: pandas.core.frame.DataFrame
122-
123-
124-
New Behavior:
125-
126-
.. code-block:: python
127-
128-
In [1]: df = pd.DataFrame({'date': pd.to_datetime(['10/10/2000', '11/10/2000']), 'value': [10, 13]})
129-
130-
In [2]: df.groupby(pd.TimeGrouper(key='date', freq='M')).apply(lambda x: x.value.sum())
131-
Out[2]:
132-
date
133-
2000-10-31 10
134-
2000-11-30 13
135-
Freq: M, dtype: int64
136-
137-
In [3]: type(df.groupby(pd.TimeGrouper(key='date', freq='M')).apply(lambda x: x.value.sum()))
138-
Out[3]: pandas.core.series.Series
139-
140-
141-
In [4]: df.groupby(pd.TimeGrouper(key='date', freq='M')).apply(lambda x: x[['value']].sum())
142-
Out[4]:
143-
value
144-
date
145-
2000-10-31 10
146-
2000-11-30 13
147-
148-
In [5]: type(df.groupby(pd.TimeGrouper(key='date', freq='M')).apply(lambda x: x[['value']].sum()))
149-
Out[5]: pandas.core.frame.DataFrame
150-
151109

152110
.. _whatsnew_0181.deprecations:
153111

pandas/tests/test_groupby.py

+2
Original file line numberDiff line numberDiff line change
@@ -4827,6 +4827,7 @@ def test_timegrouper_get_group(self):
48274827
def test_timegrouper_apply_return_type_series(self):
48284828
# Using `apply` with the `TimeGrouper` should give the
48294829
# same return type as an `apply` with a `Grouper`.
4830+
# Issue #11742
48304831
df = pd.DataFrame({'date': ['10/10/2000', '11/10/2000'],
48314832
'value': [10, 13]})
48324833
df_dt = df.copy()
@@ -4844,6 +4845,7 @@ def sumfunc_series(x):
48444845
def test_timegrouper_apply_return_type_value(self):
48454846
# Using `apply` with the `TimeGrouper` should give the
48464847
# same return type as an `apply` with a `Grouper`.
4848+
# Issue #11742
48474849
df = pd.DataFrame({'date': ['10/10/2000', '11/10/2000'],
48484850
'value': [10, 13]})
48494851
df_dt = df.copy()

0 commit comments

Comments
 (0)