Skip to content

Commit

Permalink
fix[rust]: fix flawed simplify expression rule (#4396)
Browse files Browse the repository at this point in the history
'lit(true) | expr' was replaced with 'lit(false)',
where it should produce 'lit(true)'
  • Loading branch information
ritchie46 committed Aug 13, 2022
1 parent 0f912ba commit d5d9d4f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ impl OptimizationRule for SimplifyBooleanRule {
AExpr::Literal(LiteralValue::Boolean(true))
) =>
{
Some(AExpr::Literal(LiteralValue::Boolean(false)))
Some(AExpr::Literal(LiteralValue::Boolean(true)))
}

// x OR true => true
Expand All @@ -219,7 +219,7 @@ impl OptimizationRule for SimplifyBooleanRule {
AExpr::Literal(LiteralValue::Boolean(true))
) =>
{
Some(AExpr::Literal(LiteralValue::Boolean(false)))
Some(AExpr::Literal(LiteralValue::Boolean(true)))
}
AExpr::Ternary {
truthy, predicate, ..
Expand Down
11 changes: 11 additions & 0 deletions py-polars/tests/test_filter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import polars as pl


def test_simplify_expression_lit_true_4376() -> None:
df = pl.DataFrame([[1, 4, 7], [2, 5, 8], [3, 6, 9]])
assert df.lazy().filter(pl.lit(True) | (pl.col("column_0") == 1)).collect(
simplify_expression=True
).shape == (3, 3)
assert df.lazy().filter((pl.col("column_0") == 1) | pl.lit(True)).collect(
simplify_expression=True
).shape == (3, 3)

0 comments on commit d5d9d4f

Please sign in to comment.