Skip to content

Commit

Permalink
fix null commutativity (#3479)
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed May 23, 2022
1 parent 0dfea6d commit 8575195
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
8 changes: 4 additions & 4 deletions polars/polars-core/src/chunked_array/comparison.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,14 @@ where
if let Some(value) = rhs.get(0) {
self.equal(value)
} else {
BooleanChunked::full("", false, self.len())
self.is_null()
}
}
(1, _) => {
if let Some(value) = self.get(0) {
rhs.equal(value)
} else {
BooleanChunked::full("", false, rhs.len())
self.is_null()
}
}
_ => {
Expand All @@ -94,14 +94,14 @@ where
if let Some(value) = rhs.get(0) {
self.not_equal(value)
} else {
BooleanChunked::full("", false, self.len())
self.is_not_null()
}
}
(1, _) => {
if let Some(value) = self.get(0) {
rhs.not_equal(value)
} else {
BooleanChunked::full("", false, rhs.len())
self.is_not_null()
}
}
_ => {
Expand Down
16 changes: 16 additions & 0 deletions polars/tests/it/lazy/expressions/arity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,3 +226,19 @@ fn test_when_then_otherwise_sum_in_agg() -> Result<()> {

Ok(())
}

#[test]
fn test_null_commutativity() {
let df = DataFrame::new_no_checks(vec![]);
let out = df
.lazy()
.select([
lit(1).neq(NULL.lit()).alias("a"),
NULL.lit().neq(1).alias("b"),
])
.collect()
.unwrap();

assert_eq!(out.column("a").unwrap().get(0), AnyValue::Boolean(true));
assert_eq!(out.column("b").unwrap().get(0), AnyValue::Boolean(true));
}

0 comments on commit 8575195

Please sign in to comment.