Skip to content

Commit af274d3

Browse files
committed
feat: Allow IntoExpr in binary ops
First step towards expressifying everywhere
1 parent 87b8402 commit af274d3

File tree

1 file changed

+42
-28
lines changed

1 file changed

+42
-28
lines changed

narwhals/_plan/dummy.py

Lines changed: 42 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -368,61 +368,75 @@ def map_batches(
368368
).to_function_expr(self._ir)
369369
)
370370

371-
def __eq__(self, other: DummyExpr) -> Self: # type: ignore[override]
371+
def __eq__(self, other: IntoExpr) -> Self: # type: ignore[override]
372372
op = ops.Eq()
373-
return self._from_ir(op.to_binary_expr(self._ir, other._ir))
373+
rhs = parse.parse_into_expr_ir(other, str_as_lit=True)
374+
return self._from_ir(op.to_binary_expr(self._ir, rhs))
374375

375-
def __ne__(self, other: DummyExpr) -> Self: # type: ignore[override]
376+
def __ne__(self, other: IntoExpr) -> Self: # type: ignore[override]
376377
op = ops.NotEq()
377-
return self._from_ir(op.to_binary_expr(self._ir, other._ir))
378+
rhs = parse.parse_into_expr_ir(other, str_as_lit=True)
379+
return self._from_ir(op.to_binary_expr(self._ir, rhs))
378380

379-
def __lt__(self, other: DummyExpr) -> Self:
381+
def __lt__(self, other: IntoExpr) -> Self:
380382
op = ops.Lt()
381-
return self._from_ir(op.to_binary_expr(self._ir, other._ir))
383+
rhs = parse.parse_into_expr_ir(other, str_as_lit=True)
384+
return self._from_ir(op.to_binary_expr(self._ir, rhs))
382385

383-
def __le__(self, other: DummyExpr) -> Self:
386+
def __le__(self, other: IntoExpr) -> Self:
384387
op = ops.LtEq()
385-
return self._from_ir(op.to_binary_expr(self._ir, other._ir))
388+
rhs = parse.parse_into_expr_ir(other, str_as_lit=True)
389+
return self._from_ir(op.to_binary_expr(self._ir, rhs))
386390

387-
def __gt__(self, other: DummyExpr) -> Self:
391+
def __gt__(self, other: IntoExpr) -> Self:
388392
op = ops.Gt()
389-
return self._from_ir(op.to_binary_expr(self._ir, other._ir))
393+
rhs = parse.parse_into_expr_ir(other, str_as_lit=True)
394+
return self._from_ir(op.to_binary_expr(self._ir, rhs))
390395

391-
def __ge__(self, other: DummyExpr) -> Self:
396+
def __ge__(self, other: IntoExpr) -> Self:
392397
op = ops.GtEq()
393-
return self._from_ir(op.to_binary_expr(self._ir, other._ir))
398+
rhs = parse.parse_into_expr_ir(other, str_as_lit=True)
399+
return self._from_ir(op.to_binary_expr(self._ir, rhs))
394400

395-
def __add__(self, other: DummyExpr) -> Self:
401+
def __add__(self, other: IntoExpr) -> Self:
396402
op = ops.Add()
397-
return self._from_ir(op.to_binary_expr(self._ir, other._ir))
403+
rhs = parse.parse_into_expr_ir(other, str_as_lit=True)
404+
return self._from_ir(op.to_binary_expr(self._ir, rhs))
398405

399-
def __sub__(self, other: DummyExpr) -> Self:
406+
def __sub__(self, other: IntoExpr) -> Self:
400407
op = ops.Sub()
401-
return self._from_ir(op.to_binary_expr(self._ir, other._ir))
408+
rhs = parse.parse_into_expr_ir(other, str_as_lit=True)
409+
return self._from_ir(op.to_binary_expr(self._ir, rhs))
402410

403-
def __mul__(self, other: DummyExpr) -> Self:
411+
def __mul__(self, other: IntoExpr) -> Self:
404412
op = ops.Multiply()
405-
return self._from_ir(op.to_binary_expr(self._ir, other._ir))
413+
rhs = parse.parse_into_expr_ir(other, str_as_lit=True)
414+
return self._from_ir(op.to_binary_expr(self._ir, rhs))
406415

407-
def __truediv__(self, other: DummyExpr) -> Self:
416+
def __truediv__(self, other: IntoExpr) -> Self:
408417
op = ops.TrueDivide()
409-
return self._from_ir(op.to_binary_expr(self._ir, other._ir))
418+
rhs = parse.parse_into_expr_ir(other, str_as_lit=True)
419+
return self._from_ir(op.to_binary_expr(self._ir, rhs))
410420

411-
def __floordiv__(self, other: DummyExpr) -> Self:
421+
def __floordiv__(self, other: IntoExpr) -> Self:
412422
op = ops.FloorDivide()
413-
return self._from_ir(op.to_binary_expr(self._ir, other._ir))
423+
rhs = parse.parse_into_expr_ir(other, str_as_lit=True)
424+
return self._from_ir(op.to_binary_expr(self._ir, rhs))
414425

415-
def __mod__(self, other: DummyExpr) -> Self:
426+
def __mod__(self, other: IntoExpr) -> Self:
416427
op = ops.Modulus()
417-
return self._from_ir(op.to_binary_expr(self._ir, other._ir))
428+
rhs = parse.parse_into_expr_ir(other, str_as_lit=True)
429+
return self._from_ir(op.to_binary_expr(self._ir, rhs))
418430

419-
def __and__(self, other: DummyExpr) -> Self:
431+
def __and__(self, other: IntoExpr) -> Self:
420432
op = ops.And()
421-
return self._from_ir(op.to_binary_expr(self._ir, other._ir))
433+
rhs = parse.parse_into_expr_ir(other, str_as_lit=True)
434+
return self._from_ir(op.to_binary_expr(self._ir, rhs))
422435

423-
def __or__(self, other: DummyExpr) -> Self:
436+
def __or__(self, other: IntoExpr) -> Self:
424437
op = ops.Or()
425-
return self._from_ir(op.to_binary_expr(self._ir, other._ir))
438+
rhs = parse.parse_into_expr_ir(other, str_as_lit=True)
439+
return self._from_ir(op.to_binary_expr(self._ir, rhs))
426440

427441
def __invert__(self) -> Self:
428442
return self._from_ir(boolean.Not().to_function_expr(self._ir))

0 commit comments

Comments
 (0)