Skip to content

Commit

Permalink
refactor(api): remove unnecessary methods used to implement negate() (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
kszucs authored Mar 28, 2024
1 parent 7a8f65c commit f59f423
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 27 deletions.
29 changes: 26 additions & 3 deletions ibis/expr/types/logical.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 1 addition & 13 deletions ibis/expr/types/numeric.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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`.
Expand Down
12 changes: 1 addition & 11 deletions ibis/expr/types/temporal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit f59f423

Please sign in to comment.