Skip to content

Commit 58416f2

Browse files
authored
Added __getattr__ in DataFrameGroupBy (#457)
* ty * changed the return value to SeriesGroupBy and corrected the tests likewise * changed test to test '__getattr()' indirectly * modified the tests so SeriesGroupBy is not tested directly but indirectly
1 parent d89767d commit 58416f2

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

pandas-stubs/core/groupby/generic.pyi

+1
Original file line numberDiff line numberDiff line change
@@ -359,3 +359,4 @@ class DataFrameGroupBy(GroupBy):
359359
ascending: bool = ...,
360360
dropna: bool = ...,
361361
) -> Series[float]: ...
362+
def __getattr__(self, name: str) -> SeriesGroupBy: ...

tests/test_frame.py

+11
Original file line numberDiff line numberDiff line change
@@ -2292,3 +2292,14 @@ def test_groupby_and_transform() -> None:
22922292
check(assert_type(c2, pd.DataFrame), pd.DataFrame)
22932293
check(assert_type(c3, pd.Series), pd.Series)
22942294
check(assert_type(c4, pd.Series), pd.Series)
2295+
2296+
2297+
def test_getattr_and_dataframe_groupby() -> None:
2298+
df = pd.DataFrame(
2299+
data={"col1": [1, 1, 2], "col2": [3, 4, 5], "col3": [0, 1, 0], 0: [-1, -1, -1]}
2300+
)
2301+
check(assert_type(df.groupby("col1").col3.agg(min), pd.Series), pd.Series)
2302+
check(
2303+
assert_type(df.groupby("col1").col3.agg([min, max]), pd.DataFrame),
2304+
pd.DataFrame,
2305+
)

0 commit comments

Comments
 (0)