Skip to content

Commit

Permalink
NotEq
Browse files Browse the repository at this point in the history
  • Loading branch information
jpn-- committed Mar 20, 2024
1 parent d9e240f commit d9c7fae
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 2 additions & 2 deletions sharrow/aster.py
Original file line number Diff line number Diff line change
Expand Up @@ -977,8 +977,8 @@ def visit_Call(self, node):
def visit_Compare(self, node):
result = None

# devolve XXX == YYY when XXX or YYY is a categorical and the other is a constant category value
if len(node.ops) == 1 and isinstance(node.ops[0], ast.Eq):
# devolve XXX ==/!= YYY when XXX or YYY is a categorical and the other is a constant category value
if len(node.ops) == 1 and isinstance(node.ops[0], (ast.Eq, ast.NotEq)):
left = self.visit(node.left)
right = self.visit(node.comparators[0])
left_is_categorical = (
Expand Down
6 changes: 6 additions & 0 deletions sharrow/tests/test_categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,9 @@ def test_missing_categorical():
a = f6.load_dataarray(dtype=np.int8)
a = a.isel(expressions=0)
assert all(a == np.asarray([0, 0, 0, 0, 0, 0]))

expr = "df.TourMode2 != 'Bus'"
f7 = tree.setup_flow({expr: expr}, with_root_node_name="df")
a = f7.load_dataarray(dtype=np.int8)
a = a.isel(expressions=0)
assert all(a == np.asarray([1, 0, 1, 1, 1, 1]))

0 comments on commit d9c7fae

Please sign in to comment.