Skip to content

BUG: Fixed __join_multi always returning indexers (#34074) #34075

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
May 11, 2020
Merged
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v1.1.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ MultiIndex
# Common elements are now guaranteed to be ordered by the left side
left.intersection(right, sort=False)

-
- Bug when joining 2 Multi-indexes, without specifying level with different columns. Return-indexers parameter is ignored. (:issue:`34074`)

I/O
^^^
Expand Down
5 changes: 4 additions & 1 deletion pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3529,7 +3529,10 @@ def _join_multi(self, other, how, return_indexers=True):

multi_join_idx = multi_join_idx.remove_unused_levels()

return multi_join_idx, lidx, ridx
if return_indexers:
return multi_join_idx, lidx, ridx
else:
return multi_join_idx

jl = list(overlap)[0]

Expand Down
11 changes: 10 additions & 1 deletion pandas/tests/indexes/multi/test_join.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,19 @@ def test_join_multi_wrong_order():
midx1 = pd.MultiIndex.from_product([[1, 2], [3, 4]], names=["a", "b"])
midx2 = pd.MultiIndex.from_product([[1, 2], [3, 4]], names=["b", "a"])

join_idx, lidx, ridx = midx1.join(midx2, return_indexers=False)
join_idx, lidx, ridx = midx1.join(midx2, return_indexers=True)

exp_ridx = np.array([-1, -1, -1, -1], dtype=np.intp)

tm.assert_index_equal(midx1, join_idx)
assert lidx is None
tm.assert_numpy_array_equal(ridx, exp_ridx)


def test_join_multi_return_indexers():
# GH 34074

midx1 = pd.MultiIndex.from_product([[1, 2], [3, 4], [5, 6]], names=["a", "b", "c"])
midx2 = pd.MultiIndex.from_product([[1, 2], [3, 4]], names=["a", "b"])

assert type(midx1.join(midx2, return_indexers=False)) != tuple