Skip to content

Commit 466b175

Browse files
committed
Change suffixes field to accept only tuple of len 2
1 parent c5cde4b commit 466b175

File tree

3 files changed

+8
-10
lines changed

3 files changed

+8
-10
lines changed

pandas/core/frame.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@
226226
sort : bool, default False
227227
Sort the join keys lexicographically in the result DataFrame. If False,
228228
the order of the join keys depends on the join type (how keyword).
229-
suffixes : list/tuple of (str, str), default ('_x', '_y')
229+
suffixes : tuple of (str, str), default ('_x', '_y')
230230
Suffix to apply to overlapping column names in the left and right
231231
side, respectively. To raise an exception on overlapping columns use
232232
(False, False).

pandas/core/reshape/merge.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2065,16 +2065,16 @@ def _validate_operand(obj: FrameOrSeries) -> "DataFrame":
20652065

20662066
def _items_overlap_with_suffix(left: Index, right: Index, suffixes):
20672067
"""
2068-
Suffixes type validatoin.
2068+
Suffixes type validation.
20692069
20702070
If two indices overlap, add suffixes to overlapping entries.
20712071
20722072
If corresponding suffix is empty, the entry is simply converted to string.
20732073
20742074
"""
2075-
if not isinstance(suffixes, (tuple, list)):
2075+
if not isinstance(suffixes, tuple):
20762076
raise TypeError(
2077-
f"suffixes should be of type list/tuple. But got {type(suffixes)}"
2077+
f"suffixes should be tuple of (str, str). But got {type(suffixes)}"
20782078
)
20792079

20802080
to_rename = left.intersection(right)

pandas/tests/reshape/merge/test_merge.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2004,8 +2004,8 @@ def test_merge_series(on, left_on, right_on, left_index, right_index, nm):
20042004
("b", "b", dict(suffixes=(None, "_y")), ["b", "b_y"]),
20052005
("a", "a", dict(suffixes=("_x", None)), ["a_x", "a"]),
20062006
("a", "b", dict(suffixes=("_x", None)), ["a", "b"]),
2007-
("a", "a", dict(suffixes=[None, "_x"]), ["a", "a_x"]),
2008-
(0, 0, dict(suffixes=["_a", None]), ["0_a", 0]),
2007+
("a", "a", dict(suffixes=(None, "_x")), ["a", "a_x"]),
2008+
(0, 0, dict(suffixes=("_a", None)), ["0_a", 0]),
20092009
("a", "a", dict(), ["a_x", "a_y"]),
20102010
(0, 0, dict(), ["0_x", "0_y"]),
20112011
],
@@ -2057,10 +2057,8 @@ def test_merge_duplicate_suffix(how, expected):
20572057
@pytest.mark.parametrize(
20582058
"col1, col2, suffixes",
20592059
[
2060-
("a", "a", [None, None]),
20612060
("a", "a", (None, None)),
20622061
("a", "a", ("", None)),
2063-
(0, 0, [None, None]),
20642062
(0, 0, (None, "")),
20652063
],
20662064
)
@@ -2082,7 +2080,7 @@ def test_merge_suffix_type_error(col1, col2, suffixes):
20822080
a = pd.DataFrame({col1: [1, 2, 3]})
20832081
b = pd.DataFrame({col2: [3, 4, 5]})
20842082

2085-
msg = f"suffixes should be of type list/tuple. But got {type(suffixes)}"
2083+
msg = f"suffixes should be tuple of \\(str, str\\). But got {type(suffixes)}"
20862084
with pytest.raises(TypeError, match=msg):
20872085
pd.merge(a, b, left_index=True, right_index=True, suffixes=suffixes)
20882086

@@ -2091,7 +2089,7 @@ def test_merge_suffix_type_error(col1, col2, suffixes):
20912089
"col1, col2, suffixes, msg",
20922090
[
20932091
("a", "a", ("a", "b", "c"), r"too many values to unpack \(expected 2\)"),
2094-
("a", "a", ["a"], r"not enough values to unpack \(expected 2, got 1\)"),
2092+
("a", "a", tuple("a"), r"not enough values to unpack \(expected 2, got 1\)"),
20952093
],
20962094
)
20972095
def test_merge_suffix_length_error(col1, col2, suffixes, msg):

0 commit comments

Comments
 (0)