Skip to content

Commit 4f1e97a

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent e39950f commit 4f1e97a

File tree

2 files changed

+13
-15
lines changed

2 files changed

+13
-15
lines changed

pandas/core/reshape/merge.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3074,8 +3074,7 @@ def renamer(x, suffix: str | None):
30743074

30753075
if dups:
30763076
raise MergeError(
3077-
f"Passing 'suffixes' which cause duplicate columns {dups} is "
3078-
f"not allowed.",
3077+
f"Passing 'suffixes' which cause duplicate columns {dups} is not allowed.",
30793078
)
30803079

30813080
return llabels, rlabels

pandas/tests/reshape/merge/test_merge.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3066,8 +3066,8 @@ def test_merge_for_suffix_collisions():
30663066
# GH#61402
30673067
# Case 1: suffixes=("_dup", "") test collision
30683068
df1 = pd.DataFrame({"col1": [1], "col2": [2]})
3069-
df2 = pd.DataFrame({"col1": [1], "col2": [2], "col2_dup": [3]})
3070-
with pytest.raises(MergeError, match="duplicate columns"):
3069+
df2 = pd.DataFrame({"col1": [1], "col2": [2], "col2_dup": [3]})
3070+
with pytest.raises(MergeError, match="duplicate columns"):
30713071
pd.merge(df1, df2, on="col1", suffixes=("_dup", ""))
30723072

30733073
# Case 2: suffixes=("", "_dup") test collision
@@ -3076,22 +3076,21 @@ def test_merge_for_suffix_collisions():
30763076
with pytest.raises(MergeError, match="duplicate columns"):
30773077
pd.merge(df1, df2, on="col1", suffixes=("", "_dup"))
30783078

3079-
# Case 3: suffixes=("_dup" != "__dup"), test similar
3079+
# Case 3: suffixes=("_dup" != "__dup"), test similar
30803080
# non-collision
30813081
df3 = pd.DataFrame({"col1": [1], "col2__dup": [4]})
30823082
df4 = pd.DataFrame({"col1": [1], "col2": [2]})
3083-
merged = df3.merge(df4, on='col1')
3083+
merged = df3.merge(df4, on="col1")
30843084
expected = pd.DataFrame([{"col1": 1, "col2__dup": 4, "col2": 2}])
3085-
pd.testing.assert_frame_equal(merged, expected)
3086-
3085+
pd.testing.assert_frame_equal(merged, expected)
30873086

3088-
# Case 4: suffixes=("", ""), auto-suffixes create
3087+
# Case 4: suffixes=("", ""), auto-suffixes create
30893088
# collision due to co2_x existing
30903089
df5 = pd.DataFrame({"col1": [1], "col2": [2]})
3091-
df6 = pd.DataFrame({"col1": [1], "col2": [2], "col2_x": [3]})
3090+
df6 = pd.DataFrame({"col1": [1], "col2": [2], "col2_x": [3]})
30923091
with pytest.raises(MergeError, match="duplicate columns"):
30933092
pd.merge(df5, df6, on="col1")
3094-
3093+
30953094
# Case 5: test special characters in suffixes
30963095
df7 = pd.DataFrame({"col1": [1], "metric": [10]})
30973096
df8 = pd.DataFrame({"col1": [1], "metric": [10], "metric#$%^": [20]})
@@ -3100,13 +3099,13 @@ def test_merge_for_suffix_collisions():
31003099

31013100
# Case 6: check if escape in column name causes conflict
31023101
df7 = pd.DataFrame({"col1": [1], "metric": [10]})
3103-
df8 = pd.DataFrame({"col1": [1], "metric": [10], "metric\#$%^": [20]})
3102+
df8 = pd.DataFrame({"col1": [1], "metric": [10], r"metric\#$%^": [20]})
31043103
with pytest.raises(MergeError, match="duplicate columns"):
3105-
pd.merge(df7, df8, on="col1", suffixes=("\#$%^", ""))
3104+
pd.merge(df7, df8, on="col1", suffixes=(r"\#$%^", ""))
31063105

31073106
# Case 7: suffix is a special character string
31083107
df9 = pd.DataFrame({"col1": [1], "col2": [2], "col2": [3]})
31093108
df10 = pd.DataFrame({"col1": [1], "col2": [2]})
3110-
merged = df9.merge(df10, on='col1')
3109+
merged = df9.merge(df10, on="col1")
31113110
expected = pd.DataFrame([{"col1": 1, "col2_x": 3, "col2_y": 2}])
3112-
pd.testing.assert_frame_equal(merged, expected)
3111+
pd.testing.assert_frame_equal(merged, expected)

0 commit comments

Comments
 (0)