I'm having a hard time understanding how to use the lazy with_context
. The docs say
This allows expressions to also access columns from DataFrames that are not part of this one.
I want to filter a column based on a column from another frame, but I get errors stating that the column from the other frame does not exist. Not sure what I'm doing wrong here, as it seems to fit the description of what the with_context
docs describe.
main.rs
use polars::prelude::*;
fn main() {
let df0 = df! {
"id" => [1, 2, 3],
"name" => ["foo", "bar", "baz"],
}
.unwrap()
.lazy();
let other_df = df! {
"other_id" => [1,2,2,1],
"name" => ["w", "x", "y", "z"],
}
.unwrap()
.lazy();
let lf = df0.with_context(&[other_df]);
let res = lf
.filter(col("id").is_in(col("other_id")))
.collect()
.unwrap();
println!("{:?}", res);
}
Cargo.toml
[dependencies]
polars = {git = "https://github.com/pola-rs/polars", branch = "master", features = ["lazy", "is_in"]}
Edit:
If i do select
instead of filter
, I don't get an error.
let res = lf
.select(&[col("id").is_in(col("other_id"))])
.collect()
.unwrap();