REF/CLN: ops boilerplate #23853
State: closed

-  closes #23853
-  passes `git diff upstream/master -u -- "*.py" | flake8 --diff`

Implement a wrapper class other than a single decorator. It is tidier to add more conditions for ops later.


Labels:
name: Refactor
description: Internal refactoring of code
name: Internals
description: Related to non-user accessible pandas implementation
name: Clean

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

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

```diff
@@            Coverage Diff             @@
##           master   #24846      +/-   ##
==========================================
- Coverage   92.39%   92.38%   -0.01%     
==========================================
  Files         166      166              
  Lines       52378    52400      +22     
==========================================
+ Hits        48393    48412      +19     
- Misses       3985     3988       +3
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.81% <89.13%> (-0.01%)` | :arrow_down: |
| #single | `42.94% <84.78%> (+0.03%)` | :arrow_up: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/24846?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/arrays/\_\_init\_\_.py](https://codecov.io/gh/pandas-dev/pandas/pull/24846/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvYXJyYXlzL19faW5pdF9fLnB5) | `100% <ø> (ø)` | :arrow_up: |
| [pandas/core/arrays/integer.py](https://codecov.io/gh/pandas-dev/pandas/pull/24846/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvYXJyYXlzL2ludGVnZXIucHk=) | `96.61% <100%> (+0.28%)` | :arrow_up: |
| [pandas/core/arrays/timedeltas.py](https://codecov.io/gh/pandas-dev/pandas/pull/24846/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvYXJyYXlzL3RpbWVkZWx0YXMucHk=) | `88.33% <100%> (+0.12%)` | :arrow_up: |
| [pandas/core/arrays/period.py](https://codecov.io/gh/pandas-dev/pandas/pull/24846/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvYXJyYXlzL3BlcmlvZC5weQ==) | `98.51% <100%> (-0.02%)` | :arrow_down: |
| [pandas/core/arrays/datetimes.py](https://codecov.io/gh/pandas-dev/pandas/pull/24846/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvYXJyYXlzL2RhdGV0aW1lcy5weQ==) | `97.76% <100%> (-0.02%)` | :arrow_down: |
| [pandas/core/arrays/base.py](https://codecov.io/gh/pandas-dev/pandas/pull/24846/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvYXJyYXlzL2Jhc2UucHk=) | `96.17% <86.84%> (-2.09%)` | :arrow_down: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/24846?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/24846?src=pr&el=footer). Last update [f4458c1...6d0f4dd](https://codecov.io/gh/pandas-dev/pandas/pull/24846?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/24846?src=pr&el=h1) Report
> Merging [#24846](https://codecov.io/gh/pandas-dev/pandas/pull/24846?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/2b16e2e6c5a298396727fc2e66a60edf1eb13bf9?src=pr&el=desc) will **decrease** coverage by `<.01%`.
> The diff coverage is `90.9%`.

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

```diff
@@            Coverage Diff             @@
##           master   #24846      +/-   ##
==========================================
- Coverage   92.38%   92.38%   -0.01%     
==========================================
  Files         166      166              
  Lines       52398    52417      +19     
==========================================
+ Hits        48406    48423      +17     
- Misses       3992     3994       +2
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.8% <90.9%> (-0.01%)` | :arrow_down: |
| #single | `42.92% <87.27%> (+0.03%)` | :arrow_up: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/24846?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/arrays/datetimelike.py](https://codecov.io/gh/pandas-dev/pandas/pull/24846/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvYXJyYXlzL2RhdGV0aW1lbGlrZS5weQ==) | `97.83% <100%> (+0.15%)` | :arrow_up: |
| [pandas/core/arrays/period.py](https://codecov.io/gh/pandas-dev/pandas/pull/24846/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvYXJyYXlzL3BlcmlvZC5weQ==) | `98.51% <100%> (-0.02%)` | :arrow_down: |
| [pandas/core/arrays/timedeltas.py](https://codecov.io/gh/pandas-dev/pandas/pull/24846/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvYXJyYXlzL3RpbWVkZWx0YXMucHk=) | `88.43% <100%> (+0.12%)` | :arrow_up: |
| [pandas/core/arrays/categorical.py](https://codecov.io/gh/pandas-dev/pandas/pull/24846/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvYXJyYXlzL2NhdGVnb3JpY2FsLnB5) | `95.96% <100%> (-0.02%)` | :arrow_down: |
| [pandas/core/arrays/datetimes.py](https://codecov.io/gh/pandas-dev/pandas/pull/24846/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvYXJyYXlzL2RhdGV0aW1lcy5weQ==) | `97.77% <100%> (-0.03%)` | :arrow_down: |
| [pandas/core/ops.py](https://codecov.io/gh/pandas-dev/pandas/pull/24846/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvb3BzLnB5) | `93.93% <86.84%> (-0.36%)` | :arrow_down: |
| [pandas/util/testing.py](https://codecov.io/gh/pandas-dev/pandas/pull/24846/diff?src=pr&el=tree#diff-cGFuZGFzL3V0aWwvdGVzdGluZy5weQ==) | `88.13% <0%> (+0.09%)` | :arrow_up: |

------

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

To close #23853 this would need to handle arithmetic ops in addition to comparison ops
Any reason not to wrap Categorical comparison ops?
@jbrockmendel if you'd have a look.
@jreback I'm -1 on this as implemented.  The point of #23853 is to make all the methods behave the same; this does not do that.  And while it technically removes boilerplate, it does so with a net increase in LOC.

Even if merged, this does not close #23853, since there are many methods this isn't applied to.

A better approach would be to write a single decorator with the desired behavior (like #24282) and apply it in subset of methods where it wouldn't change behavior, then gradually expand that subset by fixing the methods with idiosyncratic behavior.
@makbigc if you want to respond to @jbrockmendel comments, alternatively can close.
closing, @makbigc a followup according to @jbrockmendel comments would be ok