Skip to content

Commit 6e91a22

Browse files
authored
CLN: some cleanups in Series.apply & related (#52786)
CLN: some cleanups in Series.qpply & related
1 parent d25d768 commit 6e91a22

File tree

3 files changed

+22
-17
lines changed

3 files changed

+22
-17
lines changed

pandas/core/apply.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
from pandas._config import option_context
2727

28+
from pandas._libs import lib
2829
from pandas._typing import (
2930
AggFuncType,
3031
AggFuncTypeBase,
@@ -110,6 +111,7 @@ def __init__(
110111
func,
111112
raw: bool,
112113
result_type: str | None,
114+
*,
113115
args,
114116
kwargs,
115117
) -> None:
@@ -1037,10 +1039,21 @@ def __init__(
10371039
self,
10381040
obj: Series,
10391041
func: AggFuncType,
1040-
convert_dtype: bool,
1042+
*,
1043+
convert_dtype: bool | lib.NoDefault = lib.no_default,
10411044
args,
10421045
kwargs,
10431046
) -> None:
1047+
if convert_dtype is lib.no_default:
1048+
convert_dtype = True
1049+
else:
1050+
warnings.warn(
1051+
"the convert_dtype parameter is deprecated and will be removed in a "
1052+
"future version. Do ``ser.astype(object).apply()`` "
1053+
"instead if you want ``convert_dtype=False``.",
1054+
FutureWarning,
1055+
stacklevel=find_stack_level(),
1056+
)
10441057
self.convert_dtype = convert_dtype
10451058

10461059
super().__init__(
@@ -1143,6 +1156,7 @@ def __init__(
11431156
self,
11441157
obj: GroupBy[NDFrameT],
11451158
func: AggFuncType,
1159+
*,
11461160
args,
11471161
kwargs,
11481162
) -> None:
@@ -1172,6 +1186,7 @@ def __init__(
11721186
self,
11731187
obj: Resampler | BaseWindow,
11741188
func: AggFuncType,
1189+
*,
11751190
args,
11761191
kwargs,
11771192
) -> None:

pandas/core/groupby/generic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1329,7 +1329,7 @@ def aggregate(self, func=None, *args, engine=None, engine_kwargs=None, **kwargs)
13291329
relabeling, func, columns, order = reconstruct_func(func, **kwargs)
13301330
func = maybe_mangle_lambdas(func)
13311331

1332-
op = GroupByApply(self, func, args, kwargs)
1332+
op = GroupByApply(self, func, args=args, kwargs=kwargs)
13331333
result = op.agg()
13341334
if not is_dict_like(func) and result is not None:
13351335
return result

pandas/core/series.py

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4368,7 +4368,7 @@ def aggregate(self, func=None, axis: Axis = 0, *args, **kwargs):
43684368
if func is None:
43694369
func = dict(kwargs.items())
43704370

4371-
op = SeriesApply(self, func, convert_dtype=False, args=args, kwargs=kwargs)
4371+
op = SeriesApply(self, func, args=args, kwargs=kwargs)
43724372
result = op.agg()
43734373
return result
43744374

@@ -4384,9 +4384,7 @@ def transform(
43844384
) -> DataFrame | Series:
43854385
# Validate axis argument
43864386
self._get_axis_number(axis)
4387-
result = SeriesApply(
4388-
self, func=func, convert_dtype=True, args=args, kwargs=kwargs
4389-
).transform()
4387+
result = SeriesApply(self, func=func, args=args, kwargs=kwargs).transform()
43904388
return result
43914389

43924390
def apply(
@@ -4508,17 +4506,9 @@ def apply(
45084506
Helsinki 2.484907
45094507
dtype: float64
45104508
"""
4511-
if convert_dtype is lib.no_default:
4512-
convert_dtype = True
4513-
else:
4514-
warnings.warn(
4515-
"the convert_dtype parameter is deprecated and will be removed in a "
4516-
"future version. Do ``ser.astype(object).apply()`` "
4517-
"instead if you want ``convert_dtype=False``.",
4518-
FutureWarning,
4519-
stacklevel=find_stack_level(),
4520-
)
4521-
return SeriesApply(self, func, convert_dtype, args, kwargs).apply()
4509+
return SeriesApply(
4510+
self, func, convert_dtype=convert_dtype, args=args, kwargs=kwargs
4511+
).apply()
45224512

45234513
def _reindex_indexer(
45244514
self,

0 commit comments

Comments
 (0)