From f4e5d0da0dd5f5aac3293bcc9dad4f73f1282d61 Mon Sep 17 00:00:00 2001 From: Andrew Wieteska Date: Tue, 15 Dec 2020 01:38:18 -0500 Subject: [PATCH 1/6] add ApplyFuncType alias --- pandas/_typing.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pandas/_typing.py b/pandas/_typing.py index 924fc323584b0..0f1ab544b2382 100644 --- a/pandas/_typing.py +++ b/pandas/_typing.py @@ -131,6 +131,7 @@ "BaseWindow", "Resampler", ] +ApplyFuncType = Union[np.ufunc, AggFuncType] # filenames and file-like-objects Buffer = Union[IO[AnyStr], RawIOBase, BufferedIOBase, TextIOBase, TextIOWrapper, mmap] From 3f85df4fef69634a1f9a85389cf047c8d9182baf Mon Sep 17 00:00:00 2001 From: Andrew Wieteska Date: Tue, 15 Dec 2020 01:39:21 -0500 Subject: [PATCH 2/6] type func arg of DataFrame.apply --- pandas/core/frame.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index f79e459362d7b..cd3ec2838bfd9 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -48,6 +48,7 @@ from pandas._libs.lib import no_default from pandas._typing import ( AggFuncType, + ApplyFuncType, ArrayLike, Axes, Axis, @@ -7656,7 +7657,13 @@ def transform( return result def apply( - self, func, axis: Axis = 0, raw: bool = False, result_type=None, args=(), **kwds + self, + func: ApplyFuncType, + axis: Axis = 0, + raw: bool = False, + result_type=None, + args=(), + **kwds, ): """ Apply a function along an axis of the DataFrame. From d2d1b49a89ef16ea6f9cdcc16d6f5e5575f0447f Mon Sep 17 00:00:00 2001 From: Andrew Wieteska Date: Tue, 15 Dec 2020 01:40:27 -0500 Subject: [PATCH 3/6] type func arg of core.apply.frame_apply --- pandas/core/apply.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/core/apply.py b/pandas/core/apply.py index 801d4665f9a1b..5508d9103d370 100644 --- a/pandas/core/apply.py +++ b/pandas/core/apply.py @@ -6,7 +6,7 @@ from pandas._config import option_context -from pandas._typing import Axis, FrameOrSeriesUnion +from pandas._typing import ApplyFuncType, Axis, FrameOrSeriesUnion from pandas.util._decorators import cache_readonly from pandas.core.dtypes.common import ( @@ -27,7 +27,7 @@ def frame_apply( obj: "DataFrame", - func, + func: ApplyFuncType, axis: Axis = 0, raw: bool = False, result_type: Optional[str] = None, From 6d534752a057e10f1cdb26a22c9cbd9afdcfacf4 Mon Sep 17 00:00:00 2001 From: Andrew Wieteska Date: Tue, 15 Dec 2020 01:46:19 -0500 Subject: [PATCH 4/6] add PythonFuncType alias --- pandas/_typing.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pandas/_typing.py b/pandas/_typing.py index 0f1ab544b2382..92eda4e781d4c 100644 --- a/pandas/_typing.py +++ b/pandas/_typing.py @@ -132,6 +132,7 @@ "Resampler", ] ApplyFuncType = Union[np.ufunc, AggFuncType] +PythonFuncType = Callable[[Any], Any] # filenames and file-like-objects Buffer = Union[IO[AnyStr], RawIOBase, BufferedIOBase, TextIOBase, TextIOWrapper, mmap] From 05043da43f6924c20279289dfe706bc7a5bbacd6 Mon Sep 17 00:00:00 2001 From: Andrew Wieteska Date: Tue, 15 Dec 2020 01:47:29 -0500 Subject: [PATCH 5/6] type func arg of DataFrame.applymap --- pandas/core/frame.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index cd3ec2838bfd9..fd254481d9d6a 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -62,6 +62,7 @@ IndexKeyFunc, Label, Level, + PythonFuncType, Renamer, StorageOptions, ValueKeyFunc, @@ -7809,7 +7810,9 @@ def apply( ) return op.get_result() - def applymap(self, func, na_action: Optional[str] = None) -> DataFrame: + def applymap( + self, func: PythonFuncType, na_action: Optional[str] = None + ) -> DataFrame: """ Apply a function to a Dataframe elementwise. From 6224f0ad27dd82442b40c97a2171837d45d3f124 Mon Sep 17 00:00:00 2001 From: Andrew Wieteska Date: Tue, 15 Dec 2020 21:44:56 -0500 Subject: [PATCH 6/6] review comments --- pandas/_typing.py | 3 ++- pandas/core/apply.py | 4 ++-- pandas/core/frame.py | 3 +-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pandas/_typing.py b/pandas/_typing.py index 92eda4e781d4c..c79942c48509e 100644 --- a/pandas/_typing.py +++ b/pandas/_typing.py @@ -95,6 +95,7 @@ IndexLabel = Union[Label, Sequence[Label]] Level = Union[Label, int] Shape = Tuple[int, ...] +Suffixes = Tuple[str, str] Ordered = Optional[bool] JSONSerializable = Optional[Union[PythonScalar, List, Dict]] Axes = Collection @@ -131,7 +132,7 @@ "BaseWindow", "Resampler", ] -ApplyFuncType = Union[np.ufunc, AggFuncType] + PythonFuncType = Callable[[Any], Any] # filenames and file-like-objects diff --git a/pandas/core/apply.py b/pandas/core/apply.py index 5508d9103d370..c0c6c9084b560 100644 --- a/pandas/core/apply.py +++ b/pandas/core/apply.py @@ -6,7 +6,7 @@ from pandas._config import option_context -from pandas._typing import ApplyFuncType, Axis, FrameOrSeriesUnion +from pandas._typing import AggFuncType, Axis, FrameOrSeriesUnion from pandas.util._decorators import cache_readonly from pandas.core.dtypes.common import ( @@ -27,7 +27,7 @@ def frame_apply( obj: "DataFrame", - func: ApplyFuncType, + func: AggFuncType, axis: Axis = 0, raw: bool = False, result_type: Optional[str] = None, diff --git a/pandas/core/frame.py b/pandas/core/frame.py index fd254481d9d6a..1edad41ccc93b 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -48,7 +48,6 @@ from pandas._libs.lib import no_default from pandas._typing import ( AggFuncType, - ApplyFuncType, ArrayLike, Axes, Axis, @@ -7659,7 +7658,7 @@ def transform( def apply( self, - func: ApplyFuncType, + func: AggFuncType, axis: Axis = 0, raw: bool = False, result_type=None,