Skip to content

Commit

Permalink
fix(python): Don't enforce row order in join test results where not g…
Browse files Browse the repository at this point in the history
…uaranteed (#17596)
  • Loading branch information
brandon-b-miller authored Jul 12, 2024
1 parent f61af0f commit da1ce87
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
7 changes: 4 additions & 3 deletions py-polars/tests/unit/sql/test_joins.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,15 +435,15 @@ def test_natural_joins_01() -> None:


@pytest.mark.parametrize(
("cols_constraint", "expected"),
("cols_constraint", "expect_data"),
[
(">= 5", [(8, 8, 6)]),
("< 7", [(5, 4, 4)]),
("< 8", [(5, 4, 4), (7, 4, 4), (0, 7, 2)]),
("!= 4", [(8, 8, 6), (2, 8, 6), (0, 7, 2)]),
],
)
def test_natural_joins_02(cols_constraint: str, expected: list[tuple[int]]) -> None:
def test_natural_joins_02(cols_constraint: str, expect_data: list[tuple[int]]) -> None:
df1 = pl.DataFrame( # noqa: F841
{
"x": [1, 5, 3, 8, 6, 7, 4, 0, 2],
Expand All @@ -464,4 +464,5 @@ def test_natural_joins_02(cols_constraint: str, expected: list[tuple[int]]) -> N
"""
).collect()

assert actual.rows() == expected
expected = pl.DataFrame(expect_data, schema=actual.columns, orient="row")
assert_frame_equal(actual, expected, check_row_order=False)
6 changes: 5 additions & 1 deletion py-polars/tests/unit/streaming/test_streaming.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,11 @@ def test_streaming_generic_left_and_inner_join_from_disk(tmp_path: Path) -> None
join_strategies: list[JoinStrategy] = ["left", "inner"]
for how in join_strategies:
q = lf0.join(lf1, left_on="id", right_on="id_r", how=how)
assert_frame_equal(q.collect(streaming=True), q.collect(streaming=False))
assert_frame_equal(
q.collect(streaming=True),
q.collect(streaming=False),
check_row_order=how == "left",
)


def test_streaming_9776() -> None:
Expand Down
14 changes: 10 additions & 4 deletions py-polars/tests/unit/streaming/test_streaming_join.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def test_streaming_full_outer_joins() -> None:
)
a = q.collect(streaming=True)
b = q.collect(streaming=False)
assert_frame_equal(a, b)
assert_frame_equal(a, b, check_row_order=False)


def test_streaming_joins() -> None:
Expand Down Expand Up @@ -167,7 +167,9 @@ def test_join_null_matches(streaming: bool) -> None:
# Inner
expected = pl.DataFrame({"idx_a": [2, 1], "a": [2, 1], "idx_b": [1, 2]})
assert_frame_equal(
df_a.join(df_b, on="a", how="inner").collect(streaming=streaming), expected
df_a.join(df_b, on="a", how="inner").collect(streaming=streaming),
expected,
check_row_order=False,
)

# Left outer
Expand All @@ -186,7 +188,9 @@ def test_join_null_matches(streaming: bool) -> None:
"a_right": [None, 2, 1, None, None],
}
)
assert_frame_equal(df_a.join(df_b, on="a", how="full").collect(), expected)
assert_frame_equal(
df_a.join(df_b, on="a", how="full").collect(), expected, check_row_order=False
)


@pytest.mark.parametrize("streaming", [False, True])
Expand Down Expand Up @@ -229,7 +233,9 @@ def test_join_null_matches_multiple_keys(streaming: bool) -> None:
}
)
assert_frame_equal(
df_a.join(df_b, on=["a", "idx"], how="full").sort("a").collect(), expected
df_a.join(df_b, on=["a", "idx"], how="full").sort("a").collect(),
expected,
check_row_order=False,
)


Expand Down

0 comments on commit da1ce87

Please sign in to comment.