-
-
Notifications
You must be signed in to change notification settings - Fork 18.2k
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 3 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 |
---|---|---|
|
@@ -1763,3 +1763,23 @@ 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_merge_correct_exception(merge_type): | ||
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. Let's just call this 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. Sure |
||
# 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' | ||
if merge_type == 'left_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. Rather than the if condition since you are parmatrizing this argument (which is nice btw) you can send it through as kwargs. So: 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 commentThe reason will be displayed to describe this comment to others. Learn more. Makes sense, will do |
||
with pytest.raises(ValueError, match=msg): | ||
pd.merge(df1, df2, how='left', left_on='A') | ||
if merge_type == 'right_on': | ||
with pytest.raises(ValueError, match=msg): | ||
pd.merge(df1, df2, how='left', right_on='A') |
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 we instead try to set
self.left_on = self.left_on or [None] * len( self.right_on)
and same for right_on
before these if clauses; that way don’t need to add additional checks
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.
Sure