PERF: improved clip performance
State: closed

closes #15400
In [1]: np.random.seed(1234)

In [2]: s = pd.Series(np.random.randn(50))

master
```
In [3]: %timeit s.clip(0, 1)
1.65 ms ± 48.2 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)
```

PR
```
In [3]: %timeit s.clip(0, 1)
124 µs ± 2.79 µs per loop (mean ± std. dev. of 7 runs, 10000 loops each)
```

prob as good as can do for now as we still have 2 where ops (numpy does this in a single loop), and we have a mask check and fill (and final construction).

but about 15x better

Labels:
name: Performance
description: Memory or execution speed performance

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

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

```diff
@@            Coverage Diff             @@
##           master   #16364      +/-   ##
==========================================
- Coverage   90.38%   90.36%   -0.02%     
==========================================
  Files         161      161              
  Lines       50916    50933      +17     
==========================================
+ Hits        46021    46028       +7     
- Misses       4895     4905      +10
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `88.14% <94.11%> (ø)` | :arrow_up: |
| #single | `40.21% <5.88%> (-0.12%)` | :arrow_down: |

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

------

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

> new implementation does not preserve heterogeneous data types

In principle could add a check for that (at the if statement to decide to take this path or not), but not sure that is worth it ..
yeah this is a limitation of the current methodology

let me see what i can do