1
1
from __future__ import annotations
2
2
3
3
import collections
4
+ from typing import TYPE_CHECKING
4
5
from typing import Any
5
6
from typing import Iterable
6
7
11
12
from narwhals .pandas_like .utils import horizontal_concat
12
13
from narwhals .pandas_like .utils import is_simple_aggregation
13
14
from narwhals .pandas_like .utils import parse_into_exprs
14
- from narwhals .spec import DataFrame as DataFrameProtocol
15
15
from narwhals .spec import GroupBy as GroupByProtocol
16
16
from narwhals .spec import IntoExpr
17
- from narwhals .spec import LazyFrame as LazyFrameProtocol
18
17
from narwhals .spec import LazyGroupBy as LazyGroupByT
19
18
19
+ if TYPE_CHECKING :
20
+ from narwhals .pandas_like .dataframe import DataFrame
21
+ from narwhals .pandas_like .dataframe import LazyFrame
22
+
20
23
21
24
class GroupBy (GroupByProtocol ):
22
- def __init__ (self , df : DataFrameProtocol , keys : list [str ], api_version : str ) -> None :
25
+ def __init__ (self , df : DataFrame , keys : list [str ], api_version : str ) -> None :
23
26
self ._df = df
24
27
self ._keys = list (keys )
25
28
self .api_version = api_version
@@ -28,7 +31,7 @@ def agg(
28
31
self ,
29
32
* aggs : IntoExpr | Iterable [IntoExpr ],
30
33
** named_aggs : IntoExpr ,
31
- ) -> DataFrameProtocol :
34
+ ) -> DataFrame :
32
35
return (
33
36
LazyGroupBy (self ._df .lazy (), self ._keys , self .api_version )
34
37
.agg (* aggs , ** named_aggs )
@@ -37,7 +40,7 @@ def agg(
37
40
38
41
39
42
class LazyGroupBy (LazyGroupByT ):
40
- def __init__ (self , df : LazyFrameProtocol , keys : list [str ], api_version : str ) -> None :
43
+ def __init__ (self , df : LazyFrame , keys : list [str ], api_version : str ) -> None :
41
44
self ._df = df
42
45
self ._keys = list (keys )
43
46
self .api_version = api_version
@@ -46,7 +49,9 @@ def agg(
46
49
self ,
47
50
* aggs : IntoExpr | Iterable [IntoExpr ],
48
51
** named_aggs : IntoExpr ,
49
- ) -> LazyFrameProtocol :
52
+ ) -> LazyFrame :
53
+ from narwhals .pandas_like .dataframe import LazyFrame
54
+
50
55
df = self ._df .dataframe # type: ignore[attr-defined]
51
56
exprs = parse_into_exprs (
52
57
get_namespace (self ._df ),
0 commit comments