Skip to content

Commit

Permalink
BUG: Join with a list of a single element behaves as a join with a si…
Browse files Browse the repository at this point in the history
…ngle element (pandas-dev#57676)
  • Loading branch information
Dacops committed Mar 20, 2024
1 parent 0f7ded2 commit 322153a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -10560,6 +10560,9 @@ def join(
from pandas.core.reshape.concat import concat
from pandas.core.reshape.merge import merge

if isinstance(other, list) and len(other) == 1:
other = other[0]

if isinstance(other, Series):
if other.name is None:
raise ValueError("Other Series must have a name")
Expand Down
18 changes: 18 additions & 0 deletions pandas/tests/frame/methods/test_join.py
Original file line number Diff line number Diff line change
Expand Up @@ -562,3 +562,21 @@ def test_frame_join_tzaware(self):

tm.assert_index_equal(result.index, expected)
assert result.index.tz.zone == "US/Central"

def test_join_list_with_single_element(self):
test1 = DataFrame(
{"cat": pd.Categorical(["a", "v", "d"])},
index=Index(["a", "b", "c"], name="y"),
)
test2 = DataFrame(
{"foo": np.arange(6)},
index=MultiIndex.from_tuples(
[(0, "a"), (0, "b"), (0, "c"), (1, "a"), (1, "b"), (1, "c")],
names=("x", "y"),
),
)

result = test2.join([test1])
expected = test2.join(test1)

assert result.equals(expected)

0 comments on commit 322153a

Please sign in to comment.