0

If I have a a a collection of NaiveDateTimes in a Vec how can I create a ChunkedArray and ultimately a Series from this ?

For ints and floats I can do

let sensor_id_col_values = (0..=20).flat_map(|i| vec![i; 5]).collect();
let sensor_id_col = Int32Chunked::from_vec("sensor_id", sensor_id_col_values).into_series();

But the methods like from_vec don't exist for Datetimes it seems.

After fighting for hours even with GPT-4 I am no closer.

Thanks

Glenn Pierce
  • 720
  • 1
  • 6
  • 18

1 Answers1

0
let start_time = NaiveDateTime::parse_from_str("2023-04-18 00:00:00", "%Y-%m-%d %H:%M:%S").unwrap();

let datetime_col_values: Vec<NaiveDateTime> = (0..=20)
                .flat_map(|i| {
                    let start = start_time + chrono::Duration::minutes(i);
                    (0..5).map(move |_| start)
                })
                .collect::<Vec<_>>();

let datetime_series = DatetimeChunked::from_naive_datetime("ts", datetime_col_values, TimeUnit::Nanoseconds).into_series();
Glenn Pierce
  • 720
  • 1
  • 6
  • 18