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 May 1, 2024
1 parent 59f6a33 commit ac65c13
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
1 change: 1 addition & 0 deletions doc/source/whatsnew/v3.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,7 @@ Other
- Bug in :func:`unique` on :class:`Index` not always returning :class:`Index` (:issue:`57043`)
- 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`)
- Bug in :meth:`DataFrame.eval` and :meth:`DataFrame.query` which did not allow to use ``tan`` function. (:issue:`55091`)
- Bug in :meth:`DataFrame.join` join with a list of a single element should behave as a join with a single element (:issue:`57676`)
- 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`)
- Bug in :meth:`DataFrame.transform` that was returning the wrong order unless the index was monotonically increasing. (:issue:`57069`)
- 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`)
Expand Down
3 changes: 3 additions & 0 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -10635,6 +10635,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
20 changes: 18 additions & 2 deletions pandas/tests/frame/methods/test_join.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,6 @@ def test_suffix_on_list_join():

# check proper errors are raised
msg = "Suffixes not supported when joining multiple DataFrames"
with pytest.raises(ValueError, match=msg):
first.join([second], lsuffix="y")
with pytest.raises(ValueError, match=msg):
first.join([second, third], rsuffix="x")
with pytest.raises(ValueError, match=msg):
Expand Down Expand Up @@ -562,3 +560,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)

tm.assert_frame_equal(result, expected)

0 comments on commit ac65c13

Please sign in to comment.