COMPAT: Remove use of private re attribute
State: closed

Closes https://github.com/pandas-dev/pandas/issues/20551

Labels:
name: Compat
description: pandas objects compatability with Numpy or Python functions

Comments:
This is a bit slower.  3.6

```python
In [3]: t1 = typing.re.Pattern

In [4]: t2 = type(re.compile(''))

In [5]: %timeit isinstance('', t1)
424 ns ± 8.76 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)

In [6]: %timeit isinstance('', t2)
99.5 ns ± 1.58 ns per loop (mean ± std. dev. of 7 runs, 10000000 loops each)
```

3.7

```python
In [1]: import re

In [2]: import typing

In [3]: t1 = typing.re.Pattern

In [4]: t2 = type(re.compile(''))

In [5]: %timeit isinstance('', t1)
741 ns ± 9.73 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)

In [6]: %timeit isinstance('', t2)
105 ns ± 1.62 ns per loop (mean ± std. dev. of 7 runs, 10000000 loops each)
```

So just use `type(re.compile(''))` everywhere?

I think the timings are small enough, that I'd rather just use `typing.re.Pattern` since it's a bit clearer.
# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/20553?src=pr&el=h1) Report
> Merging [#20553](https://codecov.io/gh/pandas-dev/pandas/pull/20553?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/c4b4a81f56205082ec7f12bf77766e3b74d27c37?src=pr&el=desc) will **increase** coverage by `0.02%`.
> The diff coverage is `83.33%`.

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

```diff
@@            Coverage Diff             @@
##           master   #20553      +/-   ##
==========================================
+ Coverage   91.81%   91.83%   +0.02%     
==========================================
  Files         152      152              
  Lines       49259    49264       +5     
==========================================
+ Hits        45229    45244      +15     
+ Misses       4030     4020      -10
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.22% <83.33%> (+0.02%)` | :arrow_up: |
| #single | `41.9% <83.33%> (ø)` | :arrow_up: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/20553?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/dtypes/inference.py](https://codecov.io/gh/pandas-dev/pandas/pull/20553/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZHR5cGVzL2luZmVyZW5jZS5weQ==) | `98.41% <100%> (ø)` | :arrow_up: |
| [pandas/compat/\_\_init\_\_.py](https://codecov.io/gh/pandas-dev/pandas/pull/20553/diff?src=pr&el=tree#diff-cGFuZGFzL2NvbXBhdC9fX2luaXRfXy5weQ==) | `58.43% <80%> (+0.69%)` | :arrow_up: |
| [pandas/util/testing.py](https://codecov.io/gh/pandas-dev/pandas/pull/20553/diff?src=pr&el=tree#diff-cGFuZGFzL3V0aWwvdGVzdGluZy5weQ==) | `84.52% <0%> (-0.21%)` | :arrow_down: |
| [pandas/core/series.py](https://codecov.io/gh/pandas-dev/pandas/pull/20553/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvc2VyaWVzLnB5) | `93.85% <0%> (ø)` | :arrow_up: |
| [pandas/plotting/\_converter.py](https://codecov.io/gh/pandas-dev/pandas/pull/20553/diff?src=pr&el=tree#diff-cGFuZGFzL3Bsb3R0aW5nL19jb252ZXJ0ZXIucHk=) | `66.81% <0%> (+1.73%)` | :arrow_up: |

------

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

lgtm.
thanks!