Idx droplevel
State: closed

- [x] closes #21115
- [x] tests added / passed
- [x] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`
- [x] whatsnew entry

Collateral change: if ``mi`` is a ``MultiIndex``, ``mi.droplevel([])`` will now return ``mi`` itself, not a copy of it. Given that these are immutable objects, seems OK to me - but if a copy is preferred, the change is trivial.

Labels:
name: API Design
name: MultiIndex

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

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

```diff
@@            Coverage Diff             @@
##           master   #21116      +/-   ##
==========================================
+ Coverage   91.83%   91.84%   +<.01%     
==========================================
  Files         153      153              
  Lines       49498    49505       +7     
==========================================
+ Hits        45458    45466       +8     
+ Misses       4040     4039       -1
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.23% <100%> (ø)` | :arrow_up: |
| #single | `41.88% <76.66%> (ø)` | :arrow_up: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/21116?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/indexes/multi.py](https://codecov.io/gh/pandas-dev/pandas/pull/21116/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9tdWx0aS5weQ==) | `94.99% <ø> (-0.09%)` | :arrow_down: |
| [pandas/core/series.py](https://codecov.io/gh/pandas-dev/pandas/pull/21116/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvc2VyaWVzLnB5) | `94.12% <100%> (ø)` | :arrow_up: |
| [pandas/core/frame.py](https://codecov.io/gh/pandas-dev/pandas/pull/21116/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZnJhbWUucHk=) | `97.22% <100%> (-0.01%)` | :arrow_down: |
| [pandas/core/indexes/base.py](https://codecov.io/gh/pandas-dev/pandas/pull/21116/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9iYXNlLnB5) | `96.68% <100%> (+0.04%)` | :arrow_up: |
| [pandas/core/reshape/reshape.py](https://codecov.io/gh/pandas-dev/pandas/pull/21116/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvcmVzaGFwZS9yZXNoYXBlLnB5) | `99.78% <0%> (-0.22%)` | :arrow_down: |
| [pandas/core/accessor.py](https://codecov.io/gh/pandas-dev/pandas/pull/21116/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvYWNjZXNzb3IucHk=) | `98.71% <0%> (ø)` | :arrow_up: |
| [pandas/core/common.py](https://codecov.io/gh/pandas-dev/pandas/pull/21116/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvY29tbW9uLnB5) | `92.09% <0%> (+0.08%)` | :arrow_up: |
| [pandas/util/testing.py](https://codecov.io/gh/pandas-dev/pandas/pull/21116/diff?src=pr&el=tree#diff-cGFuZGFzL3V0aWwvdGVzdGluZy5weQ==) | `84.81% <0%> (+0.21%)` | :arrow_up: |

------

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

Should this be added to `api.rst` under `Index`?
> Should this be added to api.rst under Index?

Not sure, we should find a general decision in #3268 (my understanding is that subdivisions in api.rst are thematic, and droplevel certainly _has to do_ with ``MultiIndex``)
Ready to merge if there are no objections
will look in a bit
> can you add to api.rst as well (as the one for MI is already there), merge when good.

``MultiIndex`` is an ``Index``, so if I add it in the ``Index`` section I will remove it from the ``MultiIndex`` section. And I argue this would not help users. We can probably reorganize api.rst better when we work on #3268, but only moving ``droplevel`` (and not, say, ``swaplevel``) is not good.
> MultiIndex is an Index, so if I add it in the Index section I will remove it from the MultiIndex

just add it to both
> just add it to both

There is no "both" as there is no specific ``Index`` section: I created a new section but it's probably going to be removed/changed when #3268 evolves.
thanks!
@toobaz Let's keep this for 0.24.0 ? (it's a new method/feature) 
Or does any of the other bug fixes depend on it?
> @toobaz Let's keep this for 0.24.0 ? (it's a new method/feature)

I don't see any harm (but it's not entirely obvious what this means to me: just move to the other whatsnew?)
Yes, in practice that is what it means. 
(I was planning to do a PR to clean up the whatsnew file for and just saw this was the only new feature)
> (I was planning to do a PR to clean up the whatsnew file for and just saw this was the only new feature)

OK! So you're taking care of this in your PR? Or should I open another one?


Yep, will do