99from typing import Mapping
1010from typing import Sequence
1111
12- from narwhals ._compliant .typing import CompliantDataFrameT
13- from narwhals ._compliant .typing import CompliantExprT
14- from narwhals ._compliant .typing import CompliantFrameT
15- from narwhals ._compliant .typing import NativeFrameT_co
12+ from narwhals ._compliant .typing import CompliantDataFrameT_co
13+ from narwhals ._compliant .typing import CompliantExprT_contra
14+ from narwhals ._compliant .typing import CompliantFrameT_co
1615from narwhals ._expression_parsing import is_elementary_expression
1716
18- if TYPE_CHECKING :
19- from typing_extensions import TypeAlias
20-
21- from narwhals ._compliant .dataframe import CompliantDataFrame
22- from narwhals ._compliant .dataframe import CompliantLazyFrame
23-
24- Frame : TypeAlias = "CompliantDataFrame[Any, Any, NativeFrameT_co] | CompliantLazyFrame[Any, NativeFrameT_co]"
25-
2617if not TYPE_CHECKING : # pragma: no cover
2718 if sys .version_info >= (3 , 9 ):
2819 from typing import Protocol as Protocol38
3627__all__ = ["CompliantGroupBy" , "EagerGroupBy" ]
3728
3829
39- # NOTE: Type checkers disagree
40- # - `pyright` wants invariant `*Expr`
41- # - `mypy` want contravariant `*Expr`
42- class CompliantGroupBy (Protocol38 [CompliantFrameT , CompliantExprT ]): # type: ignore[misc]
30+ class CompliantGroupBy (Protocol38 [CompliantFrameT_co , CompliantExprT_contra ]):
4331 _NARWHALS_TO_NATIVE_AGGREGATIONS : ClassVar [Mapping [str , Any ]]
44- _compliant_frame : CompliantFrameT
32+ _compliant_frame : Any
4533 _keys : Sequence [str ]
4634
4735 def __init__ (
4836 self ,
49- compliant_frame : CompliantFrameT ,
37+ compliant_frame : CompliantFrameT_co ,
5038 keys : Sequence [str ],
5139 * ,
5240 drop_null_keys : bool ,
5341 ) -> None : ...
5442 @property
55- def compliant (self ) -> CompliantFrameT :
56- return self ._compliant_frame
57-
58- @property
59- def native (
60- self : CompliantGroupBy [Frame [NativeFrameT_co ], CompliantExprT ],
61- ) -> NativeFrameT_co :
62- return self .compliant .native
43+ def compliant (self ) -> CompliantFrameT_co :
44+ return self ._compliant_frame # type: ignore[no-any-return]
6345
64- def agg (self , * exprs : CompliantExprT ) -> CompliantFrameT : ...
46+ def agg (self , * exprs : CompliantExprT_contra ) -> CompliantFrameT_co : ...
6547
66- def _ensure_all_simple (self , exprs : Sequence [CompliantExprT ]) -> None :
48+ def _ensure_all_simple (self , exprs : Sequence [CompliantExprT_contra ]) -> None :
6749 for expr in exprs :
6850 if (
6951 not is_elementary_expression (expr )
@@ -85,8 +67,8 @@ def _ensure_all_simple(self, exprs: Sequence[CompliantExprT]) -> None:
8567 raise ValueError (msg )
8668
8769
88- class EagerGroupBy ( # type: ignore[misc]
89- CompliantGroupBy [CompliantDataFrameT , CompliantExprT ],
90- Protocol38 [CompliantDataFrameT , CompliantExprT ],
70+ class EagerGroupBy (
71+ CompliantGroupBy [CompliantDataFrameT_co , CompliantExprT_contra ],
72+ Protocol38 [CompliantDataFrameT_co , CompliantExprT_contra ],
9173):
92- def __iter__ (self ) -> Iterator [tuple [Any , CompliantDataFrameT ]]: ...
74+ def __iter__ (self ) -> Iterator [tuple [Any , CompliantDataFrameT_co ]]: ...
0 commit comments