Skip to content

Commit

Permalink
depr(api): deprecate bool_val.negate()/-bool_val in favor of `~bo…
Browse files Browse the repository at this point in the history
…ol_val`
  • Loading branch information
jcrist committed Sep 10, 2024
1 parent 1cf5439 commit 38737d4
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 41 deletions.
4 changes: 2 additions & 2 deletions ibis/backends/tests/sql/test_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def test_isnull_notnull(functional_alltypes, method_name, snapshot):


def test_negate(functional_alltypes, snapshot):
expr = -(functional_alltypes.double_col > 0)
expr = ~(functional_alltypes.double_col > 0)
snapshot.assert_match(to_sql(expr.name("tmp")), "out.sql")


Expand Down Expand Up @@ -319,7 +319,7 @@ def test_self_reference_in_not_exists(functional_alltypes, snapshot):
cond = (t.string_col == t2.string_col).any()

semi = t.filter(cond)
anti = t.filter(-cond)
anti = t.filter(~cond)

snapshot.assert_match(to_sql(semi), "semi.sql")
snapshot.assert_match(to_sql(anti), "anti.sql")
Expand Down
4 changes: 2 additions & 2 deletions ibis/backends/tests/test_aggregation.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ def mean_and_std(v):
],
),
param(
lambda t, where: -t.bool_col.any(where=where),
lambda t, where: ~t.bool_col.any(where=where),
lambda t, where: ~t.bool_col[where].any(),
id="any_negate",
marks=[
Expand Down Expand Up @@ -330,7 +330,7 @@ def mean_and_std(v):
],
),
param(
lambda t, where: -t.bool_col.all(where=where),
lambda t, where: ~t.bool_col.all(where=where),
lambda t, where: ~t.bool_col[where].all(),
id="all_negate",
marks=[
Expand Down
8 changes: 3 additions & 5 deletions ibis/backends/tests/test_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import decimal
from collections import Counter
from itertools import permutations
from operator import invert, methodcaller, neg
from operator import invert, methodcaller

import pytest
import toolz
Expand Down Expand Up @@ -76,7 +76,7 @@ def test_null_literal_typed(con, backend):
expr = ibis.null(bool)
assert expr.type() == dt.boolean
assert pd.isna(con.execute(expr))
assert pd.isna(con.execute(expr.negate()))
assert pd.isna(con.execute(~expr))
assert pd.isna(con.execute(expr.cast(str).upper()))


Expand Down Expand Up @@ -1003,15 +1003,13 @@ def test_isin_notin_column_expr(backend, alltypes, df, ibis_op, pandas_op):
param(False, False, toolz.identity, id="false_noop"),
param(True, False, invert, id="true_invert"),
param(False, True, invert, id="false_invert"),
param(True, False, neg, id="true_negate"),
param(False, True, neg, id="false_negate"),
],
)
def test_logical_negation_literal(con, expr, expected, op):
assert con.execute(op(ibis.literal(expr)).name("tmp")) == expected


@pytest.mark.parametrize("op", [toolz.identity, invert, neg])
@pytest.mark.parametrize("op", [toolz.identity, invert])
def test_logical_negation_column(backend, alltypes, df, op):
result = op(alltypes["bool_col"]).name("tmp").execute()
expected = op(df["bool_col"])
Expand Down
35 changes: 9 additions & 26 deletions ibis/expr/types/logical.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import ibis
import ibis.expr.operations as ops
from ibis import util
from ibis.expr.types.core import _binop
from ibis.expr.types.numeric import NumericColumn, NumericScalar, NumericValue

Expand Down Expand Up @@ -227,34 +228,16 @@ def __invert__(self) -> BooleanValue:
│ NULL │
└──────────┘
"""
return self.negate()
return ops.Not(self).to_expr()

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()
"""DEPRECATED."""
util.warn_deprecated(

Check warning on line 235 in ibis/expr/types/logical.py

View check run for this annotation

Codecov / codecov/patch

ibis/expr/types/logical.py#L235

Added line #L235 was not covered by tests
"`-bool_val`/`bool_val.negate()`",
instead="use `~bool_val` instead",
as_of="9.5",
)
return ~self

Check warning on line 240 in ibis/expr/types/logical.py

View check run for this annotation

Codecov / codecov/patch

ibis/expr/types/logical.py#L240

Added line #L240 was not covered by tests


@public
Expand Down
10 changes: 4 additions & 6 deletions ibis/tests/expr/test_value_exprs.py
Original file line number Diff line number Diff line change
Expand Up @@ -501,17 +501,15 @@ def test_negate(table, col):
assert isinstance(result.op(), ops.Negate)


@pytest.mark.parametrize("op", [operator.neg, operator.invert])
@pytest.mark.parametrize("value", [True, False])
def test_negate_boolean_scalar(op, value):
result = op(ibis.literal(value))
def test_negate_boolean_scalar(value):
result = ~ibis.literal(value)
assert isinstance(result, ir.BooleanScalar)
assert isinstance(result.op(), ops.Not)


@pytest.mark.parametrize("op", [operator.neg, operator.invert])
def test_negate_boolean_column(table, op):
result = op(table["h"])
def test_negate_boolean_column(table):
result = ~table["h"]
assert isinstance(result, ir.BooleanColumn)
assert isinstance(result.op(), ops.Not)

Expand Down

0 comments on commit 38737d4

Please sign in to comment.