@@ -158,14 +158,19 @@ class providing the base-class of operations.
158158 side-effects, as they will take effect twice for the first
159159 group.
160160
161+ .. versionchanged:: 1.3.0
162+
163+ The resulting dtype will reflect the return value of the passed ``func``,
164+ see the examples below.
165+
161166 Examples
162167 --------
163168 {examples}
164169 """ ,
165170 "dataframe_examples" : """
166171 >>> df = pd.DataFrame({'A': 'a a b'.split(),
167172 ... 'B': [1,2,3],
168- ... 'C': [4,6, 5]})
173+ ... 'C': [4,6,5]})
169174 >>> g = df.groupby('A')
170175
171176 Notice that ``g`` has two groups, ``a`` and ``b``.
@@ -183,13 +188,17 @@ class providing the base-class of operations.
183188
184189 Example 2: The function passed to `apply` takes a DataFrame as
185190 its argument and returns a Series. `apply` combines the result for
186- each group together into a new DataFrame:
191+ each group together into a new DataFrame.
192+
193+ .. versionchanged:: 1.3.0
187194
188- >>> g[['B', 'C']].apply(lambda x: x.max() - x.min())
189- B C
195+ The resulting dtype will reflect the return value of the passed ``func``.
196+
197+ >>> g[['B', 'C']].apply(lambda x: x.astype(float).max() - x.min())
198+ B C
190199 A
191- a 1 2
192- b 0 0
200+ a 1.0 2.0
201+ b 0.0 0. 0
193202
194203 Example 3: The function passed to `apply` takes a DataFrame as
195204 its argument and returns a scalar. `apply` combines the result for
@@ -210,12 +219,16 @@ class providing the base-class of operations.
210219
211220 Example 1: The function passed to `apply` takes a Series as
212221 its argument and returns a Series. `apply` combines the result for
213- each group together into a new Series:
222+ each group together into a new Series.
223+
224+ .. versionchanged:: 1.3.0
214225
215- >>> g.apply(lambda x: x*2 if x.name == 'b' else x/2)
226+ The resulting dtype will reflect the return value of the passed ``func``.
227+
228+ >>> g.apply(lambda x: x*2 if x.name == 'a' else x/2)
216229 a 0.0
217- a 0.5
218- b 4 .0
230+ a 2.0
231+ b 1 .0
219232 dtype: float64
220233
221234 Example 2: The function passed to `apply` takes a Series as
@@ -367,12 +380,17 @@ class providing the base-class of operations.
367380 in the subframe. If f also supports application to the entire subframe,
368381 then a fast path is used starting from the second chunk.
369382* f must not mutate groups. Mutation is not supported and may
370- produce unexpected results. See :ref:`udf-mutation` for more details.
383+ produce unexpected results. See :ref:`gotchas. udf-mutation` for more details.
371384
372385When using ``engine='numba'``, there will be no "fall back" behavior internally.
373386The group data and group index will be passed as numpy arrays to the JITed
374387user defined function, and no alternative execution attempts will be tried.
375388
389+ .. versionchanged:: 1.3.0
390+
391+ The resulting dtype will reflect the return value of the passed ``func``,
392+ see the examples below.
393+
376394Examples
377395--------
378396
@@ -402,6 +420,20 @@ class providing the base-class of operations.
4024203 3 8.0
4034214 4 6.0
4044225 3 8.0
423+
424+ .. versionchanged:: 1.3.0
425+
426+ The resulting dtype will reflect the return value of the passed ``func``,
427+ for example:
428+
429+ >>> grouped[['C', 'D']].transform(lambda x: x.astype(int).max())
430+ C D
431+ 0 5 8
432+ 1 5 9
433+ 2 5 8
434+ 3 5 9
435+ 4 5 8
436+ 5 5 9
405437"""
406438
407439_agg_template = """
@@ -469,12 +501,16 @@ class providing the base-class of operations.
469501When using ``engine='numba'``, there will be no "fall back" behavior internally.
470502The group data and group index will be passed as numpy arrays to the JITed
471503user defined function, and no alternative execution attempts will be tried.
472- {examples}
473504
474505Functions that mutate the passed object can produce unexpected
475- behavior or errors and are not supported. See :ref:`udf-mutation`
506+ behavior or errors and are not supported. See :ref:`gotchas. udf-mutation`
476507for more details.
477- """
508+
509+ .. versionchanged:: 1.3.0
510+
511+ The resulting dtype will reflect the return value of the passed ``func``,
512+ see the examples below.
513+ {examples}"""
478514
479515
480516@final
@@ -1232,9 +1268,6 @@ def _python_agg_general(self, func, *args, **kwargs):
12321268 assert result is not None
12331269 key = base .OutputKey (label = name , position = idx )
12341270
1235- if is_numeric_dtype (obj .dtype ):
1236- result = maybe_downcast_numeric (result , obj .dtype )
1237-
12381271 if self .grouper ._filter_empty_groups :
12391272 mask = counts .ravel () > 0
12401273
0 commit comments