Skip to content

Commit 8cc7bd6

Browse files
committed
Add support for join_keys as a positional argument
1 parent 99aba0b commit 8cc7bd6

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

python/datafusion/dataframe.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ def join(
406406
def join(
407407
self,
408408
right: DataFrame,
409-
on: str | Sequence[str] | None = None,
409+
on: str | Sequence[str] | tuple[list[str], list[str]] | None = None,
410410
how: Literal["inner", "left", "right", "full", "semi", "anti"] = "inner",
411411
*,
412412
left_on: str | Sequence[str] | None = None,
@@ -429,6 +429,14 @@ def join(
429429
Returns:
430430
DataFrame after join.
431431
"""
432+
# This check is to prevent breaking API changes where users prior to
433+
# DF 43.0.0 would pass the join_keys as a positional argument instead
434+
# of a keyword argument.
435+
if isinstance(on, tuple) and len(on) == 2:
436+
if isinstance(on[0], list) and isinstance(on[1], list):
437+
join_keys = on # type: ignore
438+
on = None
439+
432440
if join_keys is not None:
433441
warnings.warn(
434442
"`join_keys` is deprecated, use `on` or `left_on` with `right_on`",

python/tests/test_dataframe.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,16 @@ def test_join():
337337
expected = {"a": [1, 2], "c": [8, 10], "b": [4, 5]}
338338
assert table.to_pydict() == expected
339339

340+
# Verify we don't make a breaking change to pre-43.0.0
341+
# where users would pass join_keys as a positional argument
342+
df2 = df.join(df1, (["a"], ["a"]), how="inner") # type: ignore
343+
df2.show()
344+
df2 = df2.sort(column("l.a"))
345+
table = pa.Table.from_batches(df2.collect())
346+
347+
expected = {"a": [1, 2], "c": [8, 10], "b": [4, 5]}
348+
assert table.to_pydict() == expected
349+
340350

341351
def test_join_invalid_params():
342352
ctx = SessionContext()

0 commit comments

Comments
 (0)