Skip to content

Commit

Permalink
chore: test and handle the case of self being a null-valued expression
Browse files Browse the repository at this point in the history
  • Loading branch information
cpcloud committed May 6, 2024
1 parent d67f70f commit 4521895
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
4 changes: 4 additions & 0 deletions ibis/expr/types/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1162,11 +1162,15 @@ def __hash__(self) -> int:
def __eq__(self, other: Value) -> ir.BooleanValue:
if _is_null_literal(other):
return self.isnull()
elif _is_null_literal(self):
return other.isnull()
return _binop(ops.Equals, self, other)

def __ne__(self, other: Value) -> ir.BooleanValue:
if _is_null_literal(other):
return self.notnull()
elif _is_null_literal(self):
return other.notnull()
return _binop(ops.NotEquals, self, other)

def __ge__(self, other: Value) -> ir.BooleanValue:
Expand Down
14 changes: 6 additions & 8 deletions ibis/tests/expr/test_value_exprs.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,16 +352,14 @@ def test_notnull(table):

@pytest.mark.parametrize(
"value",
[
param(lambda: None, id="none"),
param(lambda: ibis.NA, id="NA"),
param(lambda: ibis.literal(None, type="int32"), id="typed-null"),
],
[None, ibis.NA, ibis.literal(None, type="int32")],
ids=["none", "NA", "typed-null"],
)
def test_null_eq_and_ne(table, value):
other = value()
assert (table.a == other).equals(table.a.isnull())
assert (table.a != other).equals(table.a.notnull())
assert (table.a == value).equals(table.a.isnull())
assert (value == table.a).equals(table.a.isnull())
assert (table.a != value).equals(table.a.notnull())
assert (value != table.a).equals(table.a.notnull())


@pytest.mark.parametrize("column", ["e", "f"], ids=["float32", "double"])
Expand Down

0 comments on commit 4521895

Please sign in to comment.