Skip to content

Commit

Permalink
working version with test
Browse files Browse the repository at this point in the history
  • Loading branch information
barak1412 committed Sep 30, 2024
1 parent c23266b commit d7316f7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
6 changes: 3 additions & 3 deletions crates/polars-core/src/chunked_array/comparison/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,7 @@ where
.reduce(reduce)
.unwrap();

if !is_missing & (a.null_count() > 0 || b.null_count() > 0) {
if !is_missing && (a.null_count() > 0 || b.null_count() > 0) {
let mut a = a.into_owned();
a.zip_outer_validity(&b);
unsafe {
Expand All @@ -801,7 +801,7 @@ impl ChunkCompareEq<&StructChunked> for StructChunked {
struct_helper(
self,
rhs,
|l, r| l.equal(r).unwrap(),
|l, r| l.equal_missing(r).unwrap(),
|a, b| a.bitand(b),
false,
false,
Expand All @@ -823,7 +823,7 @@ impl ChunkCompareEq<&StructChunked> for StructChunked {
struct_helper(
self,
rhs,
|l, r| l.not_equal(r).unwrap(),
|l, r| l.not_equal_missing(r).unwrap(),
|a, b| a | b,
true,
false,
Expand Down
19 changes: 19 additions & 0 deletions py-polars/tests/unit/operations/test_comparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,25 @@ def test_struct_equality_18870() -> None:
assert result == expected


def test_struct_nested_equality() -> None:
df = pl.DataFrame(
{
"a": [{"foo": 0, "bar": "1"}, {"foo": None, "bar": "1"}, None],
"b": [{"foo": 0, "bar": "1"}] * 3,
}
)

# eq
ans = df.select(pl.col("a").eq(pl.col("b")))
expected = pl.DataFrame({"a": [True, False, None]})
assert_frame_equal(ans, expected)

# ne
ans = df.select(pl.col("a").ne(pl.col("b")))
expected = pl.DataFrame({"a": [False, True, None]})
assert_frame_equal(ans, expected)


def isnan(x: Any) -> bool:
return isinstance(x, float) and math.isnan(x)

Expand Down

0 comments on commit d7316f7

Please sign in to comment.