fixes #26622: pd.MultiIndex.isin should fail when input args are too short
State: closed

- [x] closes #26622
- [x] tests added / passed
- [x] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`
- [x] whatsnew entry

This fixes #26622 by making `pd.MultiIndex.isin` fail when input args are too short, as well as when they are too long (the current behavior). It also replaces existing error message with something a little bit clearly and more directly related to `isin` and its parameters.

Currently, `isin` does some validation by [constructing a new `MultiIndex` and then taking its `values`](https://github.com/pandas-dev/pandas/blob/addc5fcd95064b765d4ee4260304d44822fdee3b/pandas/core/indexes/multi.py#L3178):

    values = MultiIndex.from_tuples(values, names=self.names).values

Though the code I wrote should handle all validation relating to the length of the elements of `values`, I left this line in since I was unsure if it was validating/fixing anything else. Does anyone know if that line is safe to remove now?

Labels:
name: Error Reporting
description: Incorrect or improved errors from pandas
name: MultiIndex

Comments:
pls always add tests, how would u know if it works otherwise?
@jreback Already on it! I'll push em in a sec. What does the `whatsnew entry` on the checklist refer to?
> @jreback Already on it! I'll push em in a sec. What does the `whatsnew entry` on the checklist refer to?

doc/source/whatsnew/v0.25.0.rst
# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/26623?src=pr&el=h1) Report
> Merging [#26623](https://codecov.io/gh/pandas-dev/pandas/pull/26623?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/addc5fcd95064b765d4ee4260304d44822fdee3b?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/26623/graphs/tree.svg?width=650&token=eZ4WkYLtcO&height=150&src=pr)](https://codecov.io/gh/pandas-dev/pandas/pull/26623?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master   #26623      +/-   ##
==========================================
+ Coverage   91.86%   91.87%   +<.01%     
==========================================
  Files         174      174              
  Lines       50722    50696      -26     
==========================================
- Hits        46594    46575      -19     
+ Misses       4128     4121       -7
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.41% <100%> (+0.01%)` | :arrow_up: |
| #single | `41.78% <0%> (-0.11%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/26623?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/indexes/multi.py](https://codecov.io/gh/pandas-dev/pandas/pull/26623/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9tdWx0aS5weQ==) | `95.68% <100%> (+0.01%)` | :arrow_up: |
| [pandas/io/gbq.py](https://codecov.io/gh/pandas-dev/pandas/pull/26623/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL2dicS5weQ==) | `78.94% <0%> (-10.53%)` | :arrow_down: |
| [pandas/io/clipboard/\_\_init\_\_.py](https://codecov.io/gh/pandas-dev/pandas/pull/26623/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL2NsaXBib2FyZC9fX2luaXRfXy5weQ==) | `54.34% <0%> (-2.52%)` | :arrow_down: |
| [pandas/core/dtypes/cast.py](https://codecov.io/gh/pandas-dev/pandas/pull/26623/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZHR5cGVzL2Nhc3QucHk=) | `90.54% <0%> (-1%)` | :arrow_down: |
| [pandas/core/frame.py](https://codecov.io/gh/pandas-dev/pandas/pull/26623/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZnJhbWUucHk=) | `97% <0%> (-0.12%)` | :arrow_down: |
| [pandas/util/testing.py](https://codecov.io/gh/pandas-dev/pandas/pull/26623/diff?src=pr&el=tree#diff-cGFuZGFzL3V0aWwvdGVzdGluZy5weQ==) | `90.81% <0%> (-0.11%)` | :arrow_down: |
| [pandas/core/sparse/frame.py](https://codecov.io/gh/pandas-dev/pandas/pull/26623/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvc3BhcnNlL2ZyYW1lLnB5) | `95.63% <0%> (-0.02%)` | :arrow_down: |
| [pandas/core/generic.py](https://codecov.io/gh/pandas-dev/pandas/pull/26623/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZ2VuZXJpYy5weQ==) | `93.61% <0%> (-0.02%)` | :arrow_down: |
| [pandas/plotting/\_core.py](https://codecov.io/gh/pandas-dev/pandas/pull/26623/diff?src=pr&el=tree#diff-cGFuZGFzL3Bsb3R0aW5nL19jb3JlLnB5) | `83.77% <0%> (ø)` | :arrow_up: |
| [pandas/core/sparse/scipy\_sparse.py](https://codecov.io/gh/pandas-dev/pandas/pull/26623/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvc3BhcnNlL3NjaXB5X3NwYXJzZS5weQ==) | `100% <0%> (ø)` | :arrow_up: |
| ... and [3 more](https://codecov.io/gh/pandas-dev/pandas/pull/26623/diff?src=pr&el=tree-more) | |

------

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

Great. Thanks @simonjayhawkins for taking the time to review this.
cc @toobaz for thoughts on this
can you merge master and update to comments
can you merge master and move the note to 1.0.0
Closing as this looks stale, but @telamonian ping if you'd like to pick back up