-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG:Sanity check on merge parameters for correct exception #26824 #26855
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 8 commits
c3064e6
c862ec0
0df85f0
dea59fa
53aee36
6396947
11b1894
7b4aa22
bfb7984
1e2b276
0f88c32
a9905bd
a939d8e
83f8cda
962882d
139d696
4e6bd89
a0680e0
0a894a9
0cb8843
4e45c75
500e374
773dec2
7770b1d
efb0761
6b7f5a2
b7c482e
e4e486c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -1089,13 +1089,15 @@ def _validate_specification(self): | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
raise ValueError('len(left_on) must equal the number ' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
'of levels in the index of "right"') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
self.right_on = [None] * n | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
self.right_on = self.right_on or [None] * (n + 1) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why do you need to add 1 this seems odd There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. so, the thinking here was to not add additional check and force the cases where either of left_on or right_on is absent to the if clause at 1099. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. right but i think this is actually changing things slightly maybe let’s go back to your original patch There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
additional message checks maybe should be added to the following tests as a precursor. xref #23922
also the following tests perhaps should be moved to pandas/tests/reshape/merge/test_merge.py ( could potentially add additional parametrisation to these tests rather than creating new) pandas/pandas/tests/reshape/merge/test_join.py Lines 202 to 247 in a738223
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
elif self.right_on is not None: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
n = len(self.right_on) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if self.left_index: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if len(self.right_on) != self.left.index.nlevels: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
raise ValueError('len(right_on) must equal the number ' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
'of levels in the index of "left"') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
self.left_on = [None] * n | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
self.left_on = self.left_on or [None] * (n + 1) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if len(self.right_on) != len(self.left_on): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
raise ValueError("len(right_on) must equal len(left_on)") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1763,3 +1763,20 @@ def test_merge_equal_cat_dtypes2(): | |
|
||
# Categorical is unordered, so don't check ordering. | ||
tm.assert_frame_equal(result, expected, check_categorical=False) | ||
|
||
|
||
@pytest.mark.parametrize('merge_type', ['left_on', 'right_on']) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. move this near the test_validation test |
||
def test_missing_on_raises(merge_type): | ||
# GH26824 | ||
df1 = DataFrame({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. call these left & right |
||
'A': [1, 2, 3, 4, 5, 6], | ||
'B': ['P', 'Q', 'R', 'S', 'T', 'U'] | ||
}) | ||
df2 = DataFrame({ | ||
'A': [1, 2, 4, 5, 7, 8], | ||
'C': ['L', 'M', 'N', 'O', 'P', 'Q'] | ||
}) | ||
msg = 'must equal' | ||
kwargs = {merge_type: 'A'} | ||
with pytest.raises(ValueError, match=msg): | ||
pd.merge(df1, df2, how='left', **kwargs) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you elaborate slightly; this only matters if
on
itself is not provided. Do we have a check ifon
is provide and either ofleft_on
orright_on
is notNone
?