Skip to content

Commit ac65c13

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 59f6a33 commit ac65c13

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
@@ -477,6 +477,7 @@ Other
477477
- Bug in :func:`unique` on :class:`Index` not always returning :class:`Index` (:issue:`57043`)
478478
- Bug in :meth:`DataFrame.eval` and :meth:`DataFrame.query` which caused an exception when using NumPy attributes via ``@`` notation, e.g., ``df.eval("@np.floor(a)")``. (:issue:`58041`)
479479
- Bug in :meth:`DataFrame.eval` and :meth:`DataFrame.query` which did not allow to use ``tan`` function. (:issue:`55091`)
480+
- Bug in :meth:`DataFrame.join` join with a list of a single element should behave as a join with a single element (:issue:`57676`)
480481
- Bug in :meth:`DataFrame.sort_index` when passing ``axis="columns"`` and ``ignore_index=True`` and ``ascending=False`` not returning a :class:`RangeIndex` columns (:issue:`57293`)
481482
- Bug in :meth:`DataFrame.transform` that was returning the wrong order unless the index was monotonically increasing. (:issue:`57069`)
482483
- Bug in :meth:`DataFrame.where` where using a non-bool type array in the function would return a ``ValueError`` instead of a ``TypeError`` (:issue:`56330`)

pandas/core/frame.py

+3
Original file line numberDiff line numberDiff line change
@@ -10635,6 +10635,9 @@ def join(
1063510635
from pandas.core.reshape.concat import concat
1063610636
from pandas.core.reshape.merge import merge
1063710637

10638+
if isinstance(other, list) and len(other) == 1:
10639+
other = other[0]
10640+
1063810641
if isinstance(other, Series):
1063910642
if other.name is None:
1064010643
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)