Repository: pola-rs/polars
File: py-polars/tests/unit/operations/test_join.py (Python)

Code before:
    assert_frame_equal(q.collect(), q.collect(optimizations=pl.QueryOptFlags.none()))


def test_join_coalesce_23177() -> None:
    df1 = pl.DataFrame(
        {
            "time": ["09:00:21"],
            "symbol": [5253],
        }
    )
    df2 = pl.DataFrame(
        {
            "symbol": [5253],
            "time": ["09:00:21"],  # note the switched column order, identical values.
        }
    )
    df = df1.lazy().join(df2.lazy(), on=["time", "symbol"], how="full", coalesce=True)

    buf = io.BytesIO()
    df.sink_csv(buf)

    expected = """time,symbol
09:00:21,5253
"""
    assert buf.getvalue().decode("utf-8") == expected

def test_join_filter_pushdown_iejoin_cse_23469() -> None:
    lf_x = pl.LazyFrame({"x": [1, 2, 3]})
    lf_y = pl.LazyFrame({"y": [1, 2, 3]})

    lf_xy = lf_x.join(lf_y, how="cross").filter(pl.col("x") > pl.col("y"))

    q = pl.concat([lf_xy, lf_xy])

    assert_frame_equal(
        q.collect().sort(pl.all()),
        pl.DataFrame(
            {
                "x": [2, 2, 3, 3, 3, 3],
                "y": [1, 1, 1, 1, 2, 2],
            },
        ),
    )

    q = pl.concat([lf_xy, lf_xy]).filter(pl.col("x") > pl.col("y"))

    assert_frame_equal(
        q.collect().sort(pl.all()),
        pl.DataFrame(
            {
                "x": [2, 2, 3, 3, 3, 3],

Review comment (suggestion):
```suggestion
def test_join_coalesce_column_order_23177() -> None:
    df1 = pl.DataFrame({"time": ["09:00:21"], "symbol": [5253]})
    df2 = pl.DataFrame({"symbol": [5253], "time": ["09:00:21"]})

    q = df1.lazy().join(df2.lazy(), on=["time", "symbol"], how="full", coalesce=True)

    expect = pl.DataFrame({"time": ["09:00:21"], "symbol": [5253]})

    assert_frame_equal(q.collect(), expect)

```

Code after:


def test_join_coalesce_column_order_23177() -> None:
    df1 = pl.DataFrame({"time": ["09:00:21"], "symbol": [5253]})
    df2 = pl.DataFrame({"symbol": [5253], "time": ["09:00:21"]})

    q = df1.lazy().join(df2.lazy(), on=["time", "symbol"], how="full", coalesce=True)

    expect = pl.DataFrame({"time": ["09:00:21"], "symbol": [5253]})

    assert_frame_equal(q.collect(), expect)


def test_join_filter_pushdown_iejoin_cse_23469() -> None:
    lf_x = pl.LazyFrame({"x": [1, 2, 3]})
    lf_y = pl.LazyFrame({"y": [1, 2, 3]})

    lf_xy = lf_x.join(lf_y, how="cross").filter(pl.col("x") > pl.col("y"))

    q = pl.concat([lf_xy, lf_xy])

    assert_frame_equal(
        q.collect().sort(pl.all()),
        pl.DataFrame(
            {
                "x": [2, 2, 3, 3, 3, 3],
                "y": [1, 1, 1, 1, 2, 2],
            },
        ),
    )

    q = pl.concat([lf_xy, lf_xy]).filter(pl.col("x") > pl.col("y"))

    assert_frame_equal(
        q.collect().sort(pl.all()),
        pl.DataFrame(
            {
                "x": [2, 2, 3, 3, 3, 3],
                "y": [1, 1, 1, 1, 2, 2],
            },
        ),
    )

    q = (
        lf_x.join_where(lf_y, pl.col("x") == pl.col("y"))
        .cache()
        .filter(pl.col("x") >= 0)
    )

    assert_frame_equal(
        q.collect().sort(pl.all()), pl.DataFrame({"x": [1, 2, 3], "y": [1, 2, 3]})