diff --git a/ibis/expr/types/generic.py b/ibis/expr/types/generic.py index cf83acec709f..367d6031a62e 100644 --- a/ibis/expr/types/generic.py +++ b/ibis/expr/types/generic.py @@ -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: diff --git a/ibis/tests/expr/test_value_exprs.py b/ibis/tests/expr/test_value_exprs.py index 88ac5d4884c1..ec8e3a224750 100644 --- a/ibis/tests/expr/test_value_exprs.py +++ b/ibis/tests/expr/test_value_exprs.py @@ -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"])