Skip to content

Commit

Permalink
c
Browse files Browse the repository at this point in the history
  • Loading branch information
nameexhaustion committed Sep 30, 2024
1 parent 29ce6f3 commit 23cda38
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
14 changes: 12 additions & 2 deletions crates/polars-plan/src/plans/conversion/dsl_to_ir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,15 +380,25 @@ pub fn to_alp_impl(lp: DslPlan, ctxt: &mut DslConversionContext) -> PolarsResult
expr,
input,
options,
} if
} if {
// This is a hack so that we don't break `list.eval(pl.element().filter())`. That expression
// hits this codepath with `col("").filter(..)` when it goes through `run_on_group_by_engine`
// and for some reason doesn't give a correct result if we do this rewrite.
//
// We detect that we are called by `run_on_group_by_engine` because it calls to here with
// nearly all optimizations turned off, so we just picked the `PREDICATE_PUSHDOWN` to check.
ctxt.opt_flags.contains(OptFlags::PREDICATE_PUSHDOWN)
&& matches!(expr.as_slice(), &[Expr::Filter { .. }]) =>
} && {
let mut rewrite = false;

if let [Expr::Filter { input, .. }] = &expr[..] {
if has_expr(input.as_ref(), |e| matches!(e, Expr::Wildcard)) {
rewrite = true
}
}

rewrite
} =>
{
let Expr::Filter {
input: filter_input,
Expand Down
5 changes: 5 additions & 0 deletions py-polars/tests/unit/expr/test_exprs.py
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,11 @@ def test_filter_all() -> None:
pl.DataFrame({"a": [2, 5], "b": ["q", "t"], "p": False}),
)

# Ensure no regression in the non-wildcard case, as the predicate may refer
# to columns that are not part of the `select()`
q = df.lazy().select(pl.col("a").filter(~pl.col("p")))
assert_frame_equal(q.collect(), pl.DataFrame({"a": [2, 5]}))

q = df.lazy().select((pl.all().reverse()).filter(~pl.col("p")))
assert r'FILTER col("p").not()' in q.explain()

Expand Down

0 comments on commit 23cda38

Please sign in to comment.