Skip to content

Commit 0cb8843

Browse files
committed
Trying original patch
1 parent 0a894a9 commit 0cb8843

File tree

2 files changed

+22
-18
lines changed

2 files changed

+22
-18
lines changed

pandas/core/reshape/merge.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,15 +1089,19 @@ def _validate_specification(self):
10891089
raise ValueError('len(left_on) must equal the number '
10901090
'of levels in the index of "right"')
10911091
self.right_on = [None] * n
1092-
self.right_on = self.right_on or [None] * (n + 1)
1092+
if self.right_on is None:
1093+
raise ValueError('both "left_on" and "right_on" '
1094+
'should be passed')
10931095
elif self.right_on is not None:
10941096
n = len(self.right_on)
10951097
if self.left_index:
10961098
if len(self.right_on) != self.left.index.nlevels:
10971099
raise ValueError('len(right_on) must equal the number '
10981100
'of levels in the index of "left"')
10991101
self.left_on = [None] * n
1100-
self.left_on = self.left_on or [None] * (n + 1)
1102+
if self.left_on is None:
1103+
raise ValueError('both "left_on" and "right_on" '
1104+
'should be passed')
11011105
if len(self.right_on) != len(self.left_on):
11021106
raise ValueError("len(right_on) must equal len(left_on)")
11031107

pandas/tests/reshape/merge/test_merge.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1026,6 +1026,22 @@ def test_validation(self):
10261026
result = merge(left, right, on=['a', 'b'], validate='1:1')
10271027
assert_frame_equal(result, expected_multi)
10281028

1029+
@pytest.mark.parametrize('merge_type', ['left_on', 'right_on'])
1030+
def test_missing_on_raises(merge_type):
1031+
# GH26824
1032+
left = DataFrame({
1033+
'A': [1, 2, 3, 4, 5, 6],
1034+
'B': ['P', 'Q', 'R', 'S', 'T', 'U']
1035+
})
1036+
right = DataFrame({
1037+
'A': [1, 2, 4, 5, 7, 8],
1038+
'C': ['L', 'M', 'N', 'O', 'P', 'Q']
1039+
})
1040+
msg = 'should be passed'
1041+
kwargs = {merge_type: 'A'}
1042+
with pytest.raises(ValueError, match=msg):
1043+
pd.merge(left, right, how='left', **kwargs)
1044+
10291045
def test_merge_two_empty_df_no_division_error(self):
10301046
# GH17776, PR #17846
10311047
a = pd.DataFrame({'a': [], 'b': [], 'c': []})
@@ -1764,19 +1780,3 @@ def test_merge_equal_cat_dtypes2():
17641780
# Categorical is unordered, so don't check ordering.
17651781
tm.assert_frame_equal(result, expected, check_categorical=False)
17661782

1767-
1768-
@pytest.mark.parametrize('merge_type', ['left_on', 'right_on'])
1769-
def test_missing_on_raises(merge_type):
1770-
# GH26824
1771-
df1 = DataFrame({
1772-
'A': [1, 2, 3, 4, 5, 6],
1773-
'B': ['P', 'Q', 'R', 'S', 'T', 'U']
1774-
})
1775-
df2 = DataFrame({
1776-
'A': [1, 2, 4, 5, 7, 8],
1777-
'C': ['L', 'M', 'N', 'O', 'P', 'Q']
1778-
})
1779-
msg = 'must equal'
1780-
kwargs = {merge_type: 'A'}
1781-
with pytest.raises(ValueError, match=msg):
1782-
pd.merge(df1, df2, how='left', **kwargs)

0 commit comments

Comments
 (0)