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
use crate::prelude::*;
impl Series {
pub fn series_equal(&self, other: &Series) -> bool {
if self.len() != other.len() {
return false;
}
if self.null_count() != other.null_count() {
return false;
}
match self.eq(other).sum() {
None => false,
Some(sum) => sum as usize == self.len(),
}
}
pub fn series_equal_missing(&self, other: &Series) -> bool {
if self.len() != other.len() {
return false;
}
if self.null_count() != other.null_count() {
return false;
}
if self.null_count() == self.len() {
return true;
}
match self.eq_missing(other).sum() {
None => false,
Some(sum) => sum as usize == self.len(),
}
}
}
impl DataFrame {
pub fn frame_equal(&self, other: &DataFrame) -> bool {
if self.shape() != other.shape() {
return false;
}
for (left, right) in self.get_columns().iter().zip(other.get_columns()) {
if !left.series_equal(right) {
return false;
}
}
true
}
pub fn frame_equal_missing(&self, other: &DataFrame) -> bool {
if self.shape() != other.shape() {
return false;
}
for (left, right) in self.get_columns().iter().zip(other.get_columns()) {
if !left.series_equal_missing(right) {
return false;
}
}
true
}
}
#[cfg(test)]
mod test {
use crate::prelude::*;
#[test]
fn test_series_equal() {
let a = Series::new("a", &[1, 2, 3]);
let b = Series::new("b", &[1, 2, 3]);
assert!(a.series_equal(&b));
let s = Series::new("foo", &[None, Some(1i64)]);
assert!(s.series_equal_missing(&s));
}
#[test]
fn test_df_equal() {
let a = Series::new("a", [1, 2, 3].as_ref());
let b = Series::new("b", [1, 2, 3].as_ref());
let df1 = DataFrame::new(vec![a, b]).unwrap();
let df2 = df1.clone();
assert!(df1.frame_equal(&df2))
}
}