I'm working with the Polars library in Rust and am struggling to find documentation related to its dtype-datetime feature, especially when compared to its Python counterpart which seems a lot richer with examples.
My goal is to create a dataframe with a column of datetime type. For the purposes of this post, I'll focus only on this column, but please note that my actual dataframe will have multiple columns. I want to use the df!
macro with existing Vectors, as shown:
df!(
"datetime_col" => datetime_vec
)
The datetime_vec
would be populated with timestamps, and I've been trying to use the chrono
crate (I'm open to suggestions):
let datetime_vec: Vec<i64> = vec![];
...
datetime_vec.push(Utc::now().timestamp_millis());
However, I'm unsure how to utilize this vector with the df!
macro such that the column will be recognized as a datetime
type. Ideally, it would be done in a way that minimizes allocations and yields best performance.
Has anyone faced this issue? What's the recommended approach? While I did look at Polars' datetime unit tests for clues (linked here), it seems they focus on converting from string to datetime. I need a way to go from i64 to datetime.