Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -1206,6 +1206,7 @@ Reshaping
- Bug in :meth:`DataFrame.merge` where user-provided suffixes could result in duplicate column names if the resulting names matched existing columns. Now raises a :class:`MergeError` in such cases. (:issue:`61402`)
- Bug in :meth:`DataFrame.merge` with :class:`CategoricalDtype` columns incorrectly raising ``RecursionError`` (:issue:`56376`)
- Bug in :meth:`DataFrame.merge` with a ``float32`` index incorrectly casting the index to ``float64`` (:issue:`41626`)
- Bug in :meth:`DataFrame.join`` when joining with empty columns of differing dtypes (:issue:`62949``)

Sparse
^^^^^^
Expand Down
9 changes: 8 additions & 1 deletion pandas/core/reshape/merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -1131,7 +1131,14 @@ def _reindex_and_concat(

left.columns = llabels
right.columns = rlabels
result = concat([left, right], axis=1)
if len(left.columns) == 0 and len(right.columns) == 0:
result = left.copy()
elif len(left.columns) == 0:
result = right.copy()
elif len(right.columns) == 0:
result = left.copy()
else:
result = concat([left, right], axis=1)
return result

def get_result(self) -> DataFrame:
Expand Down
15 changes: 15 additions & 0 deletions pandas/tests/reshape/merge/test_merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,21 @@ def test_join_append_timedeltas2(self):
)
tm.assert_frame_equal(result, expected)

def test_join_empty_columns_warning(self):
pd.set_option("infer_string", True)
df = DataFrame({"a": "x", "b": ["y", "z"]}).set_index(["a", "b"])
df.columns = Index([], dtype="int64")
ser = DataFrame({"b": ["y", "z"], "value": [1, 2]}).set_index("b")["value"]

with tm.assert_produces_warning(None): # No warning expected
result = df.join(ser, on="b")

expected = DataFrame(
{"value": [1, 2]},
index=MultiIndex.from_tuples([("x", "y"), ("x", "z")], names=["a", "b"]),
)
tm.assert_frame_equal(result, expected)

@pytest.mark.parametrize("unit", ["D", "h", "m", "s", "ms", "us", "ns"])
def test_other_datetime_unit(self, unit):
# GH 13389
Expand Down
Loading