-
-
Notifications
You must be signed in to change notification settings - Fork 18k
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
Deprecate suffixes in merge producing duplicate columns #40991
Changes from 4 commits
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 |
---|---|---|
|
@@ -2409,3 +2409,23 @@ def test_merge_result_empty_index_and_on(): | |
|
||
result = merge(df2, df1, left_index=True, right_on=["b"]) | ||
tm.assert_frame_equal(result, expected) | ||
|
||
|
||
def test_merge_suffixes_produce_dup_columns_warns(): | ||
# GH#22818 | ||
left = DataFrame({"a": [1, 2, 3], "b": 1, "b_x": 2}) | ||
right = DataFrame({"a": [1, 2, 3], "b": 2}) | ||
with tm.assert_produces_warning(FutureWarning): | ||
merge(left, right, on="a") | ||
|
||
with tm.assert_produces_warning(FutureWarning): | ||
merge(right, left, on="a", suffixes=("_y", "_x")) | ||
|
||
|
||
def test_merge_duplicate_columns_with_suffix_no_warning(): | ||
# GH#22818 | ||
left = DataFrame([[1, 1, 1], [2, 2, 2]], columns=["a", "b", "b"]) | ||
right = DataFrame({"a": [1, 3], "b": 2}) | ||
result = merge(left, right, on="a") | ||
expected = DataFrame([[1, 1, 1, 2]], columns=["a", "b_x", "b_x", "b_y"]) | ||
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. is this the expected result? 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. Yes, I wanted to avoid raising when we already get duplicate columns as input, because the collisions in this case are not caused by the suffixes 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. kk, can you add a comment to this effect 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. Will do. |
||
tm.assert_frame_equal(result, expected) |
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 assert the results here
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.
Done and added another test