rustframes/dataframe/
series.rs

1#[derive(Debug, Clone, PartialEq)]
2pub enum Series {
3    Int64(Vec<i64>),
4    Float64(Vec<f64>),
5    Bool(Vec<bool>),
6    Utf8(Vec<String>),
7}
8
9impl Series {
10    pub fn len(&self) -> usize {
11        match self {
12            Series::Int64(v) => v.len(),
13            Series::Float64(v) => v.len(),
14            Series::Bool(v) => v.len(),
15            Series::Utf8(v) => v.len(),
16        }
17    }
18
19    pub fn is_empty(&self) -> bool {
20        self.len() == 0
21    }
22}
23
24impl From<Vec<i64>> for Series {
25    fn from(v: Vec<i64>) -> Self {
26        Series::Int64(v)
27    }
28}
29
30impl From<Vec<f64>> for Series {
31    fn from(v: Vec<f64>) -> Self {
32        Series::Float64(v)
33    }
34}
35
36impl From<Vec<bool>> for Series {
37    fn from(v: Vec<bool>) -> Self {
38        Series::Bool(v)
39    }
40}
41
42impl From<Vec<&str>> for Series {
43    fn from(v: Vec<&str>) -> Self {
44        Series::Utf8(v.into_iter().map(|s| s.to_string()).collect())
45    }
46}
47
48impl From<Vec<String>> for Series {
49    fn from(v: Vec<String>) -> Self {
50        Series::Utf8(v)
51    }
52}