Skip to content

Commit 704f2da

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 b111ac6 commit 704f2da

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
@@ -458,6 +458,7 @@ Other
458458
- Bug in :class:`DataFrame` when passing a ``dict`` with a NA scalar and ``columns`` that would always return ``np.nan`` (:issue:`57205`)
459459
- Bug in :func:`unique` on :class:`Index` not always returning :class:`Index` (:issue:`57043`)
460460
- 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`)
461+
- Bug in :meth:`DataFrame.join` join with a list of a single element should behave as a join with a single element (:issue:`57676`)
461462
- 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`)
462463
- Bug in :meth:`DataFrame.transform` that was returning the wrong order unless the index was monotonically increasing. (:issue:`57069`)
463464
- 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
@@ -10609,6 +10609,9 @@ def join(
1060910609
from pandas.core.reshape.concat import concat
1061010610
from pandas.core.reshape.merge import merge
1061110611

10612+
if isinstance(other, list) and len(other) == 1:
10613+
other = other[0]
10614+
1061210615
if isinstance(other, Series):
1061310616
if other.name is None:
1061410617
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)