Search code examples
rustrust-polars

groupby_dynamic like method to support the interval index


something like a

#[derive(Clone, Debug)]
pub struct IntervalGroupOptions {
    pub index_column: String,
    /// start a window at this interval
    pub every: i32,
    /// window duration
    pub period: i32,
    /// offset window boundaries
    pub offset: i32,
    /// truncate the time column values to the window
    pub truncate: bool,
    // add the boundaries to the dataframe
    pub include_boundaries: bool,
    pub closed_window: ClosedWindow,
}

--> get the grouptuple and a broundary as a index


Solution

  • updated in https://github.com/pola-rs/polars/commit/f800a6418d90568798d92603237707dbe68c19bc

    currently can use

            .groupby_dynamic(
                vec![],
                DynamicGroupOptions {
                    index_column: "index".to_string(),
                    every: Duration::parse("48i"),
                    period: Duration::parse("240i"),
                    offset: Duration::parse("0i"),
                    truncate: false,
                    include_boundaries: true,
                    closed_window: ClosedWindow::Left,
                },
            )
            .agg([.........]).collect()