Skip to content

Commit

Permalink
python fix lazy self join (#2733)
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Feb 23, 2022
1 parent fedeb0d commit aa249e4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion py-polars/src/lazy/dataframe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ impl PyLazyFrame {

#[allow(clippy::too_many_arguments)]
pub fn join(
&mut self,
&self,
other: PyLazyFrame,
left_on: Vec<PyExpr>,
right_on: Vec<PyExpr>,
Expand Down
24 changes: 24 additions & 0 deletions py-polars/tests/test_lazy.py
Original file line number Diff line number Diff line change
Expand Up @@ -1151,3 +1151,27 @@ def test_nested_min_max() -> None:
out = df.with_column(pl.max([pl.min(["a", "b"]), pl.min(["c", "d"])]).alias("t"))
assert out.shape == (1, 5)
assert out["t"][0] == 3


def test_self_join() -> None:
# 2720
df = pl.from_dict(
data={
"employee_id": [100, 101, 102],
"employee_name": ["James", "Alice", "Bob"],
"manager_id": [None, 100, 101],
}
).lazy()

out = (
df.join(ldf=df, left_on="manager_id", right_on="employee_id", how="left")
.select(
exprs=[
pl.col("employee_id"),
pl.col("employee_name"),
pl.col("employee_name_right").alias("manager_name"),
]
)
.fetch()
)
assert out.shape == (3, 3)

0 comments on commit aa249e4

Please sign in to comment.