Skip to content

Commit 1d7670f

Browse files
arw2019luckyvs1
authored andcommitted
TYP: func argument to DataFrame.apply, DataFrame.applymap, core.apply.frame_apply (pandas-dev#38493)
1 parent caa2de5 commit 1d7670f

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

pandas/_typing.py

+2
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@
133133
"Resampler",
134134
]
135135

136+
PythonFuncType = Callable[[Any], Any]
137+
136138
# filenames and file-like-objects
137139
Buffer = Union[IO[AnyStr], RawIOBase, BufferedIOBase, TextIOBase, TextIOWrapper, mmap]
138140
FileOrBuffer = Union[str, Buffer[T]]

pandas/core/apply.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
from pandas._config import option_context
88

9-
from pandas._typing import Axis, FrameOrSeriesUnion
9+
from pandas._typing import AggFuncType, Axis, FrameOrSeriesUnion
1010
from pandas.util._decorators import cache_readonly
1111

1212
from pandas.core.dtypes.common import (
@@ -27,7 +27,7 @@
2727

2828
def frame_apply(
2929
obj: "DataFrame",
30-
func,
30+
func: AggFuncType,
3131
axis: Axis = 0,
3232
raw: bool = False,
3333
result_type: Optional[str] = None,

pandas/core/frame.py

+11-2
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
IndexLabel,
6363
Label,
6464
Level,
65+
PythonFuncType,
6566
Renamer,
6667
StorageOptions,
6768
Suffixes,
@@ -7661,7 +7662,13 @@ def transform(
76617662
return result
76627663

76637664
def apply(
7664-
self, func, axis: Axis = 0, raw: bool = False, result_type=None, args=(), **kwds
7665+
self,
7666+
func: AggFuncType,
7667+
axis: Axis = 0,
7668+
raw: bool = False,
7669+
result_type=None,
7670+
args=(),
7671+
**kwds,
76657672
):
76667673
"""
76677674
Apply a function along an axis of the DataFrame.
@@ -7807,7 +7814,9 @@ def apply(
78077814
)
78087815
return op.get_result()
78097816

7810-
def applymap(self, func, na_action: Optional[str] = None) -> DataFrame:
7817+
def applymap(
7818+
self, func: PythonFuncType, na_action: Optional[str] = None
7819+
) -> DataFrame:
78117820
"""
78127821
Apply a function to a Dataframe elementwise.
78137822

0 commit comments

Comments
 (0)