diff --git a/ibis/expr/types/logical.py b/ibis/expr/types/logical.py index 3fcc4d745478..a0c289df3bf5 100644 --- a/ibis/expr/types/logical.py +++ b/ibis/expr/types/logical.py @@ -229,9 +229,32 @@ def __invert__(self) -> BooleanValue: """ return self.negate() - @staticmethod - def __negate_op__(): - return ops.Not + def negate(self) -> BooleanValue: + """Negate a boolean expression. + + Returns + ------- + BooleanValue + A boolean value expression + + Examples + -------- + >>> import ibis + >>> ibis.options.interactive = True + >>> t = ibis.memtable({"values": [True, False, False, None]}) + >>> t.values.negate() + ┏━━━━━━━━━━━━━┓ + ┃ Not(values) ┃ + ┡━━━━━━━━━━━━━┩ + │ boolean │ + ├─────────────┤ + │ False │ + │ True │ + │ True │ + │ NULL │ + └─────────────┘ + """ + return ops.Not(self).to_expr() @public diff --git a/ibis/expr/types/numeric.py b/ibis/expr/types/numeric.py index 27802600a480..56d5c2dea178 100644 --- a/ibis/expr/types/numeric.py +++ b/ibis/expr/types/numeric.py @@ -19,11 +19,6 @@ @public class NumericValue(Value): - @staticmethod - def __negate_op__(): - # TODO(kszucs): do we need this? - return ops.Negate - def negate(self) -> NumericValue: """Negate a numeric expression. @@ -48,14 +43,7 @@ def negate(self) -> NumericValue: │ -1 │ └────────────────┘ """ - op = self.op() - try: - result = op.negate() - except AttributeError: - op_class = self.__negate_op__() - result = op_class(self) - - return result.to_expr() + return ops.Negate(self).to_expr() def __neg__(self) -> NumericValue: """Negate `self`. diff --git a/ibis/expr/types/temporal.py b/ibis/expr/types/temporal.py index c43fe6780c37..120f59b8e548 100644 --- a/ibis/expr/types/temporal.py +++ b/ibis/expr/types/temporal.py @@ -939,20 +939,10 @@ def negate(self) -> ir.IntervalValue: IntervalValue A negated interval value expression """ - op = self.op() - if hasattr(op, "negate"): - result = op.negate() - else: - result = ops.Negate(self) - - return result.to_expr() + return ops.Negate(self).to_expr() __neg__ = negate - @staticmethod - def __negate_op__(): - return ops.Negate - @public class IntervalScalar(Scalar, IntervalValue):