ENH: Multi-level join on multi-indexes
State: closed

closes #6360

Allow for merging on multiple levels of multi-indexes

Labels:
name: Reshaping
description: Concat, Merge/Join, Stack/Unstack, Explode

Comments:
# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/16162?src=pr&el=h1) Report
> Merging [#16162](https://codecov.io/gh/pandas-dev/pandas/pull/16162?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/075eca1fa085359b71f26d02c2f44156068e123c?src=pr&el=desc) will **decrease** coverage by `0.01%`.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/pandas-dev/pandas/pull/16162/graphs/tree.svg?token=eZ4WkYLtcO&width=650&src=pr&height=150)](https://codecov.io/gh/pandas-dev/pandas/pull/16162?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master   #16162      +/-   ##
==========================================
- Coverage   90.87%   90.85%   -0.02%     
==========================================
  Files         162      162              
  Lines       50816    50852      +36     
==========================================
+ Hits        46178    46202      +24     
- Misses       4638     4650      +12
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `88.63% <100%> (-0.02%)` | :arrow_down: |
| #single | `40.3% <0%> (-0.03%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/16162?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/indexes/base.py](https://codecov.io/gh/pandas-dev/pandas/pull/16162?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9iYXNlLnB5) | `96.27% <100%> (+0.07%)` | :arrow_up: |
| [pandas/plotting/\_converter.py](https://codecov.io/gh/pandas-dev/pandas/pull/16162?src=pr&el=tree#diff-cGFuZGFzL3Bsb3R0aW5nL19jb252ZXJ0ZXIucHk=) | `63.54% <0%> (-1.82%)` | :arrow_down: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/16162?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/16162?src=pr&el=footer). Last update [075eca1...75dea48](https://codecov.io/gh/pandas-dev/pandas/pull/16162?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/16162?src=pr&el=h1) Report
> :exclamation: No coverage uploaded for pull request base (`master@0d86742`). [Click here to learn what that means](https://docs.codecov.io/docs/error-reference#section-missing-base-commit).
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/pandas-dev/pandas/pull/16162/graphs/tree.svg?height=150&width=650&src=pr&token=eZ4WkYLtcO)](https://codecov.io/gh/pandas-dev/pandas/pull/16162?src=pr&el=tree)

```diff
@@            Coverage Diff            @@
##             master   #16162   +/-   ##
=========================================
  Coverage          ?   91.22%           
=========================================
  Files             ?      163           
  Lines             ?    49837           
  Branches          ?        0           
=========================================
  Hits              ?    45462           
  Misses            ?     4375           
  Partials          ?        0
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `89.02% <100%> (?)` | |
| #single | `40.3% <3.92%> (?)` | |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/16162?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/indexes/base.py](https://codecov.io/gh/pandas-dev/pandas/pull/16162/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9iYXNlLnB5) | `96.37% <100%> (ø)` | |
| [pandas/core/reshape/merge.py](https://codecov.io/gh/pandas-dev/pandas/pull/16162/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvcmVzaGFwZS9tZXJnZS5weQ==) | `94.52% <100%> (ø)` | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/16162?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/16162?src=pr&el=footer). Last update [0d86742...5da2e44](https://codecov.io/gh/pandas-dev/pandas/pull/16162?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

Can anyone give some insight on the failure of Travis CI tests?
Some linting (style) issues, starting at https://travis-ci.org/pandas-dev/pandas/jobs/232494137#L1403

You can `pip install flake8` and run it on the files your changing.
pls rebase and update
Hello @harisbal! Thanks for updating the PR.





 - In the file [`pandas/tests/reshape/merge/test_merge.py`](https://github.com/pandas-dev/pandas/blob/c562204e36c0abaad08e2fcbcc31fda1dc4c11ea/pandas/tests/reshape/merge/test_merge.py), following are the PEP8 issues :

> [Line 1433:5](https://github.com/pandas-dev/pandas/blob/c562204e36c0abaad08e2fcbcc31fda1dc4c11ea/pandas/tests/reshape/merge/test_merge.py#L1433): [E303](https://duckduckgo.com/?q=pep8%20E303) too many blank lines (2)



##### Comment last updated on March 11, 2018 at 13:40 Hours UTC
also the docs in merging.rst need updating. pls add a small sub-section in 0.21.0 as well showcasing the new functionaility.
Thank you @jreback, I'll implement the changes
@harisbal great. sorry it took so long on this.
It was actually my fault. Thanks again for all the comments :)
@jreback I have implemented the changes but one test is failing and I'm struggling to understand why. Shall I upload so you can give it a look?
@harisbal what test is failing? l
can you rebase
@jreback  Any idea why the tests do not fail when I run them locally?
Hmm @harisbal seems like there was a rebase snafu in https://github.com/pandas-dev/pandas/pull/16162/commits/5c27d875759f265bf79d7c9c989cf2464cab8a59. Need help fixing it up?
@TomAugspurger  thank you very much but I managed to rebase properly. I now have an issue when I try to outer join on an empty level. I cannot debug after a certain point (I assume cython comes into play) so some help would be much appreciated
can you rebase. let's see if we can get this in.
Two tests fail and I can't see how to fix the issue
rebase and sqash commits or create a new pr
@harisbal sorry let this drop. can you rebase and we can get this in.
This pull request is dirty beyond repair. I'll squash and start a new one