Skip to content

Commit 322153a

Browse files
committed
BUG: Join with a list of a single element behaves as a join with a single element (pandas-dev#57676)
1 parent 0f7ded2 commit 322153a

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

pandas/core/frame.py

+3
Original file line numberDiff line numberDiff line change
@@ -10560,6 +10560,9 @@ def join(
1056010560
from pandas.core.reshape.concat import concat
1056110561
from pandas.core.reshape.merge import merge
1056210562

10563+
if isinstance(other, list) and len(other) == 1:
10564+
other = other[0]
10565+
1056310566
if isinstance(other, Series):
1056410567
if other.name is None:
1056510568
raise ValueError("Other Series must have a name")

pandas/tests/frame/methods/test_join.py

+18
Original file line numberDiff line numberDiff line change
@@ -562,3 +562,21 @@ def test_frame_join_tzaware(self):
562562

563563
tm.assert_index_equal(result.index, expected)
564564
assert result.index.tz.zone == "US/Central"
565+
566+
def test_join_list_with_single_element(self):
567+
test1 = DataFrame(
568+
{"cat": pd.Categorical(["a", "v", "d"])},
569+
index=Index(["a", "b", "c"], name="y"),
570+
)
571+
test2 = DataFrame(
572+
{"foo": np.arange(6)},
573+
index=MultiIndex.from_tuples(
574+
[(0, "a"), (0, "b"), (0, "c"), (1, "a"), (1, "b"), (1, "c")],
575+
names=("x", "y"),
576+
),
577+
)
578+
579+
result = test2.join([test1])
580+
expected = test2.join(test1)
581+
582+
assert result.equals(expected)

0 commit comments

Comments
 (0)