-
-
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: DataFrame.merge(suffixes=) does not respect None #24819
Merged
Merged
Changes from 3 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
82c52a4
one in all
charlesdong1991 dd605e0
change whatsnew to 0.25
charlesdong1991 af7f9ad
add back other comment
charlesdong1991 4d5e1a9
double check test
charlesdong1991 3f65bf1
changes based on discussion
charlesdong1991 ce7e4b8
changes based on discussion with joris
charlesdong1991 90ca9cd
slight change
charlesdong1991 e995a04
slight changes
charlesdong1991 9c3dfbd
changes based on jeff review
charlesdong1991 441e9a5
fix test error
charlesdong1991 71729b2
ci fail, try again
charlesdong1991 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1967,20 +1967,31 @@ def items_overlap_with_suffix(left, lsuffix, right, rsuffix): | |
if len(to_rename) == 0: | ||
return left, right | ||
else: | ||
if not lsuffix and not rsuffix: | ||
raise ValueError('columns overlap but no suffix specified: ' | ||
'{rename}'.format(rename=to_rename)) | ||
# if column name is string, raise error if suffix is a combination of | ||
# empty string and None, or two Nones | ||
if isinstance(to_rename[0], str): | ||
if not lsuffix and not rsuffix: | ||
raise ValueError('columns overlap but no suffix specified: ' | ||
'{rename}'.format(rename=to_rename)) | ||
else: | ||
# if not, only suffix with (None, None) will raise error | ||
if lsuffix is None and rsuffix is None: | ||
raise ValueError('columns overlap but no suffix specified: ' | ||
'{rename}'.format(rename=to_rename)) | ||
|
||
def lrenamer(x): | ||
if x in to_rename: | ||
return '{x}{lsuffix}'.format(x=x, lsuffix=lsuffix) | ||
return x | ||
def renamer(x, suffix): | ||
"""Rename the left and right indices. | ||
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. can you make a proper doc-string (Parameters / Returns) |
||
|
||
def rrenamer(x): | ||
if x in to_rename: | ||
return '{x}{rsuffix}'.format(x=x, rsuffix=rsuffix) | ||
If there is overlap, and suffix is not None, add | ||
suffix, otherwise, leave it as-is. | ||
""" | ||
if x in to_rename and suffix is not None: | ||
return '{x}{suffix}'.format(x=x, suffix=suffix) | ||
return x | ||
|
||
lrenamer = partial(renamer, suffix=lsuffix) | ||
rrenamer = partial(renamer, suffix=rsuffix) | ||
|
||
return (_transform_index(left, lrenamer), | ||
_transform_index(right, rrenamer)) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -159,9 +159,13 @@ def merge_ordered(left, right, on=None, | |
left DataFrame | ||
fill_method : {'ffill', None}, default None | ||
Interpolation method for data | ||
suffixes : 2-length sequence (tuple, list, ...) | ||
Suffix to apply to overlapping column names in the left and right | ||
side, respectively | ||
suffixes : Sequence, default is ("_x", "_y") | ||
A length-2 sequence where each element is optionally a string | ||
indicating the suffix to add to overlapping column names in | ||
`left` and `right` respectively. Pass a value of `None` instead | ||
of a string to indicate that the column name from `left` or | ||
`right` should be left as-is, with no suffix. At least one of the | ||
values must not be None. | ||
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. can you add a versionchanged 0.25.0 here |
||
how : {'left', 'right', 'outer', 'inner'}, default 'outer' | ||
* left: use only keys from left frame (SQL: left outer join) | ||
* right: use only keys from right frame (SQL: right outer join) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 be a bit more clear on what the previous sympton was, instead of 'doesn't work correctly'
double backticks on None
no space after the colon
(:issue:`24782`)