DOC: Replace .values with .to_numpy() in enhancingperf
State: closed

As suggested in https://github.com/pandas-dev/pandas/issues/24807#issuecomment-454905470

Replace `.values` with `.to_numpy()` in the benchmark demonstration code.

Labels:
name: Docs

Comments:
Thanks for the PR! How much effort do you think it would it be to swap out all of these instances across the documentation?
# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/26313?src=pr&el=h1) Report
> Merging [#26313](https://codecov.io/gh/pandas-dev/pandas/pull/26313?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/20fa58d48a7788e980a084ac05196cab2cc055ac?src=pr&el=desc) will **decrease** coverage by `<.01%`.
> The diff coverage is `n/a`.

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

```diff
@@            Coverage Diff             @@
##           master   #26313      +/-   ##
==========================================
- Coverage   92.04%   92.03%   -0.01%     
==========================================
  Files         175      175              
  Lines       52302    52302              
==========================================
- Hits        48142    48137       -5     
- Misses       4160     4165       +5
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.59% <ø> (ø)` | :arrow_up: |
| #single | `40.73% <ø> (-0.17%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/26313?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/io/gbq.py](https://codecov.io/gh/pandas-dev/pandas/pull/26313/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL2dicS5weQ==) | `78.94% <0%> (-10.53%)` | :arrow_down: |
| [pandas/core/frame.py](https://codecov.io/gh/pandas-dev/pandas/pull/26313/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZnJhbWUucHk=) | `97.01% <0%> (-0.12%)` | :arrow_down: |
| [pandas/util/testing.py](https://codecov.io/gh/pandas-dev/pandas/pull/26313/diff?src=pr&el=tree#diff-cGFuZGFzL3V0aWwvdGVzdGluZy5weQ==) | `90.6% <0%> (-0.11%)` | :arrow_down: |

------

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

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

```diff
@@            Coverage Diff             @@
##           master   #26313      +/-   ##
==========================================
- Coverage   92.04%   92.03%   -0.01%     
==========================================
  Files         175      175              
  Lines       52302    52302              
==========================================
- Hits        48142    48137       -5     
- Misses       4160     4165       +5
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.59% <ø> (ø)` | :arrow_up: |
| #single | `40.73% <ø> (-0.17%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/26313?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/io/gbq.py](https://codecov.io/gh/pandas-dev/pandas/pull/26313/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL2dicS5weQ==) | `78.94% <0%> (-10.53%)` | :arrow_down: |
| [pandas/core/frame.py](https://codecov.io/gh/pandas-dev/pandas/pull/26313/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZnJhbWUucHk=) | `97.01% <0%> (-0.12%)` | :arrow_down: |
| [pandas/util/testing.py](https://codecov.io/gh/pandas-dev/pandas/pull/26313/diff?src=pr&el=tree#diff-cGFuZGFzL3V0aWwvdGVzdGluZy5weQ==) | `90.6% <0%> (-0.11%)` | :arrow_down: |

------

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

@WillAyd All the `.values` in this file have been replaced. 

Took a look at the other files under `pandas/doc/source`. Apart from `whatsnew` folder, no other file uses `.values` for pandas objects. And I suppose `whatsnew` files shouldn't be changed, right?
For our own edification, can those benchmark numbers be double-checked (i.e. the ones that follow the `timeit` commands)?  Are those still approximately correct when we swap in `to_numpy`?

And how much better is it vs. using `.values` ?
Thanks for the review.

I just checked that changing to `.to_numpy()` doesn’t change the benchmark time very much (less than 1%), and all the points that this guide tries to demonstrate still hold.

The performance comparison between `.to_numpy()` and `.values` is not discussed in this guide page. The difference seems negligible when compared to other things discussed in this guide page, such as Cython and Jit compiling. Personally I think the main reason behind this PR is to follow the documentation/community’s encouragement to use `.to_numpy()` rather than `.values`




> Personally I think the main reason behind this PR is to follow the documentation/community’s encouragement to use .to_numpy() rather than .values

True, but always good to double check to make sure we aren't actually proposing a performance regression in our docs.
Thanks @huizew !