0

I have use Polars in my Cargo.toml like this:

polars = { version = "0.24.3", features = ["lazy", "temporal", "ipc", "ipc_streaming", "dtype-datetime"] }

I have a Series extracted from a DataFrame that has datetime[ns] without a timezone. I now would like to convert this data into chrono objects, but I am not sure how. This is what I tried:

c.iter().for_each(|r| {
    let c: chrono::DateTime<chrono::Utc> = r.into();
});

Unfortunately, the compiler says this does not work - and none of the other implementations seem useful to me:

error[E0277]: the trait bound `polars::export::chrono::DateTime<Utc>: From<polars::prelude::AnyValue<'_>>` is not satisfied
  --> src/main.rs:21:46
   |
21 |     let c: chrono::DateTime<chrono::Utc> = r.into();
   |                                              ^^^^ the trait `From<polars::prelude::AnyValue<'_>>` is not implemented for `polars::export::chrono::DateTime<Utc>`
   |
   = help: the following other types implement trait `From<T>`:
             <polars::export::chrono::DateTime<FixedOffset> as From<polars::export::chrono::DateTime<Local>>>
             <polars::export::chrono::DateTime<FixedOffset> as From<polars::export::chrono::DateTime<Utc>>>
             <polars::export::chrono::DateTime<Local> as From<SystemTime>>
             <polars::export::chrono::DateTime<Local> as From<polars::export::chrono::DateTime<FixedOffset>>>
             <polars::export::chrono::DateTime<Local> as From<polars::export::chrono::DateTime<Utc>>>
             <polars::export::chrono::DateTime<Utc> as From<SystemTime>>
             <polars::export::chrono::DateTime<Utc> as From<polars::export::chrono::DateTime<FixedOffset>>>
             <polars::export::chrono::DateTime<Utc> as From<polars::export::chrono::DateTime<Local>>>
   = note: required because of the requirements on the impl of `Into<polars::export::chrono::DateTime<Utc>>` for `polars::prelude::AnyValue<'_>````
SirVer
  • 1,397
  • 1
  • 16
  • 15

1 Answers1

0

I now realized that I can directly cast the series, so this seems to work:

let v: Vec<_> = c.datetime()?.as_datetime_iter().map(|b| b.unwrap()).collect();
SirVer
  • 1,397
  • 1
  • 16
  • 15