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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134

use super::*;
use std::iter::Iterator;
use std::fmt::Debug;
use std::ops::{Add, Sub, Mul, Div};
use num::traits::{One, Zero};
use ndarray::ArrayView1;

pub trait UtahNum
    : Add<Output = Self> +
      Div<Output = Self> +
      Sub<Output = Self> +
      Mul<Output = Self> +
      Empty<Self> +
      One +
      Zero +
      Clone +
      Debug +
      PartialEq +
      Default
    {}

impl<T> UtahNum for T
    where T: Add<Output = T> +
             Div<Output = T> +
             Sub<Output = T> +
             Mul<Output = T> +
             Empty<T> +
             One +
             Zero +
             Clone +
             Debug +
             PartialEq +
             Default
{
}


pub trait Empty<T> {
    fn empty() -> T;
    fn is_empty(&self) -> bool;
}

pub trait Constructor<'a, T>
    where T: 'a + UtahNum,
          Self: Sized
{
    fn new<U: Clone + Debug>(data: Matrix<U>) -> DataFrame<T> where T: From<U>;
    fn from_array<U: Clone>(data: Row<U>, axis: UtahAxis) -> DataFrame<T> where T: From<U>;
    fn index<U: Clone>(self, index: &'a [U]) -> Result<Self> where String: From<U>;
    fn columns<U: Clone>(self, columns: &'a [U]) -> Result<Self> where String: From<U>;
    fn df_iter(&'a self, axis: UtahAxis) -> DataFrameIterator<'a, T>;
    fn df_iter_mut(&'a mut self, axis: UtahAxis) -> DataFrameMutIterator<'a, T>;
}


pub trait Operations<'a, T>
    where T: 'a + UtahNum
{
    fn shape(self) -> (usize, usize);
    fn select<U: ?Sized>(&'a self, names: &'a [&'a U], axis: UtahAxis) -> SelectIter<'a, T>
        where String: From<&'a U>;
    fn remove<U: ?Sized>(&'a self, names: &'a [&'a U], axis: UtahAxis) -> RemoveIter<'a, T>
        where String: From<&'a U>;
    fn append<U: ?Sized>(&'a mut self,
                         name: &'a U,
                         data: ArrayView1<'a, T>,
                         axis: UtahAxis)
                         -> AppendIter<'a, T>
        where String: From<&'a U>;
    fn inner_left_join(&'a self, other: &'a DataFrame<T>) -> InnerJoinIter<'a, T>;
    fn outer_left_join(&'a self, other: &'a DataFrame<T>) -> OuterJoinIter<'a, T>;
    fn inner_right_join(&'a self, other: &'a DataFrame<T>) -> InnerJoinIter<'a, T>;
    fn outer_right_join(&'a self, other: &'a DataFrame<T>) -> OuterJoinIter<'a, T>;
    fn concat(&'a self, other: &'a DataFrame<T>, axis: UtahAxis) -> ConcatIter<'a, T>;
    fn sumdf(&'a mut self, axis: UtahAxis) -> SumIter<'a, T>;
    fn mean(&'a mut self, axis: UtahAxis) -> MeanIter<'a, T>;
    fn maxdf(&'a mut self, axis: UtahAxis) -> MaxIter<'a, T>;
    fn mindf(&'a mut self, axis: UtahAxis) -> MinIter<'a, T>;
    fn mapdf<F>(&'a mut self, f: F, axis: UtahAxis) -> MapDFIter<'a, T, F>
        where F: Fn(T) -> T,
              for<'r> F: Fn(T) -> T;
    fn impute(&'a mut self, strategy: ImputeStrategy, axis: UtahAxis) -> ImputeIter<'a, T>;
}

pub trait Aggregate<'a, T>
    where T: UtahNum
{
    fn sumdf(self) -> Sum<'a, Self, T> where Self: Sized + Iterator<Item = Window<'a, T>>;

    fn maxdf(self) -> Max<'a, Self, T> where Self: Sized + Iterator<Item = Window<'a, T>>;

    fn mindf(self) -> Min<'a, Self, T> where Self: Sized + Iterator<Item = Window<'a, T>>;

    fn mean(self) -> Mean<'a, Self, T> where Self: Sized + Iterator<Item = Window<'a, T>>;
}

pub trait Process<'a, T, F>
    where T: UtahNum,
          F: Fn(T) -> T
{
    fn impute(self, strategy: ImputeStrategy) -> Impute<'a, Self, T>
        where Self: Sized + Iterator<Item = WindowMut<'a, T>>;
    fn to_mut_df(self) -> DataFrameMut<'a, T> where Self: Sized + Iterator<Item = WindowMut<'a, T>>;
    fn mapdf(self, f: F) -> MapDF<'a, T, Self, F>
        where Self: Sized + Iterator<Item = WindowMut<'a, T>> + Clone;
}

pub trait Transform<'a, T>
    where T: UtahNum + 'a
{
    fn select<U: ?Sized>(self, names: &'a [&'a U]) -> Select<'a, Self, T>
        where Self: Sized + Iterator<Item = Window<'a, T>> + Clone,
              String: From<&'a U>,
              T: 'a;
    fn remove<U: ?Sized>(self, names: &'a [&'a U]) -> Remove<'a, Self, T>
        where Self: Sized + Iterator<Item = Window<'a, T>> + Clone,
              String: From<&'a U>,
              T: 'a;
    fn append<U: ?Sized>(self, name: &'a U, data: ArrayView1<'a, T>) -> Append<'a, Self, T>
        where Self: Sized + Iterator<Item = Window<'a, T>> + Clone,
              String: From<&'a U>,
              T: 'a;
}



pub trait ToDataFrame<'a, I, T>
    where T: UtahNum + 'a
{
    fn as_df(self) -> Result<DataFrame<T>> where Self: Sized + Iterator<Item = I>;
    fn as_matrix(self) -> Result<Matrix<T>> where Self: Sized + Iterator<Item = I>;
    fn as_array(self) -> Result<Row<T>> where Self: Sized + Iterator<Item = I>;
}