Skip to content

Commit a8af821

Browse files
committed
notes on what should happen
1 parent 40e1737 commit a8af821

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

narwhals/_sql/typing.py

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,34 @@
1414
SQLLazyFrameT = TypeVar("SQLLazyFrameT", bound="SQLLazyFrameAny")
1515

1616

17-
# it needs to inherit from SQLExpr, but getting errors if passing SQLExprT
18-
class NativeSQLExpr(Any): ...
17+
# it needs to inherit from SQLExpr, but getting errors if passing SQLExprT. I have not sorted out what relation
18+
# (covarinant, contravariant or intravariant it needs to be yet) it needs to have to its parent class
19+
class NativeSQLExpr(SQLExprT):
20+
# not sure how to initialise the class, I want it to have all the methods etc of SQLExprT and add its own operator
21+
# methods in addition to those
22+
def __init__(self, other: [Int | Float]) -> None:
23+
super().__init__(other)
24+
25+
# I've seen lots of examples of the operator dunder methods being used, but I'm struggling with
26+
# the typing. for sql, there are nice binary examples, but that's not the right method
27+
# e.g.
28+
def __gt__(self, other: Self) -> Self:
29+
return self._with_binary(lambda expr, other: expr.__gt__(other), other)
30+
31+
def __and__(self, other: Self) -> Self:
32+
return self._with_binary(lambda expr, other: expr.__and__(other), other)
33+
34+
# so it should probably look more like something from the polars examples,
35+
# where we just apply the native method:
36+
def __gt__(self, other: Any) -> Self:
37+
return self._with_native(self.native.__gt__(extract_native(other)))
38+
39+
def __le__(self, other: Any) -> Self:
40+
return self._with_native(self.native.__le__(extract_native(other)))
41+
42+
43+
44+
45+
46+
47+

0 commit comments

Comments
 (0)