Skip to content

Commit

Permalink
fix(rust, python): fix invalid boolean simplification (#5976)
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Jan 1, 2023
1 parent ab317c7 commit dc67fd0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ impl OptimizationRule for SimplifyBooleanRule {
}
// x or false => x
AExpr::BinaryExpr {
left,
op: Operator::Or,
right,
..
Expand All @@ -184,7 +185,7 @@ impl OptimizationRule for SimplifyBooleanRule {
AExpr::Literal(LiteralValue::Boolean(false))
) =>
{
Some(expr_arena.get(*right).clone())
Some(expr_arena.get(*left).clone())
}

// false OR x => x
Expand Down
10 changes: 10 additions & 0 deletions py-polars/tests/unit/test_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,13 @@ def test_predicate_order_explode_5950() -> None:
.filter(pl.col("n").count().over(["i"]) == 2)
.filter(pl.col("n").is_not_null())
).collect().to_dict(False) == {"i": [1], "n": [0]}


def test_binary_simplification_5971() -> None:
df = pl.DataFrame(pl.Series("a", [1, 2, 3, 4]))
assert df.select((pl.col("a") > 2) | pl.lit(False))["a"].to_list() == [
False,
False,
True,
True,
]

0 comments on commit dc67fd0

Please sign in to comment.