Skip to content

Commit 4450eda

Browse files
committed
BUG: raise MergeError when both right_on and right_index are specified
1 parent 945385d commit 4450eda

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

pandas/core/reshape/merge.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1928,6 +1928,10 @@ def _validate_left_right_on(self, left_on, right_on):
19281928
)
19291929
if not self.right_index and right_on is None:
19301930
raise MergeError('Must pass "right_on" OR "right_index".')
1931+
# if self.right_index and right_on is not None:
1932+
# raise MergeError(
1933+
# 'Can only pass argument "right_on" OR "right_index" not both.'
1934+
# )
19311935
n = len(left_on)
19321936
if self.right_index:
19331937
if len(left_on) != self.right.index.nlevels:

pandas/tests/reshape/merge/test_merge.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3149,3 +3149,11 @@ def test_merge_pyarrow_datetime_duplicates():
31493149
)
31503150
expected = expected.convert_dtypes(dtype_backend="pyarrow")
31513151
tm.assert_frame_equal(result, expected)
3152+
3153+
3154+
def test_merge_right_on_and_right_index():
3155+
df1 = pd.DataFrame({"col": [1, 2, 3]})
3156+
df2 = pd.DataFrame({"col": [2, 3, 4]})
3157+
3158+
with pytest.raises(pd.errors.MergeError):
3159+
df1.merge(df2, left_on="col", right_on="col", right_index=True)

0 commit comments

Comments
 (0)