Skip to content

Commit 1048c48

Browse files
committed
Add test cases for agg dicts with keys which are sub-types of Hashable and adjust type annotation to support this
1 parent bbe4f35 commit 1048c48

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

pandas-stubs/_typing.pyi

+2-2
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,9 @@ F = TypeVar("F", bound=FuncType)
126126
HashableT = TypeVar("HashableT", bound=Hashable)
127127

128128
AggFuncTypeBase: TypeAlias = Union[Callable, str, np.ufunc]
129-
AggFuncTypeDictSeries: TypeAlias = Mapping[Hashable, AggFuncTypeBase]
129+
AggFuncTypeDictSeries: TypeAlias = Mapping[HashableT, AggFuncTypeBase]
130130
AggFuncTypeDictFrame: TypeAlias = Mapping[
131-
Hashable, Union[AggFuncTypeBase, list[AggFuncTypeBase]]
131+
HashableT, Union[AggFuncTypeBase, list[AggFuncTypeBase]]
132132
]
133133
AggFuncTypeSeriesToFrame: TypeAlias = Union[
134134
list[AggFuncTypeBase],

tests/test_frame.py

+4
Original file line numberDiff line numberDiff line change
@@ -670,6 +670,10 @@ def test_types_groupby_agg() -> None:
670670
0: lambda x: x.min(),
671671
}
672672
check(assert_type(df.groupby("col1").agg(agg_dict3), pd.DataFrame), pd.DataFrame)
673+
agg_dict4 = {"col2": "sum"}
674+
check(assert_type(df.groupby("col1").agg(agg_dict4), pd.DataFrame), pd.DataFrame)
675+
agg_dict5 = {0: "sum"}
676+
check(assert_type(df.groupby("col1").agg(agg_dict5), pd.DataFrame), pd.DataFrame)
673677
named_agg = pd.NamedAgg(column="col2", aggfunc="max")
674678
check(
675679
assert_type(df.groupby("col1").agg(new_col=named_agg), pd.DataFrame),

0 commit comments

Comments
 (0)