Use ._tshift internally for datetimelike ops
State: closed

In preperation for PeriodArray / DatetimeArray / TimedeltaArray.

Index.shift has a different meaning from ExtensionArray.shift.

- Index.shift pointwise shifts each element by some amount
- ExtensionArray.shift shits the *position* of each value in the array
  padding the end with NA

This is going to get confusing. This PR tries to avoid some of that by
internally using a new `_tshift` method (time-shift) when we want to do pointwise
shifting of each value. Places that know they want that behavior (like in the
datetimelike ops) should use that.

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

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/23e5cfca21fae0a74d867073096b7fb76ab332fe/pandas/core/arrays/datetimelike.py) !

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


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

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

```diff
@@            Coverage Diff             @@
##           master   #22949      +/-   ##
==========================================
+ Coverage   92.18%   92.18%   +<.01%     
==========================================
  Files         169      169              
  Lines       50823    50827       +4     
==========================================
+ Hits        46853    46857       +4     
  Misses       3970     3970
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.6% <88.88%> (ø)` | :arrow_up: |
| #single | `42.36% <22.22%> (ø)` | :arrow_up: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/22949?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/arrays/datetimelike.py](https://codecov.io/gh/pandas-dev/pandas/pull/22949/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvYXJyYXlzL2RhdGV0aW1lbGlrZS5weQ==) | `95.56% <100%> (+0.02%)` | :arrow_up: |
| [pandas/core/arrays/period.py](https://codecov.io/gh/pandas-dev/pandas/pull/22949/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvYXJyYXlzL3BlcmlvZC5weQ==) | `92.04% <80%> (+0.06%)` | :arrow_up: |

------

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

These changes cover the places known to hit PeriodIndex.shift, the places I needed to change on the PeriodArray refactor to get tests passing.

I don't see any uses in Internals, and no other Index classes I'm aware of actually implement `.shift`. Just the datetimelike ones I've updated here.
Renamed to `_time_shift`.

> if you are actually going to change this, then this should be much more consistent across the code base, e.g. does internals need changing, what about the Index classes?

Do you have particular places in mind?
All green.
thanks