1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
use util::error::*;
use util::types::*;
use std::iter::Iterator;
use ndarray::{AxisIter, AxisIterMut};
use util::traits::*;
use std::slice::Iter;
use ndarray::{ArrayView1, ArrayViewMut1, Dim, Ix};
#[derive(Debug, Clone, PartialEq)]
pub struct DataFrame<T>
where T: UtahNum
{
pub columns: Vec<String>,
pub data: Matrix<T>,
pub index: Vec<String>,
}
#[derive(Debug, PartialEq)]
pub struct DataFrameMut<'a, T: 'a>
where T: UtahNum
{
pub columns: Vec<String>,
pub data: MatrixMut<'a, T>,
pub index: Vec<String>,
}
#[derive(Clone)]
pub struct DataFrameIterator<'a, T: 'a>
where T: UtahNum
{
pub names: Iter<'a, String>,
pub data: AxisIter<'a, T, Dim<[Ix; 1]>>,
pub other: Vec<String>,
pub axis: UtahAxis,
}
impl<'a, T> Iterator for DataFrameIterator<'a, T>
where T: UtahNum
{
type Item = (String, ArrayView1<'a, T>);
fn next(&mut self) -> Option<Self::Item> {
match self.names.next() {
Some(val) => {
match self.data.next() {
Some(dat) => Some((val.clone(), dat)),
None => None,
}
}
None => None,
}
}
}
pub struct DataFrameMutIterator<'a, T>
where T: UtahNum + 'a
{
pub names: Iter<'a, String>,
pub data: AxisIterMut<'a, T, Dim<[Ix; 1]>>,
pub other: Vec<String>,
pub axis: UtahAxis,
}
impl<'a, T> Iterator for DataFrameMutIterator<'a, T>
where T: UtahNum
{
type Item = (String, ArrayViewMut1<'a, T>);
fn next(&mut self) -> Option<Self::Item> {
match self.names.next() {
Some(val) => {
match self.data.next() {
Some(dat) => Some((val.clone(), dat)),
None => None,
}
}
None => None,
}
}
}
impl<'a, T> DataFrameMut<'a, T>
where T: 'a + UtahNum
{
pub fn to_df(self) -> Result<DataFrame<T>> {
let d = self.data.map(|x| ((*x).clone()));
let df = DataFrame::new(d).columns(&self.columns[..])?.index(&self.index[..])?;
Ok(df)
}
}