Skip to content

Commit

Permalink
lazy: expand cols in filter (#3128)
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Apr 12, 2022
1 parent b774caa commit 3708721
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
5 changes: 4 additions & 1 deletion polars/polars-lazy/src/logical_plan/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,10 @@ impl LogicalPlanBuilder {
/// Apply a filter
pub fn filter(self, predicate: Expr) -> Self {
let predicate = if has_expr(&predicate, |e| {
matches!(e, Expr::Wildcard | Expr::RenameAlias { .. })
matches!(
e,
Expr::Wildcard | Expr::RenameAlias { .. } | Expr::Columns(_)
)
}) {
let rewritten = rewrite_projections(vec![predicate], self.0.schema(), &[]);
combine_predicates_expr(rewritten.into_iter())
Expand Down
22 changes: 22 additions & 0 deletions polars/tests/it/lazy/predicate_queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,25 @@ fn filter_true_lit() -> Result<()> {
assert!(res.frame_equal_missing(&df));
Ok(())
}

#[test]
fn test_combine_columns_in_filter() -> Result<()> {
let df = df![
"a" => [1, 2, 3],
"b" => [None, Some("a"), Some("b")]
]?;

let out = df
.lazy()
.filter(cols(vec!["a".to_string(), "b".to_string()]).gt(lit(2)))
.collect()?;

let expected = df![
"a" => [3],
"b" => ["b"],
]?;

// "b" > "2" == true
assert!(out.frame_equal(&expected));
Ok(())
}

0 comments on commit 3708721

Please sign in to comment.