Skip to content

Commit

Permalink
Merge pull request #30 from raisadz/increase-coverage
Browse files Browse the repository at this point in the history
Modify pandas-like merge to have the same behaviour as in Polars
  • Loading branch information
MarcoGorelli authored Mar 28, 2024
2 parents cc56729 + fb75c28 commit 9cf4502
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 7 deletions.
7 changes: 1 addition & 6 deletions narwhals/pandas_like/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,18 +177,13 @@ def join(
if isinstance(right_on, str):
right_on = [right_on]

if overlap := (set(self.columns) - set(left_on)).intersection(
set(other.columns) - set(right_on),
):
msg = f"Found overlapping columns in join: {overlap}. Please rename columns to avoid this."
raise ValueError(msg)

return self._from_dataframe(
self._dataframe.merge(
other._dataframe,
left_on=left_on,
right_on=right_on,
how=how,
suffixes=("", "_right"),
),
)

Expand Down
2 changes: 1 addition & 1 deletion tests/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def test_rename(df_raw: Any) -> None:
@pytest.mark.parametrize("df_raw", [df_pandas, df_lazy])
def test_join(df_raw: Any) -> None:
df = nw.LazyFrame(df_raw)
df_right = df.rename({"z": "z_right"})
df_right = df
result = df.join(df_right, left_on=["a", "b"], right_on=["a", "b"], how="inner")
result_native = nw.to_native(result)
expected = {"a": [1, 3, 2], "b": [4, 4, 6], "z": [7.0, 8, 9], "z_right": [7.0, 8, 9]}
Expand Down

0 comments on commit 9cf4502

Please sign in to comment.