diff --git a/crates/polars-core/src/chunked_array/comparison/mod.rs b/crates/polars-core/src/chunked_array/comparison/mod.rs index 300f5f338cff..72faab7cc5ef 100644 --- a/crates/polars-core/src/chunked_array/comparison/mod.rs +++ b/crates/polars-core/src/chunked_array/comparison/mod.rs @@ -720,22 +720,13 @@ where BooleanChunked::full(PlSmallStr::EMPTY, value, a.len()) } else { let (a, b) = align_chunks_binary(a, b); - let mut out = a + let out = a .fields_as_series() .iter() .zip(b.fields_as_series().iter()) .map(|(l, r)| op(l, r)) .reduce(reduce) .unwrap(); - if a.null_count() > 0 || b.null_count() > 0 { - let mut a = a.into_owned(); - a.zip_outer_validity(&b); - unsafe { - for (arr, a) in out.downcast_iter_mut().zip(a.downcast_iter()) { - arr.set_validity(a.validity().cloned()) - } - } - } out } } diff --git a/py-polars/tests/unit/operations/test_comparison.py b/py-polars/tests/unit/operations/test_comparison.py index 72771ff64eab..89254473f501 100644 --- a/py-polars/tests/unit/operations/test_comparison.py +++ b/py-polars/tests/unit/operations/test_comparison.py @@ -158,6 +158,30 @@ def test_missing_equality_on_bools() -> None: ] +def test_struct_equality_18870() -> None: + s = pl.Series([{"a": 1}, None]) + + # eq + result = s.eq(s).to_list() + expected = [True, None] + assert result == expected + + # ne + result = s.ne(s).to_list() + expected = [False, None] + assert result == expected + + # eq_missing + result = s.eq_missing(s).to_list() + expected = [True, True] + assert result == expected + + # ne_missing + result = s.ne_missing(s).to_list() + expected = [False, False] + assert result == expected + + def isnan(x: Any) -> bool: return isinstance(x, float) and math.isnan(x)