REF: Refactor Date/TimeLikeOps
State: closed

No real functional changes, just an inheritance reorganization to make the diff at #24024 smaller.

Changes:

- Removes DatelikeOps from PeriodIndex (already had strftime via delegation)
- Moves Date/TimelikeOps from DatetimeIndex to DatetimeArray
- Moves TimelikeOps from TimedeltaIndex to TimedeltaArray

Labels:
name: Refactor
description: Internal refactoring of code
name: Datetime
description: Datetime data dtype

Comments:
Hello @TomAugspurger! Thanks for submitting the PR.

 - There are no PEP8 issues in the file [`pandas/core/arrays/datetimelike.py`](https://github.com/TomAugspurger/pandas/blob/becf7d79abd34eecee90ba5a778846c9db3b497c/pandas/core/arrays/datetimelike.py) !

 - There are no PEP8 issues in the file [`pandas/core/arrays/datetimes.py`](https://github.com/TomAugspurger/pandas/blob/becf7d79abd34eecee90ba5a778846c9db3b497c/pandas/core/arrays/datetimes.py) !

 - There are no PEP8 issues in the file [`pandas/core/arrays/timedeltas.py`](https://github.com/TomAugspurger/pandas/blob/becf7d79abd34eecee90ba5a778846c9db3b497c/pandas/core/arrays/timedeltas.py) !

 - There are no PEP8 issues in the file [`pandas/core/indexes/datetimelike.py`](https://github.com/TomAugspurger/pandas/blob/becf7d79abd34eecee90ba5a778846c9db3b497c/pandas/core/indexes/datetimelike.py) !

 - There are no PEP8 issues in the file [`pandas/core/indexes/datetimes.py`](https://github.com/TomAugspurger/pandas/blob/becf7d79abd34eecee90ba5a778846c9db3b497c/pandas/core/indexes/datetimes.py) !

 - There are no PEP8 issues in the file [`pandas/core/indexes/period.py`](https://github.com/TomAugspurger/pandas/blob/becf7d79abd34eecee90ba5a778846c9db3b497c/pandas/core/indexes/period.py) !

 - There are no PEP8 issues in the file [`pandas/core/indexes/timedeltas.py`](https://github.com/TomAugspurger/pandas/blob/becf7d79abd34eecee90ba5a778846c9db3b497c/pandas/core/indexes/timedeltas.py) !


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

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

```diff
@@            Coverage Diff             @@
##           master   #24038      +/-   ##
==========================================
- Coverage   42.46%   42.45%   -0.01%     
==========================================
  Files         161      161              
  Lines       51557    51557              
==========================================
- Hits        21892    21889       -3     
- Misses      29665    29668       +3
```

| Flag | Coverage Δ | |
|---|---|---|
| #single | `42.45% <48.07%> (-0.01%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/24038?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/indexes/period.py](https://codecov.io/gh/pandas-dev/pandas/pull/24038/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9wZXJpb2QucHk=) | `39.82% <100%> (ø)` | :arrow_up: |
| [pandas/core/indexes/datetimelike.py](https://codecov.io/gh/pandas-dev/pandas/pull/24038/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9kYXRldGltZWxpa2UucHk=) | `53.54% <100%> (+1%)` | :arrow_up: |
| [pandas/core/arrays/timedeltas.py](https://codecov.io/gh/pandas-dev/pandas/pull/24038/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvYXJyYXlzL3RpbWVkZWx0YXMucHk=) | `50.28% <100%> (ø)` | :arrow_up: |
| [pandas/core/indexes/datetimes.py](https://codecov.io/gh/pandas-dev/pandas/pull/24038/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9kYXRldGltZXMucHk=) | `52.18% <100%> (ø)` | :arrow_up: |
| [pandas/core/arrays/datetimes.py](https://codecov.io/gh/pandas-dev/pandas/pull/24038/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvYXJyYXlzL2RhdGV0aW1lcy5weQ==) | `63.48% <100%> (ø)` | :arrow_up: |
| [pandas/core/indexes/timedeltas.py](https://codecov.io/gh/pandas-dev/pandas/pull/24038/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy90aW1lZGVsdGFzLnB5) | `39.82% <100%> (ø)` | :arrow_up: |
| [pandas/core/arrays/datetimelike.py](https://codecov.io/gh/pandas-dev/pandas/pull/24038/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvYXJyYXlzL2RhdGV0aW1lbGlrZS5weQ==) | `50.53% <41.3%> (-1.25%)` | :arrow_down: |

------

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

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

```diff
@@            Coverage Diff             @@
##           master   #24038      +/-   ##
==========================================
- Coverage   42.46%   42.45%   -0.01%     
==========================================
  Files         161      161              
  Lines       51557    51556       -1     
==========================================
- Hits        21892    21888       -4     
- Misses      29665    29668       +3
```

| Flag | Coverage Δ | |
|---|---|---|
| #single | `42.45% <47.05%> (-0.01%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/24038?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/indexes/period.py](https://codecov.io/gh/pandas-dev/pandas/pull/24038/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9wZXJpb2QucHk=) | `39.82% <100%> (ø)` | :arrow_up: |
| [pandas/core/indexes/datetimelike.py](https://codecov.io/gh/pandas-dev/pandas/pull/24038/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9kYXRldGltZWxpa2UucHk=) | `53.54% <100%> (+1%)` | :arrow_up: |
| [pandas/core/arrays/timedeltas.py](https://codecov.io/gh/pandas-dev/pandas/pull/24038/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvYXJyYXlzL3RpbWVkZWx0YXMucHk=) | `50.28% <100%> (ø)` | :arrow_up: |
| [pandas/core/indexes/datetimes.py](https://codecov.io/gh/pandas-dev/pandas/pull/24038/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9kYXRldGltZXMucHk=) | `52.18% <100%> (ø)` | :arrow_up: |
| [pandas/core/arrays/datetimes.py](https://codecov.io/gh/pandas-dev/pandas/pull/24038/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvYXJyYXlzL2RhdGV0aW1lcy5weQ==) | `63.48% <100%> (ø)` | :arrow_up: |
| [pandas/core/indexes/timedeltas.py](https://codecov.io/gh/pandas-dev/pandas/pull/24038/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy90aW1lZGVsdGFzLnB5) | `39.82% <100%> (ø)` | :arrow_up: |
| [pandas/core/arrays/datetimelike.py](https://codecov.io/gh/pandas-dev/pandas/pull/24038/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvYXJyYXlzL2RhdGV0aW1lbGlrZS5weQ==) | `50.43% <40%> (-1.36%)` | :arrow_down: |

------

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

+1 on the scope.  Needs tests for the methods added to DTA/TDA/PA
In response to 
https://github.com/pandas-dev/pandas/pull/24038#pullrequestreview-180544284, 
https://github.com/pandas-dev/pandas/pull/24038#pullrequestreview-180544274, and 
https://github.com/pandas-dev/pandas/pull/24038#pullrequestreview-180544255, nothing has changed here. These classes end up mixed into exactly the same set as before. This is merely to keep the diff at #24024 smaller.

So in response to

> Needs tests for the methods added to DTA/TDA/PA

That can't be done yet (at least I don't see an easy way), until the indexes have been split from the arrays. Things like `_ensure_localized` aren't on the array classes yet. I do that in #24024.
ok with going ahead with this to avoid blocking and making diffs easier. @jbrockmendel 
OK.  I'll see if I can implement tests in a follow-up.
thanks @TomAugspurger