Skip to content

Commit 6cb725c

Browse files
committed
feat: Generic dunders
1 parent d58e2c9 commit 6cb725c

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

narwhals/_compliant/expr.py

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,80 @@ def _reuse_series_namespace_implementation(
383383
context=self,
384384
)
385385

386+
def __eq__(self, other: Self | Any) -> EagerExpr[EagerDataFrameT, EagerSeriesT]: # type: ignore[override]
387+
return self._reuse_series_implementation("__eq__", other=other)
388+
389+
def __ne__(self, other: Self | Any) -> EagerExpr[EagerDataFrameT, EagerSeriesT]: # type: ignore[override]
390+
return self._reuse_series_implementation("__ne__", other=other)
391+
392+
def __ge__(self, other: Self | Any) -> EagerExpr[EagerDataFrameT, EagerSeriesT]:
393+
return self._reuse_series_implementation("__ge__", other=other)
394+
395+
def __gt__(self, other: Self | Any) -> EagerExpr[EagerDataFrameT, EagerSeriesT]:
396+
return self._reuse_series_implementation("__gt__", other=other)
397+
398+
def __le__(self, other: Self | Any) -> EagerExpr[EagerDataFrameT, EagerSeriesT]:
399+
return self._reuse_series_implementation("__le__", other=other)
400+
401+
def __lt__(self, other: Self | Any) -> EagerExpr[EagerDataFrameT, EagerSeriesT]:
402+
return self._reuse_series_implementation("__lt__", other=other)
403+
404+
def __and__(
405+
self, other: Self | bool | Any
406+
) -> EagerExpr[EagerDataFrameT, EagerSeriesT]:
407+
return self._reuse_series_implementation("__and__", other=other)
408+
409+
def __or__(
410+
self, other: Self | bool | Any
411+
) -> EagerExpr[EagerDataFrameT, EagerSeriesT]:
412+
return self._reuse_series_implementation("__or__", other=other)
413+
414+
def __add__(self, other: Self | Any) -> EagerExpr[EagerDataFrameT, EagerSeriesT]:
415+
return self._reuse_series_implementation("__add__", other=other)
416+
417+
def __sub__(self, other: Self | Any) -> EagerExpr[EagerDataFrameT, EagerSeriesT]:
418+
return self._reuse_series_implementation("__sub__", other=other)
419+
420+
def __rsub__(self, other: Self | Any) -> EagerExpr[EagerDataFrameT, EagerSeriesT]:
421+
return self.alias("literal")._reuse_series_implementation("__rsub__", other=other)
422+
423+
def __mul__(self, other: Self | Any) -> EagerExpr[EagerDataFrameT, EagerSeriesT]:
424+
return self._reuse_series_implementation("__mul__", other=other)
425+
426+
def __truediv__(self, other: Self | Any) -> EagerExpr[EagerDataFrameT, EagerSeriesT]:
427+
return self._reuse_series_implementation("__truediv__", other=other)
428+
429+
def __rtruediv__(self, other: Self | Any) -> EagerExpr[EagerDataFrameT, EagerSeriesT]:
430+
return self.alias("literal")._reuse_series_implementation(
431+
"__rtruediv__", other=other
432+
)
433+
434+
def __floordiv__(self, other: Self | Any) -> EagerExpr[EagerDataFrameT, EagerSeriesT]:
435+
return self._reuse_series_implementation("__floordiv__", other=other)
436+
437+
def __rfloordiv__(
438+
self, other: Self | Any
439+
) -> EagerExpr[EagerDataFrameT, EagerSeriesT]:
440+
return self.alias("literal")._reuse_series_implementation(
441+
"__rfloordiv__", other=other
442+
)
443+
444+
def __pow__(self, other: Self | Any) -> EagerExpr[EagerDataFrameT, EagerSeriesT]:
445+
return self._reuse_series_implementation("__pow__", other=other)
446+
447+
def __rpow__(self, other: Self | Any) -> EagerExpr[EagerDataFrameT, EagerSeriesT]:
448+
return self.alias("literal")._reuse_series_implementation("__rpow__", other=other)
449+
450+
def __mod__(self, other: Self | Any) -> EagerExpr[EagerDataFrameT, EagerSeriesT]:
451+
return self._reuse_series_implementation("__mod__", other=other)
452+
453+
def __rmod__(self, other: Self | Any) -> EagerExpr[EagerDataFrameT, EagerSeriesT]:
454+
return self.alias("literal")._reuse_series_implementation("__rmod__", other=other)
455+
456+
# Unary
457+
def __invert__(self) -> EagerExpr[EagerDataFrameT, EagerSeriesT]:
458+
return self._reuse_series_implementation("__invert__")
459+
386460

387461
# NOTE: See (https://github.com/narwhals-dev/narwhals/issues/2044#issuecomment-2674262833)
388462
class LazyExpr(

0 commit comments

Comments
 (0)