Skip to content

Commit 2232058

Browse files
committed
towards groupby
1 parent 3e9fcd4 commit 2232058

2 files changed

Lines changed: 8 additions & 12 deletions

File tree

pandas-stubs/core/groupby/generic.pyi

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ from typing_extensions import override
3030

3131
from pandas._libs.tslibs.timestamps import Timestamp
3232
from pandas._typing import (
33+
C2,
3334
S2,
3435
S3,
3536
AggFuncTypeBase,
@@ -69,22 +70,13 @@ class SeriesGroupBy(GroupBy[Series[S2]], Generic[S2, ByT]):
6970
@overload
7071
def aggregate(
7172
self,
72-
func: Callable[Concatenate[Series[S2], P], S3],
73+
func: Callable[[Series], C2] | Callable[Concatenate[Series[S2], P], C2],
7374
/,
7475
*args: Any,
7576
engine: WindowingEngine = ...,
7677
engine_kwargs: WindowingEngineKwargs = ...,
7778
**kwargs: Any,
78-
) -> Series[S3]: ...
79-
@overload
80-
def aggregate(
81-
self,
82-
func: Callable[[Series], S3],
83-
*args: Any,
84-
engine: WindowingEngine = ...,
85-
engine_kwargs: WindowingEngineKwargs = ...,
86-
**kwargs: Any,
87-
) -> Series[S3]: ...
79+
) -> Series[C2]: ...
8880
@overload
8981
def aggregate(
9082
self,

tests/frame/test_groupby.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
Iterator,
88
)
99
from typing import (
10+
TYPE_CHECKING,
1011
Any,
1112
assert_type,
1213
)
@@ -26,6 +27,9 @@
2627
check,
2728
)
2829

30+
if TYPE_CHECKING:
31+
from pandas._typing import S1
32+
2933

3034
def test_types_groupby_as_index() -> None:
3135
"""Test type of groupby.size method depending on `as_index`."""
@@ -296,7 +300,7 @@ def test_types_groupby_agg() -> None:
296300
agg_dict1 = {"col2": "min", "col3": "max", 0: "sum"}
297301
check(assert_type(df.groupby("col1").agg(agg_dict1), pd.DataFrame), pd.DataFrame)
298302

299-
def wrapped_min(x: pd.Series) -> Scalar:
303+
def wrapped_min(x: pd.Series[S1]) -> S1:
300304
return x.min() # type: ignore[no-any-return]
301305

302306
# TODO: facebook/pyrefly#0

0 commit comments

Comments
 (0)