Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 2 additions & 0 deletions doc/source/whatsnew/v3.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -865,7 +865,9 @@ Reshaping
- Bug in :meth:`DataFrame.unstack` producing incorrect results when manipulating empty :class:`DataFrame` with an :class:`ExtentionDtype` (:issue:`59123`)
- Bug in :meth:`concat` where concatenating DataFrame and Series with ``ignore_index = True`` drops the series name (:issue:`60723`, :issue:`56257`)
- Bug in :func:`melt` where calling with duplicate column names in ``id_vars`` raised a misleading ``AttributeError`` (:issue:`61475`)
- Bug in :meth:`DataFrame.join` incorrectly downcasting object-dtype indexes (:issue:`61771`)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we would want to backport this fix to 2.3.1?

- 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`)
-

Sparse
^^^^^^
Expand Down
6 changes: 3 additions & 3 deletions pandas/core/reshape/merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -1328,13 +1328,13 @@ def _maybe_add_join_keys(
# if we have an all missing left_indexer
# make sure to just use the right values or vice-versa
if left_indexer is not None and (left_indexer == -1).all():
key_col = Index(rvals)
key_col = Index(rvals, dtype=rvals.dtype, copy=False)
result_dtype = rvals.dtype
elif right_indexer is not None and (right_indexer == -1).all():
key_col = Index(lvals)
key_col = Index(lvals, dtype=lvals.dtype, copy=False)
result_dtype = lvals.dtype
else:
key_col = Index(lvals)
key_col = Index(lvals, dtype=lvals.dtype, copy=False)
if left_indexer is not None:
mask_left = left_indexer == -1
key_col = key_col.where(~mask_left, rvals)
Expand Down
16 changes: 4 additions & 12 deletions pandas/tests/copy_view/test_functions.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import numpy as np
import pytest

from pandas._config import using_string_dtype

from pandas.compat import HAS_PYARROW

from pandas import (
DataFrame,
Index,
Expand Down Expand Up @@ -247,13 +243,9 @@ def test_merge_copy_keyword():
assert np.shares_memory(get_array(df2, "b"), get_array(result, "b"))


@pytest.mark.xfail(
using_string_dtype() and HAS_PYARROW,
reason="TODO(infer_string); result.index infers str dtype while both "
"df1 and df2 index are object.",
)
def test_join_on_key():
df_index = Index(["a", "b", "c"], name="key", dtype=object)
@pytest.mark.parametrize("dtype", [object, "str"])
def test_join_on_key(dtype):
df_index = Index(["a", "b", "c"], name="key", dtype=dtype)

df1 = DataFrame({"a": [1, 2, 3]}, index=df_index.copy(deep=True))
df2 = DataFrame({"b": [4, 5, 6]}, index=df_index.copy(deep=True))
Expand All @@ -265,7 +257,7 @@ def test_join_on_key():

assert np.shares_memory(get_array(result, "a"), get_array(df1, "a"))
assert np.shares_memory(get_array(result, "b"), get_array(df2, "b"))
assert np.shares_memory(get_array(result.index), get_array(df1.index))
assert tm.shares_memory(get_array(result.index), get_array(df1.index))
assert not np.shares_memory(get_array(result.index), get_array(df2.index))

result.iloc[0, 0] = 0
Expand Down
Loading