PERF: Improve performance of Series.isin() on sets
State: closed

- [x] closes #25507
- [x] tests added / passed
- [x] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`
- [x] whatsnew entry

Issue #25507 pointed out that using `DataFrame.isin` or `Series.isin` on a set took extremely long due to the set being first converted to a list then back to a hash table to lookup values. This fix eliminates that conversion and simply uses the set to directly test membership.

Sample code from issue:
```python
import pandas as pd

squares = set(a**2 for a in range(10000000))
series = pd.Series(range(100))

def test_isin():
    _ = series.isin(squares)

%timeit test_isin()
```
Output:
```
Before:
3.89 s ± 66.1 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)

After:
134 µs ± 11.3 µs per loop (mean ± std. dev. of 7 runs, 10000 loops each)
```

There are already several unit tests covering this function on sets with different dtypes. Additionally, I added an additional asv benchmark for sets:
```
series_methods.IsIn.time_isin
======== =============
dtype
-------- -------------
int64    1.46±0.04ms
uint64    1.76±0.1ms
object    3.53±0.2ms
======== =============

series_methods.IsIn.time_isin_set
======== =============
dtype
-------- -------------
int64    1.58±0.03ms
uint64   1.61±0.06ms
object   3.24±0.04ms
======== =============
```
If the additional benchmark is overkill I can of course remove it.

Labels:
name: Performance
description: Memory or execution speed performance
name: Reshaping
description: Concat, Merge/Join, Stack/Unstack, Explode

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

```diff
@@            Coverage Diff             @@
##           master   #25812      +/-   ##
==========================================
+ Coverage   91.27%   91.27%   +<.01%     
==========================================
  Files         173      173              
  Lines       53002    53007       +5     
==========================================
+ Hits        48375    48381       +6     
+ Misses       4627     4626       -1
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `89.83% <100%> (ø)` | :arrow_up: |
| #single | `41.76% <20%> (-0.01%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/25812?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/algorithms.py](https://codecov.io/gh/pandas-dev/pandas/pull/25812/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvYWxnb3JpdGhtcy5weQ==) | `94.83% <100%> (+0.03%)` | :arrow_up: |
| [pandas/util/testing.py](https://codecov.io/gh/pandas-dev/pandas/pull/25812/diff?src=pr&el=tree#diff-cGFuZGFzL3V0aWwvdGVzdGluZy5weQ==) | `89.4% <0%> (+0.1%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/25812?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/25812?src=pr&el=footer). Last update [fbe2523...a083384](https://codecov.io/gh/pandas-dev/pandas/pull/25812?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/25812?src=pr&el=h1) Report
> Merging [#25812](https://codecov.io/gh/pandas-dev/pandas/pull/25812?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/9e27f1298d4cd1dcfcf559937125e547c0341f0e?src=pr&el=desc) will **increase** coverage by `0.14%`.
> The diff coverage is `100%`.

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

```diff
@@            Coverage Diff             @@
##           master   #25812      +/-   ##
==========================================
+ Coverage    91.3%   91.45%   +0.14%     
==========================================
  Files         173      172       -1     
  Lines       53004    52899     -105     
==========================================
- Hits        48397    48380      -17     
+ Misses       4607     4519      -88
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.02% <100%> (+0.14%)` | :arrow_up: |
| #single | `41.82% <42.85%> (+0.05%)` | :arrow_up: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/25812?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/dtypes/common.py](https://codecov.io/gh/pandas-dev/pandas/pull/25812/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZHR5cGVzL2NvbW1vbi5weQ==) | `96.78% <ø> (ø)` | :arrow_up: |
| [pandas/core/dtypes/inference.py](https://codecov.io/gh/pandas-dev/pandas/pull/25812/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZHR5cGVzL2luZmVyZW5jZS5weQ==) | `98.46% <100%> (+0.04%)` | :arrow_up: |
| [pandas/core/algorithms.py](https://codecov.io/gh/pandas-dev/pandas/pull/25812/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvYWxnb3JpdGhtcy5weQ==) | `94.83% <100%> (+0.03%)` | :arrow_up: |
| [pandas/io/feather\_format.py](https://codecov.io/gh/pandas-dev/pandas/pull/25812/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL2ZlYXRoZXJfZm9ybWF0LnB5) | `89.47% <0%> (-0.27%)` | :arrow_down: |
| [pandas/core/computation/engines.py](https://codecov.io/gh/pandas-dev/pandas/pull/25812/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvY29tcHV0YXRpb24vZW5naW5lcy5weQ==) | `88.7% <0%> (-0.18%)` | :arrow_down: |
| [pandas/plotting/\_tools.py](https://codecov.io/gh/pandas-dev/pandas/pull/25812/diff?src=pr&el=tree#diff-cGFuZGFzL3Bsb3R0aW5nL190b29scy5weQ==) | `78.65% <0%> (-0.12%)` | :arrow_down: |
| [pandas/util/testing.py](https://codecov.io/gh/pandas-dev/pandas/pull/25812/diff?src=pr&el=tree#diff-cGFuZGFzL3V0aWwvdGVzdGluZy5weQ==) | `89.3% <0%> (-0.11%)` | :arrow_down: |
| [pandas/io/excel/\_xlrd.py](https://codecov.io/gh/pandas-dev/pandas/pull/25812/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL2V4Y2VsL194bHJkLnB5) | `93.93% <0%> (-0.1%)` | :arrow_down: |
| [pandas/core/tools/datetimes.py](https://codecov.io/gh/pandas-dev/pandas/pull/25812/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvdG9vbHMvZGF0ZXRpbWVzLnB5) | `84.59% <0%> (-0.05%)` | :arrow_down: |
| [pandas/core/computation/align.py](https://codecov.io/gh/pandas-dev/pandas/pull/25812/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvY29tcHV0YXRpb24vYWxpZ24ucHk=) | `97.82% <0%> (-0.03%)` | :arrow_down: |
| ... and [14 more](https://codecov.io/gh/pandas-dev/pandas/pull/25812/diff?src=pr&el=tree-more) | |

------

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