Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to use .col() method in polars rust

I am trying to execute this line in my Rust program:

let filtered_df = df.filter(col("time").eq(cursor_date_str)).head(Some(1));

and the compiler returns that

error[E0425]: cannot find function `col` in this scope
  --> src/main.rs:50:37
   |
50 |         let filtered_df = df.filter(col("time").eq(cursor_date_str)).head(Some(1));
   |                                     ^^^ not found in this scope

even though I have imported all from prelude:

use polars::prelude::*;

and my polars is up to date as well:

polars = "0.30.0"
like image 800
Arthur Zhang Avatar asked Sep 05 '25 03:09

Arthur Zhang


1 Answers

You need to enable lazy feature in Cargo.toml.

[dependencies]
polars = { version = "0.30.0", features = ["lazy"] }

Note: I could not find anything other than this in the official documentation, But I got this hint after looking at the source code of polars which defines it's prelude.rs file like this.

#[cfg(feature = "polars-algo")]
pub use polars_algo::prelude::*;
pub use polars_core::frame::groupby::*;
pub use polars_core::prelude::*;
pub use polars_core::utils::NoNull;
#[cfg(feature = "polars-io")]
pub use polars_io::prelude::*;
#[cfg(feature = "lazy")]
pub use polars_lazy::prelude::*; //`col` comes from `polars_lazy` crate
pub use polars_ops::prelude::*;
#[cfg(feature = "temporal")]
pub use polars_time::prelude::*;
like image 181
Abdul Niyas P M Avatar answered Sep 07 '25 21:09

Abdul Niyas P M