Skip to content

Commit

Permalink
Backport PR #49284 on branch 1.5.x (REGR: MultiIndex.join does not wo…
Browse files Browse the repository at this point in the history
…rk for ea dtypes) (#49627)

REGR: MultiIndex.join does not work for ea dtypes (#49284)

* REGR: MultiIndex.join does not work for ea dtypes

* Update base.py

(cherry picked from commit f82b1c6)
  • Loading branch information
phofl committed Nov 11, 2022
1 parent c8018b5 commit 08d02e2
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 2 deletions.
1 change: 1 addition & 0 deletions doc/source/whatsnew/v1.5.2.rst
Expand Up @@ -13,6 +13,7 @@ including other versions of pandas.

Fixed regressions
~~~~~~~~~~~~~~~~~
- Fixed regression in :meth:`MultiIndex.join` for extension array dtypes (:issue:`49277`)
- Fixed regression in :meth:`Series.replace` raising ``RecursionError`` with numeric dtype and when specifying ``value=None`` (:issue:`45725`)
- Fixed regression in :meth:`DataFrame.plot` preventing :class:`~matplotlib.colors.Colormap` instance
from being passed using the ``colormap`` argument if Matplotlib 3.6+ is used (:issue:`49374`)
Expand Down
6 changes: 4 additions & 2 deletions pandas/core/indexes/base.py
Expand Up @@ -4701,8 +4701,10 @@ def join(
return self._join_non_unique(other, how=how)
elif not self.is_unique or not other.is_unique:
if self.is_monotonic_increasing and other.is_monotonic_increasing:
if self._can_use_libjoin:
if not is_interval_dtype(self.dtype):
# otherwise we will fall through to _join_via_get_indexer
# GH#39133
# go through object dtype for ea till engine is supported properly
return self._join_monotonic(other, how=how)
else:
return self._join_non_unique(other, how=how)
Expand Down Expand Up @@ -5079,7 +5081,7 @@ def _wrap_joined_index(self: _IndexT, joined: ArrayLike, other: _IndexT) -> _Ind
return self._constructor(joined, name=name) # type: ignore[return-value]
else:
name = get_op_result_name(self, other)
return self._constructor._with_infer(joined, name=name)
return self._constructor._with_infer(joined, name=name, dtype=self.dtype)

@cache_readonly
def _can_use_libjoin(self) -> bool:
Expand Down
48 changes: 48 additions & 0 deletions pandas/tests/indexes/multi/test_join.py
Expand Up @@ -5,6 +5,8 @@
Index,
Interval,
MultiIndex,
Series,
StringDtype,
)
import pandas._testing as tm

Expand Down Expand Up @@ -158,3 +160,49 @@ def test_join_overlapping_interval_level():
result = idx_1.join(idx_2, how="outer")

tm.assert_index_equal(result, expected)


def test_join_midx_ea():
# GH#49277
midx = MultiIndex.from_arrays(
[Series([1, 1, 3], dtype="Int64"), Series([1, 2, 3], dtype="Int64")],
names=["a", "b"],
)
midx2 = MultiIndex.from_arrays(
[Series([1], dtype="Int64"), Series([3], dtype="Int64")], names=["a", "c"]
)
result = midx.join(midx2, how="inner")
expected = MultiIndex.from_arrays(
[
Series([1, 1], dtype="Int64"),
Series([1, 2], dtype="Int64"),
Series([3, 3], dtype="Int64"),
],
names=["a", "b", "c"],
)
tm.assert_index_equal(result, expected)


def test_join_midx_string():
# GH#49277
midx = MultiIndex.from_arrays(
[
Series(["a", "a", "c"], dtype=StringDtype()),
Series(["a", "b", "c"], dtype=StringDtype()),
],
names=["a", "b"],
)
midx2 = MultiIndex.from_arrays(
[Series(["a"], dtype=StringDtype()), Series(["c"], dtype=StringDtype())],
names=["a", "c"],
)
result = midx.join(midx2, how="inner")
expected = MultiIndex.from_arrays(
[
Series(["a", "a"], dtype=StringDtype()),
Series(["a", "b"], dtype=StringDtype()),
Series(["c", "c"], dtype=StringDtype()),
],
names=["a", "b", "c"],
)
tm.assert_index_equal(result, expected)

0 comments on commit 08d02e2

Please sign in to comment.