Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(api): remove unnecessary methods used to implement negate() #8812

Merged
merged 1 commit into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading