Skip to content

Commit

Permalink
[Rust] PartialEq for DataFrame (#1838)
Browse files Browse the repository at this point in the history
  • Loading branch information
ibENPC committed Nov 21, 2021
1 parent a5e7f8d commit be19af6
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions polars/polars-core/src/testing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,17 @@ impl DataFrame {
}
}

impl PartialEq for DataFrame {
fn eq(&self, other: &Self) -> bool {
self.shape() == other.shape()
&& self
.columns
.iter()
.zip(other.columns.iter())
.all(|(s1, s2)| s1 == s2)
}
}

#[cfg(test)]
mod test {
use crate::prelude::*;
Expand Down Expand Up @@ -150,4 +161,23 @@ mod test {
assert_ne!(s2, s3);
assert_ne!(s4, s4);
}

#[test]
fn test_df_partialeq() {
let df1 = df!("a" => &[1, 2, 3],
"b" => &[4, 5, 6])
.unwrap();
let df2 = df!("b" => &[4, 5, 6],
"a" => &[1, 2, 3])
.unwrap();
let df3 = df!("" => &[Some(1), None]).unwrap();
let df4 = df!("" => &[f32::NAN]).unwrap();

assert_eq!(df1, df1);
assert_ne!(df1, df2);
assert_eq!(df2, df2);
assert_ne!(df2, df3);
assert_eq!(df3, df3);
assert_ne!(df4, df4);
}
}

0 comments on commit be19af6

Please sign in to comment.