Skip to content

Commit 91e015c

Browse files
correct
1 parent cf4cc1d commit 91e015c

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

pandas/core/reshape/merge.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,13 +225,29 @@ def merge(
225225
sort : bool, default False
226226
Sort the join keys lexicographically in the result DataFrame. If False,
227227
the order of the join keys depends on the join type (how keyword).
228+
diff_option : Literal str
229+
The allowed values are "suffix"、"prefix"、"both",default "suffix".
230+
If the value is "suffix", the duplicated columns will be differentiated
231+
using the suffixes provided by parameter "suffixes".
232+
If the value is "prefix", the duplicated columns will be differentiated
233+
using the prefixes provided by parameter "prefixes".
234+
If the value is "both", the duplicated columns will be differentiated
235+
using both the suffixes provided by parameter "suffixes" and
236+
the prefixes provided by parameter "prefixes".
228237
suffixes : list-like, default is ("_x", "_y")
229238
A length-2 sequence where each element is optionally a string
230239
indicating the suffix to add to overlapping column names in
231240
`left` and `right` respectively. Pass a value of `None` instead
232241
of a string to indicate that the column name from `left` or
233242
`right` should be left as-is, with no suffix. At least one of the
234243
values must not be None.
244+
prefixes : list-like, default is ("a_", "b_")
245+
A length-2 sequence where each element is optionally a string
246+
indicating the prefix to add to overlapping column names in
247+
`left` and `right` respectively. Pass a value of `None` instead
248+
of a string to indicate that the column name from `left` or
249+
`right` should be left as-is, with no prefix. At least one of the
250+
values must not be None.
235251
copy : bool, default False
236252
If False, avoid copy if possible.
237253

pandas/tests/reshape/merge/test_join.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -783,7 +783,7 @@ def test_join_dups(self):
783783
# GH 40991: As of 2.0 causes duplicate columns
784784
with pytest.raises(
785785
pd.errors.MergeError,
786-
match="Passing 'suffixes' which cause duplicate columns",
786+
match="Passing 'suffixes' or/and 'prefixes' which cause duplicate columns",
787787
):
788788
dta.merge(w, left_index=True, right_index=True)
789789

pandas/tests/reshape/merge/test_multi.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,9 @@ def test_join_multi_levels_invalid(self, portfolio, household):
652652
portfolio2 = portfolio.copy()
653653
portfolio2.index.set_names(["household_id", "foo"])
654654

655-
with pytest.raises(ValueError, match="columns overlap but no suffix specified"):
655+
with pytest.raises(
656+
ValueError, match="columns overlap but no suffix or prefix specified"
657+
):
656658
portfolio2.join(portfolio, how="inner")
657659

658660
def test_join_multi_levels2(self):

0 commit comments

Comments
 (0)