33from typing import TYPE_CHECKING , Any , Callable , Literal , Protocol , cast
44
55from narwhals ._compliant .expr import LazyExpr
6- from narwhals ._compliant .typing import (
7- AliasNames ,
8- EvalNames ,
9- EvalSeries ,
10- NativeExprT ,
11- WindowFunction ,
12- )
6+ from narwhals ._compliant .typing import AliasNames , WindowFunction
137from narwhals ._compliant .window import WindowInputs
148from narwhals ._expression_parsing import (
159 combine_alias_output_names ,
1610 combine_evaluate_output_names ,
1711)
18- from narwhals ._sql .typing import SQLLazyFrameT , NativeSQLExprT
12+ from narwhals ._sql .typing import NativeSQLExprT , SQLLazyFrameT
1913from narwhals ._utils import Implementation , Version , not_implemented
2014
2115if TYPE_CHECKING :
2216 from collections .abc import Iterable , Sequence
2317
2418 from typing_extensions import Self , TypeIs
2519
26- from narwhals ._compliant .typing import AliasNames , WindowFunction
20+ from narwhals ._compliant .typing import (
21+ AliasNames ,
22+ EvalNames ,
23+ EvalSeries ,
24+ NativeExprT ,
25+ WindowFunction ,
26+ )
2727 from narwhals ._expression_parsing import ExprMetadata
2828 from narwhals ._sql .namespace import SQLNamespace
2929 from narwhals .typing import NumericLiteral , PythonLiteral , RankMethod , TemporalLiteral
3030
31- # am I right in thinking we need to pass NativeSQLExprT here, not NativeExprT? since NativeSQLExprT
32- # inherits from it, I can use that througout in the code and it will also have its parents functionality.
31+
32+ # am I right in thinking we need to pass NativeSQLExprT here, not NativeExprT? since NativeSQLExprT
33+ # inherits from it, I can use that througout in the code and it will also have its parents functionality.
3334# though at the moment there are still problems with the class..
34- class SQLExpr (LazyExpr [SQLLazyFrameT , NativeSQLExprT ], Protocol [SQLLazyFrameT , NativeSQLExprT ]):
35+ class SQLExpr (
36+ LazyExpr [SQLLazyFrameT , NativeSQLExprT ], Protocol [SQLLazyFrameT , NativeSQLExprT ]
37+ ):
3538 _call : EvalSeries [SQLLazyFrameT , NativeSQLExprT ]
3639 _evaluate_output_names : EvalNames [SQLLazyFrameT ]
3740 _alias_output_names : AliasNames | None
@@ -277,7 +280,7 @@ def func(
277280 }
278281 return [
279282 self ._when (
280- self ._window_expression (
283+ self ._window_expression (
281284 self ._function ("count" , expr ), ** window_kwargs
282285 )
283286 >= self ._lit (min_samples ),
@@ -498,13 +501,12 @@ def round(self, decimals: int) -> Self:
498501 return self ._with_elementwise (
499502 lambda expr : self ._function ("round" , expr , self ._lit (decimals ))
500503 )
501- # WIP: trying new NativeSQLExprT
504+
505+ # WIP: trying new NativeSQLExprT
502506 def sqrt (self ) -> Self :
503507 def _sqrt (expr : NativeSQLExprT ) -> NativeSQLExprT :
504508 return self ._when (
505- expr < self ._lit (0 ),
506- self ._lit (float ("nan" )),
507- self ._function ("sqrt" , expr ),
509+ expr < self ._lit (0 ), self ._lit (float ("nan" )), self ._function ("sqrt" , expr )
508510 )
509511
510512 return self ._with_elementwise (_sqrt )
@@ -515,12 +517,12 @@ def exp(self) -> Self:
515517 def log (self , base : float ) -> Self :
516518 def _log (expr : NativeSQLExprT ) -> NativeSQLExprT :
517519 return self ._when (
518- expr < self ._lit (0 ),
520+ expr < self ._lit (0 ),
519521 self ._lit (float ("nan" )),
520522 self ._when (
521523 cast ("NativeSQLExprT" , expr == self ._lit (0 )),
522524 self ._lit (float ("-inf" )),
523- self ._function ("log" , expr ) / self ._function ("log" , self ._lit (base )),
525+ self ._function ("log" , expr ) / self ._function ("log" , self ._lit (base )),
524526 ),
525527 )
526528
@@ -668,19 +670,19 @@ def _rank(
668670 count_window_kwargs : dict [str , Any ] = {"partition_by" : (* partition_by , expr )}
669671 if method == "max" :
670672 rank_expr = (
671- self ._window_expression (func , ** window_kwargs )
673+ self ._window_expression (func , ** window_kwargs )
672674 + self ._window_expression (count_expr , ** count_window_kwargs )
673675 - self ._lit (1 )
674676 )
675677 elif method == "average" :
676678 rank_expr = self ._window_expression (func , ** window_kwargs ) + (
677- self ._window_expression (count_expr , ** count_window_kwargs )
679+ self ._window_expression (count_expr , ** count_window_kwargs )
678680 - self ._lit (1 )
679681 ) / self ._lit (2.0 )
680682 else :
681683 rank_expr = self ._window_expression (func , ** window_kwargs )
682- # TODO: @mp, thought I added this to NativeSQLExprT but not working?
683- return self ._when (~ self ._function ("isnull" , expr ), rank_expr ) # type: ignore[operator]
684+ # TODO: @mp, thought I added this to NativeSQLExprT but not working?
685+ return self ._when (~ self ._function ("isnull" , expr ), rank_expr ) # type: ignore[operator]
684686
685687 def _unpartitioned_rank (expr : NativeSQLExprT ) -> NativeSQLExprT :
686688 return _rank (expr , descending = [descending ], nulls_last = [True ])
0 commit comments