Skip to content

Commit

Permalink
fix overflow hash join; did not matter in release
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Nov 17, 2021
1 parent fa73629 commit 3da75f9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
17 changes: 16 additions & 1 deletion polars/polars-core/src/frame/hash_join/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1825,7 +1825,6 @@ mod test {

#[test]
#[cfg_attr(miri, ignore)]
#[cfg(feature = "dtype-u64")]
fn test_join_floats() -> Result<()> {
let df_a = df! {
"a" => &[1.0, 2.0, 1.0, 1.0],
Expand Down Expand Up @@ -1869,4 +1868,20 @@ mod test {
);
Ok(())
}

#[test]
#[cfg_attr(miri, ignore)]
fn test_join_nulls() -> Result<()> {
let a = df![
"a" => [Some(1), None, None]
]?;
let b = df![
"a" => [Some(1), None, None, None, None]
]?;

let out = a.inner_join(&b, "a", "a")?;

assert_eq!(out.shape(), (9, 1));
Ok(())
}
}
6 changes: 3 additions & 3 deletions polars/polars-core/src/vector_hasher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,15 +248,15 @@ impl AsU64 for Option<u32> {
fn as_u64(self) -> u64 {
match self {
Some(v) => v as u64,
// just a number
None => u64::MAX,
// just a number safe from overflow
None => u64::MAX >> 2,
}
}
}

impl AsU64 for Option<u64> {
fn as_u64(self) -> u64 {
self.unwrap_or(u64::MAX)
self.unwrap_or(u64::MAX >> 2)
}
}

Expand Down

0 comments on commit 3da75f9

Please sign in to comment.