COMPAT/TEST test, fix for unsafe Vector.resize(), which allows refche…
State: closed

closes issue #15854, supersedes pull request #16224, #16193 

Adds a test showing how the ``uniques`` attribute leaks to user space, and calling ``get_labels()`` again with different data could change the underlying ndarray. With this pull request an exception will be raised after calling ``append()`` after calling ``to_array()``, which makes the test pass. It also allows addition of the ``refcheck=False`` kwarg to ``ndarray.resize()``, which fixes the issue above.

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

Comments:
# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/16258?src=pr&el=h1) Report
> Merging [#16258](https://codecov.io/gh/pandas-dev/pandas/pull/16258?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/ba60321d00d686a3137ffe26f919d64e84d43aa0?src=pr&el=desc) will **decrease** coverage by `0.01%`.
> The diff coverage is `n/a`.

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

```diff
@@            Coverage Diff             @@
##           master   #16258      +/-   ##
==========================================
- Coverage   90.32%    90.3%   -0.02%     
==========================================
  Files         167      167              
  Lines       50907    50907              
==========================================
- Hits        45982    45973       -9     
- Misses       4925     4934       +9
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `88.09% <ø> (ø)` | :arrow_up: |
| #single | `40.29% <ø> (-0.11%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/16258?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/io/gbq.py](https://codecov.io/gh/pandas-dev/pandas/pull/16258?src=pr&el=tree#diff-cGFuZGFzL2lvL2dicS5weQ==) | `25% <0%> (-58.34%)` | :arrow_down: |
| [pandas/core/frame.py](https://codecov.io/gh/pandas-dev/pandas/pull/16258?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZnJhbWUucHk=) | `97.58% <0%> (-0.1%)` | :arrow_down: |

------

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

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

```diff
@@            Coverage Diff             @@
##           master   #16258      +/-   ##
==========================================
+ Coverage   90.34%   90.35%   +<.01%     
==========================================
  Files         167      161       -6     
  Lines       50908    50863      -45     
==========================================
- Hits        45994    45957      -37     
+ Misses       4914     4906       -8
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `88.13% <ø> (+0.02%)` | :arrow_up: |
| #single | `40.33% <ø> (-0.07%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/16258?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/io/gbq.py](https://codecov.io/gh/pandas-dev/pandas/pull/16258?src=pr&el=tree#diff-cGFuZGFzL2lvL2dicS5weQ==) | `25% <0%> (-58.34%)` | :arrow_down: |
| [pandas/io/msgpack/\_version.py](https://codecov.io/gh/pandas-dev/pandas/pull/16258?src=pr&el=tree#diff-cGFuZGFzL2lvL21zZ3BhY2svX3ZlcnNpb24ucHk=) | `44.86% <0%> (-55.14%)` | :arrow_down: |
| [pandas/core/util/hashing.py](https://codecov.io/gh/pandas-dev/pandas/pull/16258?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvdXRpbC9oYXNoaW5nLnB5) | `92.03% <0%> (-7.02%)` | :arrow_down: |
| [pandas/core/computation/expressions.py](https://codecov.io/gh/pandas-dev/pandas/pull/16258?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvY29tcHV0YXRpb24vZXhwcmVzc2lvbnMucHk=) | `90.47% <0%> (-2.21%)` | :arrow_down: |
| [pandas/plotting/\_converter.py](https://codecov.io/gh/pandas-dev/pandas/pull/16258?src=pr&el=tree#diff-cGFuZGFzL3Bsb3R0aW5nL19jb252ZXJ0ZXIucHk=) | `63.23% <0%> (-1.82%)` | :arrow_down: |
| [pandas/core/frame.py](https://codecov.io/gh/pandas-dev/pandas/pull/16258?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZnJhbWUucHk=) | `97.59% <0%> (-0.1%)` | :arrow_down: |
| [pandas/util/\_\_init\_\_.py](https://codecov.io/gh/pandas-dev/pandas/pull/16258?src=pr&el=tree#diff-cGFuZGFzL3V0aWwvX19pbml0X18ucHk=) | | |
| [pandas/formats/style.py](https://codecov.io/gh/pandas-dev/pandas/pull/16258?src=pr&el=tree#diff-cGFuZGFzL2Zvcm1hdHMvc3R5bGUucHk=) | | |
| [pandas/io/msgpack/\_\_init\_\_.py](https://codecov.io/gh/pandas-dev/pandas/pull/16258?src=pr&el=tree#diff-cGFuZGFzL2lvL21zZ3BhY2svX19pbml0X18ucHk=) | | |
| [pandas/io/json/\_\_init\_\_.py](https://codecov.io/gh/pandas-dev/pandas/pull/16258?src=pr&el=tree#diff-cGFuZGFzL2lvL2pzb24vX19pbml0X18ucHk=) | | |
| ... and [20 more](https://codecov.io/gh/pandas-dev/pandas/pull/16258?src=pr&el=tree-more) | |

------

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

Sorry it took so many builds to get tests to pass, I am still learning the build system
@chris-b1 any opinions?
@jreback rather than use format() in the error message, I simply shortened it. Thanks for the review
thanks!