Skip to content

Commit 2c08b7c

Browse files
committed
it gets better
1 parent 9451786 commit 2c08b7c

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

narwhals/pandas_like/group_by_object.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations
22

33
import collections
4+
from typing import TYPE_CHECKING
45
from typing import Any
56
from typing import Iterable
67

@@ -11,15 +12,17 @@
1112
from narwhals.pandas_like.utils import horizontal_concat
1213
from narwhals.pandas_like.utils import is_simple_aggregation
1314
from narwhals.pandas_like.utils import parse_into_exprs
14-
from narwhals.spec import DataFrame as DataFrameProtocol
1515
from narwhals.spec import GroupBy as GroupByProtocol
1616
from narwhals.spec import IntoExpr
17-
from narwhals.spec import LazyFrame as LazyFrameProtocol
1817
from narwhals.spec import LazyGroupBy as LazyGroupByT
1918

19+
if TYPE_CHECKING:
20+
from narwhals.pandas_like.dataframe import DataFrame
21+
from narwhals.pandas_like.dataframe import LazyFrame
22+
2023

2124
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:
2326
self._df = df
2427
self._keys = list(keys)
2528
self.api_version = api_version
@@ -28,7 +31,7 @@ def agg(
2831
self,
2932
*aggs: IntoExpr | Iterable[IntoExpr],
3033
**named_aggs: IntoExpr,
31-
) -> DataFrameProtocol:
34+
) -> DataFrame:
3235
return (
3336
LazyGroupBy(self._df.lazy(), self._keys, self.api_version)
3437
.agg(*aggs, **named_aggs)
@@ -37,7 +40,7 @@ def agg(
3740

3841

3942
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:
4144
self._df = df
4245
self._keys = list(keys)
4346
self.api_version = api_version
@@ -46,7 +49,9 @@ def agg(
4649
self,
4750
*aggs: IntoExpr | Iterable[IntoExpr],
4851
**named_aggs: IntoExpr,
49-
) -> LazyFrameProtocol:
52+
) -> LazyFrame:
53+
from narwhals.pandas_like.dataframe import LazyFrame
54+
5055
df = self._df.dataframe # type: ignore[attr-defined]
5156
exprs = parse_into_exprs(
5257
get_namespace(self._df),

0 commit comments

Comments
 (0)