Skip to content

Conversation

phofl
Copy link
Member

@phofl phofl commented Apr 16, 2021

I think we should not allow these column collisions at all. Hence deprecating and raising in 2.0
Alternative here would be to add an errors keyword to the merge and join functions as @simonjayhawkins mentioned in the op.

@phofl phofl added Deprecate Functionality to remove in pandas Reshaping Concat, Merge/Join, Stack/Unstack, Explode labels Apr 16, 2021
Copy link
Member

@mroeschke mroeschke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed; deprecation of this behavior is easier to maintain as opposed to adding a new param

@mroeschke mroeschke added this to the 1.3 milestone Apr 20, 2021
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")
Copy link
Contributor

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

Copy link
Member Author

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

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"])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this the expected result?

Copy link
Member Author

Choose a reason for hiding this comment

The 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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kk, can you add a comment to this effect

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do.

@jreback jreback merged commit f656217 into pandas-dev:master Apr 20, 2021
@jreback
Copy link
Contributor

jreback commented Apr 20, 2021

thanks @phofl

yeshsurya pushed a commit to yeshsurya/pandas that referenced this pull request Apr 21, 2021
@phofl phofl deleted the 22818 branch April 21, 2021 20:39
yeshsurya pushed a commit to yeshsurya/pandas that referenced this pull request May 6, 2021
JulianWgs pushed a commit to JulianWgs/pandas that referenced this pull request Jul 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Deprecate Functionality to remove in pandas Reshaping Concat, Merge/Join, Stack/Unstack, Explode

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DataFrame.merge() doesn't check if new suffixed column names clash with existing column names

3 participants