Skip to content

Commit 660b4e3

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 266cab9 commit 660b4e3

File tree

2 files changed

+25
-22
lines changed

2 files changed

+25
-22
lines changed

narwhals/_sql/expr.py

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,38 @@
33
from typing import TYPE_CHECKING, Any, Callable, Literal, Protocol, cast
44

55
from 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
137
from narwhals._compliant.window import WindowInputs
148
from 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
1913
from narwhals._utils import Implementation, Version, not_implemented
2014

2115
if 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
@@ -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)

narwhals/_sql/typing.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44

55
from narwhals._compliant.expr import NativeExpr
66

7+
78
class NativeSQLExpr(NativeExpr):
8-
# both Self because we're comparing an expression with an expression?
9+
# both Self because we're comparing an expression with an expression?
910
def __gt__(self, value: Self) -> Self: ...
1011

1112
def __lt__(self, value: Self) -> Self: ...
@@ -26,16 +27,17 @@ def __truediv__(self, value: Self) -> Self: ...
2627

2728
def __mul__(self, value: Self) -> Self: ...
2829

30+
2931
if TYPE_CHECKING:
32+
from typing_extensions import Self
33+
3034
from narwhals._sql.dataframe import SQLLazyFrame
3135
from narwhals._sql.expr import SQLExpr
32-
from narwhals.dtypes import Boolean
33-
from typing_extensions import Self
3436

3537
# TODO: @mp, understand why these are here & if we need one for NativeSQLExprT;
3638
# seem to reflect number of different 'catgories' each of the parent class has
3739
# tbc! since NativeExpr only has Protocol, I don't think we need this for NativeSQLExpr
38-
# NativeSQLExpr isn't accepting Any arguments :) I need to go back to the reading on
40+
# NativeSQLExpr isn't accepting Any arguments :) I need to go back to the reading on
3941
# cov-, contra- & invariance
4042
SQLExprAny = SQLExpr[Any, Any]
4143
SQLLazyFrameAny = SQLLazyFrame[Any, Any, Any]
@@ -45,5 +47,4 @@ def __mul__(self, value: Self) -> Self: ...
4547
SQLExprT_contra = TypeVar("SQLExprT_contra", bound="SQLExprAny", contravariant=True)
4648
SQLLazyFrameT = TypeVar("SQLLazyFrameT", bound="SQLLazyFrameAny")
4749
# TODO: @mp, should this be contravariant as to do with function arguments? think through!
48-
NativeSQLExprT = TypeVar("NativeSQLExprT", bound="NativeSQLExprAny")
49-
50+
NativeSQLExprT = TypeVar("NativeSQLExprT", bound="NativeSQLExprAny")

0 commit comments

Comments
 (0)