@@ -1393,7 +1393,7 @@ def _aggregate_with_numba(self, func, *args, engine_kwargs=None, **kwargs):
1393
1393
# -----------------------------------------------------------------
1394
1394
# apply/agg/transform
1395
1395
1396
- def apply (self , func , * args , include_groups : bool = True , ** kwargs ) -> NDFrameT :
1396
+ def apply (self , func , * args , include_groups : bool = False , ** kwargs ) -> NDFrameT :
1397
1397
"""
1398
1398
Apply function ``func`` group-wise and combine the results together.
1399
1399
@@ -1419,18 +1419,17 @@ def apply(self, func, *args, include_groups: bool = True, **kwargs) -> NDFrameT:
1419
1419
*args : tuple
1420
1420
Optional positional arguments to pass to ``func``.
1421
1421
1422
- include_groups : bool, default True
1422
+ include_groups : bool, default False
1423
1423
When True, will attempt to apply ``func`` to the groupings in
1424
1424
the case that they are columns of the DataFrame. If this raises a
1425
1425
TypeError, the result will be computed with the groupings excluded.
1426
1426
When False, the groupings will be excluded when applying ``func``.
1427
1427
1428
1428
.. versionadded:: 2.2.0
1429
1429
1430
- .. deprecated :: 2.2 .0
1430
+ .. versionchanged :: 3.0 .0
1431
1431
1432
- Setting include_groups to True is deprecated. Only the value
1433
- False will be allowed in a future version of pandas.
1432
+ The default changed from True to False, and True is no longer allowed.
1434
1433
1435
1434
**kwargs : dict
1436
1435
Optional keyword arguments to pass to ``func``.
@@ -1520,7 +1519,7 @@ def apply(self, func, *args, include_groups: bool = True, **kwargs) -> NDFrameT:
1520
1519
each group together into a Series, including setting the index as
1521
1520
appropriate:
1522
1521
1523
- >>> g1.apply(lambda x: x.C.max() - x.B.min(), include_groups=False )
1522
+ >>> g1.apply(lambda x: x.C.max() - x.B.min())
1524
1523
A
1525
1524
a 5
1526
1525
b 2
@@ -1529,11 +1528,13 @@ def apply(self, func, *args, include_groups: bool = True, **kwargs) -> NDFrameT:
1529
1528
Example 4: The function passed to ``apply`` returns ``None`` for one of the
1530
1529
group. This group is filtered from the result:
1531
1530
1532
- >>> g1.apply(lambda x: None if x.iloc[0, 0] == 3 else x, include_groups=False )
1531
+ >>> g1.apply(lambda x: None if x.iloc[0, 0] == 3 else x)
1533
1532
B C
1534
1533
0 1 4
1535
1534
1 2 6
1536
1535
"""
1536
+ if include_groups :
1537
+ raise ValueError ("include_groups=True is no longer allowed." )
1537
1538
if isinstance (func , str ):
1538
1539
if hasattr (self , func ):
1539
1540
res = getattr (self , func )
@@ -1560,33 +1561,7 @@ def f(g):
1560
1561
else :
1561
1562
f = func
1562
1563
1563
- if not include_groups :
1564
- return self ._python_apply_general (f , self ._obj_with_exclusions )
1565
-
1566
- try :
1567
- result = self ._python_apply_general (f , self ._selected_obj )
1568
- if (
1569
- not isinstance (self .obj , Series )
1570
- and self ._selection is None
1571
- and self ._selected_obj .shape != self ._obj_with_exclusions .shape
1572
- ):
1573
- warnings .warn (
1574
- message = _apply_groupings_depr .format (type (self ).__name__ , "apply" ),
1575
- category = DeprecationWarning ,
1576
- stacklevel = find_stack_level (),
1577
- )
1578
- except TypeError :
1579
- # gh-20949
1580
- # try again, with .apply acting as a filtering
1581
- # operation, by excluding the grouping column
1582
- # This would normally not be triggered
1583
- # except if the udf is trying an operation that
1584
- # fails on *some* columns, e.g. a numeric operation
1585
- # on a string grouper column
1586
-
1587
- return self ._python_apply_general (f , self ._obj_with_exclusions )
1588
-
1589
- return result
1564
+ return self ._python_apply_general (f , self ._obj_with_exclusions )
1590
1565
1591
1566
@final
1592
1567
def _python_apply_general (
@@ -3424,7 +3399,9 @@ def describe(
3424
3399
return result
3425
3400
3426
3401
@final
3427
- def resample (self , rule , * args , include_groups : bool = True , ** kwargs ) -> Resampler :
3402
+ def resample (
3403
+ self , rule , * args , include_groups : bool = False , ** kwargs
3404
+ ) -> Resampler :
3428
3405
"""
3429
3406
Provide resampling when using a TimeGrouper.
3430
3407
@@ -3449,10 +3426,9 @@ def resample(self, rule, *args, include_groups: bool = True, **kwargs) -> Resamp
3449
3426
3450
3427
.. versionadded:: 2.2.0
3451
3428
3452
- .. deprecated :: 2.2 .0
3429
+ .. versionchanged :: 3 .0
3453
3430
3454
- Setting include_groups to True is deprecated. Only the value
3455
- False will be allowed in a future version of pandas.
3431
+ The default was changed to False, and True is no longer allowed.
3456
3432
3457
3433
**kwargs
3458
3434
Possible arguments are `how`, `fill_method`, `limit`, `kind` and
@@ -3485,7 +3461,7 @@ def resample(self, rule, *args, include_groups: bool = True, **kwargs) -> Resamp
3485
3461
Downsample the DataFrame into 3 minute bins and sum the values of
3486
3462
the timestamps falling into a bin.
3487
3463
3488
- >>> df.groupby("a").resample("3min", include_groups=False ).sum()
3464
+ >>> df.groupby("a").resample("3min").sum()
3489
3465
b
3490
3466
a
3491
3467
0 2000-01-01 00:00:00 2
@@ -3494,7 +3470,7 @@ def resample(self, rule, *args, include_groups: bool = True, **kwargs) -> Resamp
3494
3470
3495
3471
Upsample the series into 30 second bins.
3496
3472
3497
- >>> df.groupby("a").resample("30s", include_groups=False ).sum()
3473
+ >>> df.groupby("a").resample("30s").sum()
3498
3474
b
3499
3475
a
3500
3476
0 2000-01-01 00:00:00 1
@@ -3508,7 +3484,7 @@ def resample(self, rule, *args, include_groups: bool = True, **kwargs) -> Resamp
3508
3484
3509
3485
Resample by month. Values are assigned to the month of the period.
3510
3486
3511
- >>> df.groupby("a").resample("ME", include_groups=False ).sum()
3487
+ >>> df.groupby("a").resample("ME").sum()
3512
3488
b
3513
3489
a
3514
3490
0 2000-01-31 3
@@ -3517,11 +3493,7 @@ def resample(self, rule, *args, include_groups: bool = True, **kwargs) -> Resamp
3517
3493
Downsample the series into 3 minute bins as above, but close the right
3518
3494
side of the bin interval.
3519
3495
3520
- >>> (
3521
- ... df.groupby("a")
3522
- ... .resample("3min", closed="right", include_groups=False)
3523
- ... .sum()
3524
- ... )
3496
+ >>> (df.groupby("a").resample("3min", closed="right").sum())
3525
3497
b
3526
3498
a
3527
3499
0 1999-12-31 23:57:00 1
@@ -3532,11 +3504,7 @@ def resample(self, rule, *args, include_groups: bool = True, **kwargs) -> Resamp
3532
3504
the bin interval, but label each bin using the right edge instead of
3533
3505
the left.
3534
3506
3535
- >>> (
3536
- ... df.groupby("a")
3537
- ... .resample("3min", closed="right", label="right", include_groups=False)
3538
- ... .sum()
3539
- ... )
3507
+ >>> (df.groupby("a").resample("3min", closed="right", label="right").sum())
3540
3508
b
3541
3509
a
3542
3510
0 2000-01-01 00:00:00 1
@@ -3545,11 +3513,10 @@ def resample(self, rule, *args, include_groups: bool = True, **kwargs) -> Resamp
3545
3513
"""
3546
3514
from pandas .core .resample import get_resampler_for_grouping
3547
3515
3548
- # mypy flags that include_groups could be specified via `*args` or `**kwargs`
3549
- # GH#54961 would resolve.
3550
- return get_resampler_for_grouping ( # type: ignore[misc]
3551
- self , rule , * args , include_groups = include_groups , ** kwargs
3552
- )
3516
+ if include_groups :
3517
+ raise ValueError ("include_groups=True is no longer allowed." )
3518
+
3519
+ return get_resampler_for_grouping (self , rule , * args , ** kwargs )
3553
3520
3554
3521
@final
3555
3522
def rolling (
@@ -5561,13 +5528,3 @@ def _insert_quantile_level(idx: Index, qs: npt.NDArray[np.float64]) -> MultiInde
5561
5528
mi = MultiIndex (levels = levels , codes = codes , names = [idx .name , None ])
5562
5529
5563
5530
return mi
5564
-
5565
-
5566
- # GH#7155
5567
- _apply_groupings_depr = (
5568
- "{}.{} operated on the grouping columns. This behavior is deprecated, "
5569
- "and in a future version of pandas the grouping columns will be excluded "
5570
- "from the operation. Either pass `include_groups=False` to exclude the "
5571
- "groupings or explicitly select the grouping columns after groupby to silence "
5572
- "this warning."
5573
- )
0 commit comments