Skip to content

Commit 35df38f

Browse files
committed
Series.apply callable result might not be hashable
It's possible for the callable in Series.apply to return something non-hashable like a list, but the result of apply should still be a Series.
1 parent 5305cd0 commit 35df38f

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

pandas-stubs/core/series.pyi

+1-1
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,7 @@ class Series(IndexOpsMixin, NDFrame, Generic[S1]):
685685
@overload
686686
def apply(
687687
self,
688-
func: Callable[..., Hashable],
688+
func: Callable[..., Scalar | Sequence | Mapping],
689689
convertDType: _bool = ...,
690690
args: tuple = ...,
691691
**kwds,

tests/test_series.py

+5
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,11 @@ def retseries(x: float) -> float:
398398

399399
check(assert_type(s.apply(retseries).tolist(), list), list)
400400

401+
def retlist(x: float) -> list:
402+
return [x]
403+
404+
check(assert_type(s.apply(retlist), pd.Series), pd.Series, list)
405+
401406
def get_depth(url: str) -> int:
402407
return len(url)
403408

0 commit comments

Comments
 (0)