Skip to content

Commit 6015196

Browse files
committed
REGR: MultiIndex.join does not work for ea dtypes
1 parent 86c3d42 commit 6015196

File tree

3 files changed

+52
-3
lines changed

3 files changed

+52
-3
lines changed

doc/source/whatsnew/v1.5.2.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ including other versions of pandas.
1313

1414
Fixed regressions
1515
~~~~~~~~~~~~~~~~~
16-
-
16+
- Fixed regression in :meth:`MultiIndex.join` for extension array dtypes (:issue:`49277`)
1717
-
1818

1919
.. ---------------------------------------------------------------------------

pandas/core/indexes/base.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -4675,8 +4675,9 @@ def join(
46754675
return self._join_non_unique(other, how=how)
46764676
elif not self.is_unique or not other.is_unique:
46774677
if self.is_monotonic_increasing and other.is_monotonic_increasing:
4678-
if self._can_use_libjoin:
4678+
if not is_interval_dtype(self.dtype):
46794679
# otherwise we will fall through to _join_via_get_indexer
4680+
# go through object dtype for ea till engine is supported properly
46804681
return self._join_monotonic(other, how=how)
46814682
else:
46824683
return self._join_non_unique(other, how=how)
@@ -5051,7 +5052,7 @@ def _wrap_joined_index(self: _IndexT, joined: ArrayLike, other: _IndexT) -> _Ind
50515052
return self._constructor(joined, name=name) # type: ignore[return-value]
50525053
else:
50535054
name = get_op_result_name(self, other)
5054-
return self._constructor._with_infer(joined, name=name)
5055+
return self._constructor._with_infer(joined, name=name, dtype=self.dtype)
50555056

50565057
@cache_readonly
50575058
def _can_use_libjoin(self) -> bool:

pandas/tests/indexes/multi/test_join.py

+48
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
Index,
66
Interval,
77
MultiIndex,
8+
Series,
9+
StringDtype,
810
)
911
import pandas._testing as tm
1012

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

160162
tm.assert_index_equal(result, expected)
163+
164+
165+
def test_join_midx_ea():
166+
# GH#49277
167+
midx = MultiIndex.from_arrays(
168+
[Series([1, 1, 3], dtype="Int64"), Series([1, 2, 3], dtype="Int64")],
169+
names=["a", "b"],
170+
)
171+
midx2 = MultiIndex.from_arrays(
172+
[Series([1], dtype="Int64"), Series([3], dtype="Int64")], names=["a", "c"]
173+
)
174+
result = midx.join(midx2, how="inner")
175+
expected = MultiIndex.from_arrays(
176+
[
177+
Series([1, 1], dtype="Int64"),
178+
Series([1, 2], dtype="Int64"),
179+
Series([3, 3], dtype="Int64"),
180+
],
181+
names=["a", "b", "c"],
182+
)
183+
tm.assert_index_equal(result, expected)
184+
185+
186+
def test_join_midx_string():
187+
# GH#49277
188+
midx = MultiIndex.from_arrays(
189+
[
190+
Series(["a", "a", "c"], dtype=StringDtype()),
191+
Series(["a", "b", "c"], dtype=StringDtype()),
192+
],
193+
names=["a", "b"],
194+
)
195+
midx2 = MultiIndex.from_arrays(
196+
[Series(["a"], dtype=StringDtype()), Series(["c"], dtype=StringDtype())],
197+
names=["a", "c"],
198+
)
199+
result = midx.join(midx2, how="inner")
200+
expected = MultiIndex.from_arrays(
201+
[
202+
Series(["a", "a"], dtype=StringDtype()),
203+
Series(["a", "b"], dtype=StringDtype()),
204+
Series(["c", "c"], dtype=StringDtype()),
205+
],
206+
names=["a", "b", "c"],
207+
)
208+
tm.assert_index_equal(result, expected)

0 commit comments

Comments
 (0)