API: referring to duplicate level name raises ValueError
State: closed

follow-up on: https://github.com/pandas-dev/pandas/pull/21423

But, this currently has a lot of failures, because of https://github.com/pandas-dev/pandas/issues/21677 that we first need to resolve.

Labels:
name: API Design
name: MultiIndex

Comments:
Hello @jorisvandenbossche! Thanks for updating the PR.







Cheers ! There are no PEP8 issues in this Pull Request. :beers: 

##### Comment last updated on July 08, 2018 at 13:57 Hours UTC
Changed the implementation a bit to keep the fallback logic for integer names, to decouple it from the discussion in #21677 
# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/21678?src=pr&el=h1) Report
> :exclamation: No coverage uploaded for pull request base (`master@1986dbe`). [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/21678/graphs/tree.svg?width=650&height=150&src=pr&token=eZ4WkYLtcO)](https://codecov.io/gh/pandas-dev/pandas/pull/21678?src=pr&el=tree)

```diff
@@            Coverage Diff            @@
##             master   #21678   +/-   ##
=========================================
  Coverage          ?    91.9%           
=========================================
  Files             ?      160           
  Lines             ?    49894           
  Branches          ?        0           
=========================================
  Hits              ?    45854           
  Misses            ?     4040           
  Partials          ?        0
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.28% <100%> (?)` | |
| #single | `42.1% <75%> (?)` | |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/21678?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/reshape/reshape.py](https://codecov.io/gh/pandas-dev/pandas/pull/21678/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvcmVzaGFwZS9yZXNoYXBlLnB5) | `99.78% <ø> (ø)` | |
| [pandas/core/indexes/multi.py](https://codecov.io/gh/pandas-dev/pandas/pull/21678/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9tdWx0aS5weQ==) | `95.04% <100%> (ø)` | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/21678?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/21678?src=pr&el=footer). Last update [1986dbe...450c6bd](https://codecov.io/gh/pandas-dev/pandas/pull/21678?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

> wow much simpler

I don't think the code is simpler, the diff is just smaller :-)

> any downsides to doing this?

I don't think so. 
It's an api change, but only a minor one I think. In principle we could also keep it as KeyError (I don't think there is necessarily a more correct one, although KeyError is typically used for non-existing key, while here the key is existing but duplicate), but then encountering this in eg `stack` would change from ValueError to KeyError (so a api change as well).