diff --git a/pandas/core/apply.py b/pandas/core/apply.py index 274a389791a31..a4f2ba9133928 100644 --- a/pandas/core/apply.py +++ b/pandas/core/apply.py @@ -25,6 +25,7 @@ from pandas._config import option_context +from pandas._libs import lib from pandas._typing import ( AggFuncType, AggFuncTypeBase, @@ -110,6 +111,7 @@ def __init__( func, raw: bool, result_type: str | None, + *, args, kwargs, ) -> None: @@ -1037,10 +1039,21 @@ def __init__( self, obj: Series, func: AggFuncType, - convert_dtype: bool, + *, + convert_dtype: bool | lib.NoDefault = lib.no_default, args, kwargs, ) -> None: + if convert_dtype is lib.no_default: + convert_dtype = True + else: + warnings.warn( + "the convert_dtype parameter is deprecated and will be removed in a " + "future version. Do ``ser.astype(object).apply()`` " + "instead if you want ``convert_dtype=False``.", + FutureWarning, + stacklevel=find_stack_level(), + ) self.convert_dtype = convert_dtype super().__init__( @@ -1143,6 +1156,7 @@ def __init__( self, obj: GroupBy[NDFrameT], func: AggFuncType, + *, args, kwargs, ) -> None: @@ -1172,6 +1186,7 @@ def __init__( self, obj: Resampler | BaseWindow, func: AggFuncType, + *, args, kwargs, ) -> None: diff --git a/pandas/core/groupby/generic.py b/pandas/core/groupby/generic.py index c9ce9d4acde8d..2b68c002fe49f 100644 --- a/pandas/core/groupby/generic.py +++ b/pandas/core/groupby/generic.py @@ -1329,7 +1329,7 @@ def aggregate(self, func=None, *args, engine=None, engine_kwargs=None, **kwargs) relabeling, func, columns, order = reconstruct_func(func, **kwargs) func = maybe_mangle_lambdas(func) - op = GroupByApply(self, func, args, kwargs) + op = GroupByApply(self, func, args=args, kwargs=kwargs) result = op.agg() if not is_dict_like(func) and result is not None: return result diff --git a/pandas/core/series.py b/pandas/core/series.py index adb16c2f2dd55..67f462a1cfbde 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -4365,7 +4365,7 @@ def aggregate(self, func=None, axis: Axis = 0, *args, **kwargs): if func is None: func = dict(kwargs.items()) - op = SeriesApply(self, func, convert_dtype=False, args=args, kwargs=kwargs) + op = SeriesApply(self, func, args=args, kwargs=kwargs) result = op.agg() return result @@ -4381,9 +4381,7 @@ def transform( ) -> DataFrame | Series: # Validate axis argument self._get_axis_number(axis) - result = SeriesApply( - self, func=func, convert_dtype=True, args=args, kwargs=kwargs - ).transform() + result = SeriesApply(self, func=func, args=args, kwargs=kwargs).transform() return result def apply( @@ -4505,17 +4503,9 @@ def apply( Helsinki 2.484907 dtype: float64 """ - if convert_dtype is lib.no_default: - convert_dtype = True - else: - warnings.warn( - "the convert_dtype parameter is deprecated and will be removed in a " - "future version. Do ``ser.astype(object).apply()`` " - "instead if you want ``convert_dtype=False``.", - FutureWarning, - stacklevel=find_stack_level(), - ) - return SeriesApply(self, func, convert_dtype, args, kwargs).apply() + return SeriesApply( + self, func, convert_dtype=convert_dtype, args=args, kwargs=kwargs + ).apply() def _reindex_indexer( self,