Fix passing empty label to df drop
State: closed

- Closes #21494
- Tests added / passed

-Drop method in indexes/base.py, docs say KeyError should only be raised if **none** of labels are found in selected axis. However `pd.DataFrame(index=[1,2,3]).drop([1, 4])` throws.

-Makes behaviour consistent for .drop() across unique/non-unique indexes.
Both the below will now raise a KeyError

- `pd.DataFrame(index=[1,2,3]).drop([1, 4])`
- `pd.DataFrame(index=[1,1,3]).drop([1, 4])`

-Remove unused var `indexer` and `_axis`

Labels:
name: Indexing
description: Related to indexing on series/frames, not to indexes themselves
name: MultiIndex

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











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

##### Comment last updated on June 21, 2018 at 08:11 Hours UTC
Test failure in: test_multilevel.py looking into this
Thanks @toobaz updated as per your comments and fixed that test. ( When `level is not None` is true we still need to call indexer.all()
> When level is not None is true we still need to call indexer.all()

OK, I see the problem, ``pd.MultiIndex.from_product([[1, 2]]*2).drop([3], level=0)`` does not actually raise ( #18561 ). OK to fix it elsewhere, but please refer to that issue in a comment.
(I think the ``indexer.all()`` only solves some specific case by chance)
# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/21515?src=pr&el=h1) Report
> Merging [#21515](https://codecov.io/gh/pandas-dev/pandas/pull/21515?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/f91a7049d1730aa1924584a07a1265d9f57a2f35?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/21515/graphs/tree.svg?width=650&height=150&token=eZ4WkYLtcO&src=pr)](https://codecov.io/gh/pandas-dev/pandas/pull/21515?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master   #21515      +/-   ##
==========================================
+ Coverage   91.92%   91.92%   +<.01%     
==========================================
  Files         153      153              
  Lines       49564    49560       -4     
==========================================
- Hits        45560    45558       -2     
+ Misses       4004     4002       -2
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.32% <100%> (ø)` | :arrow_up: |
| #single | `41.8% <25%> (-0.01%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/21515?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/indexes/multi.py](https://codecov.io/gh/pandas-dev/pandas/pull/21515/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9tdWx0aS5weQ==) | `94.97% <ø> (-0.01%)` | :arrow_down: |
| [pandas/core/indexes/base.py](https://codecov.io/gh/pandas-dev/pandas/pull/21515/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9iYXNlLnB5) | `96.62% <100%> (ø)` | :arrow_up: |
| [pandas/core/generic.py](https://codecov.io/gh/pandas-dev/pandas/pull/21515/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZ2VuZXJpYy5weQ==) | `96.22% <100%> (+0.09%)` | :arrow_up: |
| [pandas/core/sorting.py](https://codecov.io/gh/pandas-dev/pandas/pull/21515/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvc29ydGluZy5weQ==) | `98.19% <0%> (-0.01%)` | :arrow_down: |

------

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

Thanks @jreback updated as per your comments, also when building the docs I noticed we didn't have the whatsnew entry for 0.23.2 in whatsnew.rst, this intended or want me to add?
Np @jreback moved them to original file and added parameterization
@toobaz pls approve & merge when satisfied. lgtm.
@toobaz updated as per your comments, thanks
@alimcmaster1 thanks!
thanks for the help @toobaz