-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
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
BUG:Sanity check on merge parameters for correct exception #26824 #26855
Changes from 6 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] * len(self.left_on) | ||
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] * len(self.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. you don’t need the lines above (not both cases) 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. not sure I get it. The previous line needs to go? 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. try it - i think it’s unnecessary 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. u can also combine the condition in 1095 and 1096 i think as well 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.
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. ok see if u can simplify things with passing tests |
||
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 = 'both left_on and right_on should be passed' | ||
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
?