blackjack/dataframe/
dataframe_groupby.rs

1//! DataFrame `groupby` functionality.
2
3use num::*;
4use std::iter::Sum;
5
6use crate::prelude::*;
7
8/// [`DataFrame::groupby`]  result.
9/// Contains the split series by key
10pub struct DataFrameGroupBy<T>
11where
12    T: BlackJackData,
13{
14    groups: Vec<SeriesGroupBy<T>>,
15}
16
17impl<T> DataFrameGroupBy<T>
18where
19    T: BlackJackData + 'static,
20{
21    /// Construct a new [`DataFrameGroupBy`] from a collection of [`SeiresGroupBy`]
22    /// structs; shouldn't be needed to be used directly.
23    pub fn new(groups: Vec<SeriesGroupBy<T>>) -> Self {
24        DataFrameGroupBy { groups }
25    }
26
27    /// Sum this grouped dataframe object.
28    /// basically calls `sum` in parallel on each grouped series collected.
29    pub fn sum(&self) -> DataFrame<i32>
30    // TODO:
31    where
32        T: BlackJackData + Copy + Sum + Num + Send + Ord,
33    {
34        // TODO: Return result
35
36        let mut df = DataFrame::new();
37
38        let _ = self
39            .groups
40            .iter()
41            .map(|series_groupby| series_groupby.sum())
42            .map(|series| df.add_column(series).unwrap())
43            .collect::<Vec<()>>();
44        df
45    }
46}