Skip to content

Commit f82b1c6

Browse files
authored
REGR: MultiIndex.join does not work for ea dtypes (pandas-dev#49284)
* REGR: MultiIndex.join does not work for ea dtypes * Update base.py
1 parent ab89c53 commit f82b1c6

File tree

3 files changed

+53
-2
lines changed

3 files changed

+53
-2
lines changed

doc/source/whatsnew/v1.5.2.rst

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

1414
Fixed regressions
1515
~~~~~~~~~~~~~~~~~
16+
- Fixed regression in :meth:`MultiIndex.join` for extension array dtypes (:issue:`49277`)
1617
- Fixed regression in :meth:`Series.replace` raising ``RecursionError`` with numeric dtype and when specifying ``value=None`` (:issue:`45725`)
1718
- Fixed regression in :meth:`DataFrame.plot` preventing :class:`~matplotlib.colors.Colormap` instance
1819
from being passed using the ``colormap`` argument if Matplotlib 3.6+ is used (:issue:`49374`)

pandas/core/indexes/base.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -4456,8 +4456,10 @@ def join(
44564456
return self._join_non_unique(other, how=how)
44574457
elif not self.is_unique or not other.is_unique:
44584458
if self.is_monotonic_increasing and other.is_monotonic_increasing:
4459-
if self._can_use_libjoin:
4459+
if not is_interval_dtype(self.dtype):
44604460
# otherwise we will fall through to _join_via_get_indexer
4461+
# GH#39133
4462+
# go through object dtype for ea till engine is supported properly
44614463
return self._join_monotonic(other, how=how)
44624464
else:
44634465
return self._join_non_unique(other, how=how)
@@ -4832,7 +4834,7 @@ def _wrap_joined_index(self: _IndexT, joined: ArrayLike, other: _IndexT) -> _Ind
48324834
return self._constructor(joined, name=name) # type: ignore[return-value]
48334835
else:
48344836
name = get_op_result_name(self, other)
4835-
return self._constructor._with_infer(joined, name=name)
4837+
return self._constructor._with_infer(joined, name=name, dtype=self.dtype)
48364838

48374839
@cache_readonly
48384840
def _can_use_libjoin(self) -> bool:

pandas/tests/indexes/multi/test_join.py

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

@@ -161,6 +163,52 @@ def test_join_overlapping_interval_level():
161163
tm.assert_index_equal(result, expected)
162164

163165

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

0 commit comments

Comments
 (0)