jiayuasu commented on code in PR #823:
URL: https://github.com/apache/sedona-db/pull/823#discussion_r3211483188
##########
python/sedonadb/python/sedonadb/expr/expression.py:
##########
@@ -152,6 +153,87 @@ def negate(self) -> "Expr":
"""
return Expr(self._impl.negate())
+ # Arithmetic operators -------------------------------------------------
+ #
+ # Each binary dunder routes through the shared `_binary` helper, which
+ # coerces plain Python values to literal Exprs via `_to_expr` and then
+ # calls into the single Rust factory `expr_binary` with a string opcode.
+ # The reflected variants (`__radd__`, `__rsub__`, ...) make
+ # `1 - col("x")` work the same as `col("x") - 1`.
+
+ def __add__(self, other: Any) -> "Expr":
+ return _binary("+", self, other)
+
+ def __radd__(self, other: Any) -> "Expr":
+ return _binary("+", other, self)
+
+ def __sub__(self, other: Any) -> "Expr":
+ return _binary("-", self, other)
+
+ def __rsub__(self, other: Any) -> "Expr":
+ return _binary("-", other, self)
+
+ def __mul__(self, other: Any) -> "Expr":
+ return _binary("*", self, other)
+
+ def __rmul__(self, other: Any) -> "Expr":
+ return _binary("*", other, self)
+
+ def __truediv__(self, other: Any) -> "Expr":
+ return _binary("/", self, other)
+
+ def __rtruediv__(self, other: Any) -> "Expr":
+ return _binary("/", other, self)
+
+ def __neg__(self) -> "Expr":
+ return self.negate()
+
+ # Comparison operators -------------------------------------------------
+
+ def __eq__(self, other: Any) -> "Expr": # type: ignore[override]
+ return _binary("==", self, other)
+
+ def __ne__(self, other: Any) -> "Expr": # type: ignore[override]
+ return _binary("!=", self, other)
+
+ def __lt__(self, other: Any) -> "Expr":
+ return _binary("<", self, other)
+
+ def __le__(self, other: Any) -> "Expr":
+ return _binary("<=", self, other)
+
+ def __gt__(self, other: Any) -> "Expr":
+ return _binary(">", self, other)
+
+ def __ge__(self, other: Any) -> "Expr":
+ return _binary(">=", self, other)
+
+ # Boolean operators ----------------------------------------------------
+ #
+ # `&` / `|` / `~` rather than `and` / `or` / `not` because Python does
+ # not allow overloading the keyword forms — they always coerce to bool.
+
Review Comment:
Done in 60428b2b — `Expr.__bool__` and `Expr.__len__` now both raise
`TypeError` with guidance toward `&`/`|`/`~` and `DataFrame.filter()`. Six new
tests cover `bool()`, `if`, `and`/`or`, `not`, and `len()`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]