@@ -158,14 +158,19 @@ class providing the base-class of operations.
158
158
side-effects, as they will take effect twice for the first
159
159
group.
160
160
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
+
161
166
Examples
162
167
--------
163
168
{examples}
164
169
""" ,
165
170
"dataframe_examples" : """
166
171
>>> df = pd.DataFrame({'A': 'a a b'.split(),
167
172
... 'B': [1,2,3],
168
- ... 'C': [4,6, 5]})
173
+ ... 'C': [4,6,5]})
169
174
>>> g = df.groupby('A')
170
175
171
176
Notice that ``g`` has two groups, ``a`` and ``b``.
@@ -183,13 +188,17 @@ class providing the base-class of operations.
183
188
184
189
Example 2: The function passed to `apply` takes a DataFrame as
185
190
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
187
194
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
190
199
A
191
- a 1 2
192
- b 0 0
200
+ a 1.0 2.0
201
+ b 0.0 0. 0
193
202
194
203
Example 3: The function passed to `apply` takes a DataFrame as
195
204
its argument and returns a scalar. `apply` combines the result for
@@ -210,12 +219,16 @@ class providing the base-class of operations.
210
219
211
220
Example 1: The function passed to `apply` takes a Series as
212
221
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
214
225
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)
216
229
a 0.0
217
- a 0.5
218
- b 4 .0
230
+ a 2.0
231
+ b 1 .0
219
232
dtype: float64
220
233
221
234
Example 2: The function passed to `apply` takes a Series as
@@ -367,12 +380,17 @@ class providing the base-class of operations.
367
380
in the subframe. If f also supports application to the entire subframe,
368
381
then a fast path is used starting from the second chunk.
369
382
* 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.
371
384
372
385
When using ``engine='numba'``, there will be no "fall back" behavior internally.
373
386
The group data and group index will be passed as numpy arrays to the JITed
374
387
user defined function, and no alternative execution attempts will be tried.
375
388
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
+
376
394
Examples
377
395
--------
378
396
@@ -402,6 +420,20 @@ class providing the base-class of operations.
402
420
3 3 8.0
403
421
4 4 6.0
404
422
5 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
405
437
"""
406
438
407
439
_agg_template = """
@@ -469,12 +501,16 @@ class providing the base-class of operations.
469
501
When using ``engine='numba'``, there will be no "fall back" behavior internally.
470
502
The group data and group index will be passed as numpy arrays to the JITed
471
503
user defined function, and no alternative execution attempts will be tried.
472
- {examples}
473
504
474
505
Functions 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`
476
507
for 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}"""
478
514
479
515
480
516
@final
@@ -1232,9 +1268,6 @@ def _python_agg_general(self, func, *args, **kwargs):
1232
1268
assert result is not None
1233
1269
key = base .OutputKey (label = name , position = idx )
1234
1270
1235
- if is_numeric_dtype (obj .dtype ):
1236
- result = maybe_downcast_numeric (result , obj .dtype )
1237
-
1238
1271
if self .grouper ._filter_empty_groups :
1239
1272
mask = counts .ravel () > 0
1240
1273
0 commit comments