Skip to content

Commit 2dd5189

Browse files
Add explicit Any type parameters for arguments used in df.apply
1 parent 3db439d commit 2dd5189

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

pandas-stubs/_typing.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -490,8 +490,8 @@ Axis: TypeAlias = AxisIndex | AxisColumn
490490
DtypeNp = TypeVar("DtypeNp", bound=np.dtype[np.generic])
491491
KeysArgType: TypeAlias = Any
492492
ListLike = TypeVar("ListLike", Sequence, np.ndarray, Series, Index)
493-
ListLikeExceptSeriesAndStr = TypeVar(
494-
"ListLikeExceptSeriesAndStr", MutableSequence, np.ndarray, tuple, Index
493+
ListLikeExceptSeriesAndStr: TypeAlias = (
494+
MutableSequence[Any] | np.ndarray[Any, Any] | tuple[Any, ...] | Index[Any]
495495
)
496496
ListLikeU: TypeAlias = Sequence | np.ndarray | Series | Index
497497
ListLikeHashable: TypeAlias = (

pandas-stubs/core/frame.pyi

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1250,7 +1250,7 @@ class DataFrame(NDFrame, OpsMixin):
12501250
@overload
12511251
def apply(
12521252
self,
1253-
f: Callable[..., ListLikeExceptSeriesAndStr | Series],
1253+
f: Callable[..., ListLikeExceptSeriesAndStr | Series[Any]],
12541254
axis: AxisIndex = ...,
12551255
raw: _bool = ...,
12561256
result_type: None = ...,
@@ -1272,7 +1272,7 @@ class DataFrame(NDFrame, OpsMixin):
12721272
@overload
12731273
def apply(
12741274
self,
1275-
f: Callable[..., Mapping],
1275+
f: Callable[..., Mapping[Any, Any]],
12761276
axis: AxisIndex = ...,
12771277
raw: _bool = ...,
12781278
result_type: None = ...,
@@ -1295,7 +1295,7 @@ class DataFrame(NDFrame, OpsMixin):
12951295
@overload
12961296
def apply(
12971297
self,
1298-
f: Callable[..., ListLikeExceptSeriesAndStr | Series | Mapping],
1298+
f: Callable[..., ListLikeExceptSeriesAndStr | Series[Any] | Mapping[Any, Any]],
12991299
axis: Axis = ...,
13001300
raw: _bool = ...,
13011301
args=...,
@@ -1317,7 +1317,9 @@ class DataFrame(NDFrame, OpsMixin):
13171317
@overload
13181318
def apply(
13191319
self,
1320-
f: Callable[..., ListLikeExceptSeriesAndStr | Series | Scalar | Mapping],
1320+
f: Callable[
1321+
..., ListLikeExceptSeriesAndStr | Series[Any] | Scalar | Mapping[Any, Any]
1322+
],
13211323
axis: Axis = ...,
13221324
raw: _bool = ...,
13231325
args=...,
@@ -1330,14 +1332,14 @@ class DataFrame(NDFrame, OpsMixin):
13301332
@overload
13311333
def apply(
13321334
self,
1333-
f: Callable[..., Series],
1335+
f: Callable[..., Series[Any]],
13341336
axis: AxisIndex = ...,
13351337
raw: _bool = ...,
13361338
args=...,
13371339
*,
13381340
result_type: Literal["reduce"],
13391341
**kwargs,
1340-
) -> Series: ...
1342+
) -> Series[Any]: ...
13411343

13421344
# apply() overloads with default result_type of None, and keyword axis=1 matters
13431345
@overload
@@ -1365,7 +1367,7 @@ class DataFrame(NDFrame, OpsMixin):
13651367
@overload
13661368
def apply(
13671369
self,
1368-
f: Callable[..., Series],
1370+
f: Callable[..., Series[Any]],
13691371
raw: _bool = ...,
13701372
result_type: None = ...,
13711373
args=...,
@@ -1378,7 +1380,7 @@ class DataFrame(NDFrame, OpsMixin):
13781380
@overload
13791381
def apply(
13801382
self,
1381-
f: Callable[..., Series],
1383+
f: Callable[..., Series[Any]],
13821384
raw: _bool = ...,
13831385
args=...,
13841386
*,

0 commit comments

Comments
 (0)