4

I want to iterate over DateChunked using map and use the date element. But iterating over gives me i32. How I can use date?

Running below code complains.

use polars::export::chrono::{NaiveDate};
fn main() {
    let df = df! [
        "date_series" => [NaiveDate::from_ymd(2020, 1, 1), NaiveDate::from_ymd(2020, 1, 2), NaiveDate::from_ymd(2020, 1, 3)]
    ].unwrap();
    
    let a: DateChunked = df["date_series"].date().unwrap().into_iter().map(|d| {
        match d {
            Some(d) => Some(d),
            None => None
        }
    }).collect();
}

complains

     }).collect();
     |        ^^^^^^^ value of type `Logical<DateType, Int32Type>` cannot be built from `std::iter::Iterator<Item=Option<i32>>`
Kushdesh
  • 1,118
  • 10
  • 16
  • 4
    `.as_date_iter()` maybe? https://docs.rs/polars/0.21.1/polars/datatypes/struct.Logical.html#method.as_date_iter – Dogbert Jun 11 '22 at 14:25

0 Answers0