Skip to content

Commit

Permalink
docstring and fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Sep 7, 2024
1 parent 3e2121d commit 0cd7540
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 2 deletions.
37 changes: 37 additions & 0 deletions py-polars/polars/dataframe/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -7110,6 +7110,43 @@ def join_where(
For example: `pl.col("time") >= pl.col("duration")`
suffix
Suffix to append to columns with a duplicate name.
Examples
--------
>>> east = pl.DataFrame(
... {
... "id": [100, 101, 102],
... "dur": [120, 140, 160],
... "rev": [12, 14, 16],
... "cores": [2, 8, 4],
... }
...)
>>> west = pl.DataFrame(
... {
... "t_id": [404, 498, 676, 742],
... "time": [90, 130, 150, 170],
... "cost": [9, 13, 15, 16],
... "cores": [4, 2, 1, 4],
... }
... )
>>> east.join_where(
>>> west,
>>> pl.col("dur") < pl.col("time"),
>>> pl.col("rev") < pl.col("cost"),
>>> )
shape: (5, 8)
┌─────┬─────┬─────┬───────┬──────┬──────┬──────┬─────────────┐
│ id ┆ dur ┆ rev ┆ cores ┆ t_id ┆ time ┆ cost ┆ cores_right │
│ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- │
│ i64 ┆ i64 ┆ i64 ┆ i64 ┆ i64 ┆ i64 ┆ i64 ┆ i64 │
╞═════╪═════╪═════╪═══════╪══════╪══════╪══════╪═════════════╡
│ 100 ┆ 120 ┆ 12 ┆ 2 ┆ 498 ┆ 130 ┆ 13 ┆ 2 │
│ 100 ┆ 120 ┆ 12 ┆ 2 ┆ 676 ┆ 150 ┆ 15 ┆ 1 │
│ 100 ┆ 120 ┆ 12 ┆ 2 ┆ 742 ┆ 170 ┆ 16 ┆ 4 │
│ 101 ┆ 140 ┆ 14 ┆ 8 ┆ 676 ┆ 150 ┆ 15 ┆ 1 │
│ 101 ┆ 140 ┆ 14 ┆ 8 ┆ 742 ┆ 170 ┆ 16 ┆ 4 │
└─────┴─────┴─────┴───────┴──────┴──────┴──────┴─────────────┘
"""
if not isinstance(other, DataFrame):
msg = f"expected `other` join table to be a DataFrame, got {type(other).__name__!r}"
Expand Down
39 changes: 38 additions & 1 deletion py-polars/polars/lazyframe/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -4569,7 +4569,7 @@ def join_where(
suffix: str = "_right",
) -> LazyFrame:
"""
Perform a join based on one or multiple equality predicates.
Perform a join based on one or multiple (in)equality predicates.
A row from this table may be included in zero or multiple rows in the result,
and the relative order of rows may differ between the input and output tables.
Expand All @@ -4586,6 +4586,43 @@ def join_where(
For example: `pl.col("time") >= pl.col("duration")`
suffix
Suffix to append to columns with a duplicate name.
Examples
--------
>>> east = pl.LazyFrame(
... {
... "id": [100, 101, 102],
... "dur": [120, 140, 160],
... "rev": [12, 14, 16],
... "cores": [2, 8, 4],
... }
...)
>>> west = pl.LazyFrame(
... {
... "t_id": [404, 498, 676, 742],
... "time": [90, 130, 150, 170],
... "cost": [9, 13, 15, 16],
... "cores": [4, 2, 1, 4],
... }
... )
>>> east.join_where(
>>> west,
>>> pl.col("dur") < pl.col("time"),
>>> pl.col("rev") < pl.col("cost"),
>>> )
shape: (5, 8)
┌─────┬─────┬─────┬───────┬──────┬──────┬──────┬─────────────┐
│ id ┆ dur ┆ rev ┆ cores ┆ t_id ┆ time ┆ cost ┆ cores_right │
│ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- │
│ i64 ┆ i64 ┆ i64 ┆ i64 ┆ i64 ┆ i64 ┆ i64 ┆ i64 │
╞═════╪═════╪═════╪═══════╪══════╪══════╪══════╪═════════════╡
│ 100 ┆ 120 ┆ 12 ┆ 2 ┆ 498 ┆ 130 ┆ 13 ┆ 2 │
│ 100 ┆ 120 ┆ 12 ┆ 2 ┆ 676 ┆ 150 ┆ 15 ┆ 1 │
│ 100 ┆ 120 ┆ 12 ┆ 2 ┆ 742 ┆ 170 ┆ 16 ┆ 4 │
│ 101 ┆ 140 ┆ 14 ┆ 8 ┆ 676 ┆ 150 ┆ 15 ┆ 1 │
│ 101 ┆ 140 ┆ 14 ┆ 8 ┆ 742 ┆ 170 ┆ 16 ┆ 4 │
└─────┴─────┴─────┴───────┴──────┴──────┴──────┴─────────────┘
"""
if not isinstance(other, LazyFrame):
msg = f"expected `other` join table to be a LazyFrame, not a {type(other).__name__!r}"
Expand Down
1 change: 0 additions & 1 deletion py-polars/tests/unit/io/test_delta.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,6 @@ def test_write_delta_with_merge(tmp_path: Path) -> None:
)

assert isinstance(merger, TableMerger)
assert merger.predicate == "s.a = t.a"
assert merger.source_alias == "s"
assert merger.target_alias == "t"

Expand Down

0 comments on commit 0cd7540

Please sign in to comment.