BUG: allow empty multiindex (fixes .isin regression, GH16777)
State: closed

 - [X] closes issue #16777
 - [X] tests added / passed
 - [X] passes ``git diff upstream/master --name-only -- '*.py' | flake8 --diff``
 - [X] whatsnew entry


Labels:
name: Regression
description: Functionality that used to work in a prior pandas version
name: MultiIndex

Comments:
# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/16782?src=pr&el=h1) Report
> Merging [#16782](https://codecov.io/gh/pandas-dev/pandas/pull/16782?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/65a0e642e1270791e6586c967758b362b865b6a8?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/16782/graphs/tree.svg?height=150&src=pr&token=eZ4WkYLtcO&width=650)](https://codecov.io/gh/pandas-dev/pandas/pull/16782?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master   #16782      +/-   ##
==========================================
+ Coverage   90.93%   90.94%   +<.01%     
==========================================
  Files         161      161              
  Lines       49260    49264       +4     
==========================================
+ Hits        44797    44801       +4     
  Misses       4463     4463
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `88.71% <100%> (ø)` | :arrow_up: |
| #single | `40.17% <33.33%> (-0.01%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/16782?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/indexes/multi.py](https://codecov.io/gh/pandas-dev/pandas/pull/16782?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9tdWx0aS5weQ==) | `96.66% <100%> (+0.01%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/16782?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/16782?src=pr&el=footer). Last update [65a0e64...6482014](https://codecov.io/gh/pandas-dev/pandas/pull/16782?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/16782?src=pr&el=h1) Report
> :exclamation: No coverage uploaded for pull request base (`master@f6edaef`). [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/16782/graphs/tree.svg?width=650&height=150&src=pr&token=eZ4WkYLtcO)](https://codecov.io/gh/pandas-dev/pandas/pull/16782?src=pr&el=tree)

```diff
@@            Coverage Diff            @@
##             master   #16782   +/-   ##
=========================================
  Coverage          ?   90.97%           
=========================================
  Files             ?      161           
  Lines             ?    49287           
  Branches          ?        0           
=========================================
  Hits              ?    44838           
  Misses            ?     4449           
  Partials          ?        0
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `88.74% <100%> (?)` | |
| #single | `40.16% <37.5%> (?)` | |

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

------

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

@drudd are you able to update this in the next few days? Releasing 0.20.3 by the end of the week. Are there any questions on the implementation or desired behavior?
Hi Tom, sorry, I was traveling over the weekend. I should be able to clean this up hopefully address comments today.
@drudd if you can fix up. we want to include with 0.20.3, releasing tomorrow.
Okay, I reported the issue of factorization (#16844), which unfortunately is difficult to work around. I've added some checks in the `.from_arrays` function to prevent `.from_arrays(arrays=[])` from being valid and adjusted tests accordingly. Not as clean as I'd like but any further changes are api breaking.

@jreback ~~I'm not sure I followed your last comment on the `MultiIndex.from_tuples([], names=['a', 'b'])` test. You agree with the test but think it should raise? My fix to the `.isin` issue relies on `.from_tuples` succeeding when passed an empty list, which unlike `.from_arrays` I believe to be correct behavior as it's the right input shape.~~  Nevermind, I see it followed from the discussion. I think I've addressed the major points and reduced the PR to the minimal change set.
thanks!