Skip to content

Commit 7a44e42

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 ec3eddd commit 7a44e42

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

doc/source/whatsnew/v3.0.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,7 @@ Bug fixes
334334
- Fixed bug in :meth:`.DataFrameGroupBy.median` where nat values gave an incorrect result. (:issue:`57926`)
335335
- Fixed bug in :meth:`DataFrame.cumsum` which was raising ``IndexError`` if dtype is ``timedelta64[ns]`` (:issue:`57956`)
336336
- Fixed bug in :meth:`DataFrame.join` inconsistently setting result index name (:issue:`55815`)
337+
- Fixed bug in :meth:`DataFrame.join` join with a list of a single element should behave as a join with a single element (:issue:`57676`)
337338
- Fixed bug in :meth:`DataFrame.to_string` that raised ``StopIteration`` with nested DataFrames. (:issue:`16098`)
338339
- Fixed bug in :meth:`DataFrame.transform` that was returning the wrong order unless the index was monotonically increasing. (:issue:`57069`)
339340
- Fixed bug in :meth:`DataFrame.update` bool dtype being converted to object (:issue:`55509`)

pandas/core/frame.py

+3
Original file line numberDiff line numberDiff line change
@@ -10587,6 +10587,9 @@ def join(
1058710587
from pandas.core.reshape.concat import concat
1058810588
from pandas.core.reshape.merge import merge
1058910589

10590+
if isinstance(other, list) and len(other) == 1:
10591+
other = other[0]
10592+
1059010593
if isinstance(other, Series):
1059110594
if other.name is None:
1059210595
raise ValueError("Other Series must have a name")

pandas/tests/frame/methods/test_join.py

+18-2
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,6 @@ def test_suffix_on_list_join():
107107

108108
# check proper errors are raised
109109
msg = "Suffixes not supported when joining multiple DataFrames"
110-
with pytest.raises(ValueError, match=msg):
111-
first.join([second], lsuffix="y")
112110
with pytest.raises(ValueError, match=msg):
113111
first.join([second, third], rsuffix="x")
114112
with pytest.raises(ValueError, match=msg):
@@ -562,3 +560,21 @@ def test_frame_join_tzaware(self):
562560

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

0 commit comments

Comments
 (0)