BUG: Implement PeriodEngine to fix PeriodIndex truncate bug
State: closed

- [x] closes #17717
- [x] tests added / passed
- [x] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`
- [x] whatsnew entry


Labels:
name: Bug
name: Indexing
description: Related to indexing on series/frames, not to indexes themselves
name: Period
description: Period data type

Comments:
Does this make sense though? 

Even if it fixes that issue - why should a `PeriodIndex` ever be equal to an `Int64Index`?
@MaximilianR We are already treating Period and int as same.
https://github.com/Licht-T/pandas/blob/a240a734cd33362fb6825fd2ce67163e82f8f9a4/pandas/_libs/period.pyx#L761
@Licht-T no this is *adding* a well-defined value

```
In [2]: pd.Period('2012-02', freq='M') + 2
Out[2]: Period('2012-04', 'M')
```

this is NOT the same thing. We do not treat Periods and integers the same.
@Licht-T if you want to revise to the issue ok
@MaximilianR @jreback Thanks for your comment. I am making another solution.
# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/17755?src=pr&el=h1) Report
> Merging [#17755](https://codecov.io/gh/pandas-dev/pandas/pull/17755?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/97fea48945163ec27349918c14ec9bdca2335460?src=pr&el=desc) will **decrease** coverage by `0.04%`.
> The diff coverage is `n/a`.

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

```diff
@@            Coverage Diff             @@
##           master   #17755      +/-   ##
==========================================
- Coverage   91.25%   91.21%   -0.05%     
==========================================
  Files         163      163              
  Lines       49856    49856              
==========================================
- Hits        45496    45475      -21     
- Misses       4360     4381      +21
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `89.01% <ø> (-0.03%)` | :arrow_down: |
| #single | `40.25% <ø> (-0.07%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/17755?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/io/gbq.py](https://codecov.io/gh/pandas-dev/pandas/pull/17755?src=pr&el=tree#diff-cGFuZGFzL2lvL2dicS5weQ==) | `25% <0%> (-58.34%)` | :arrow_down: |
| [pandas/plotting/\_converter.py](https://codecov.io/gh/pandas-dev/pandas/pull/17755?src=pr&el=tree#diff-cGFuZGFzL3Bsb3R0aW5nL19jb252ZXJ0ZXIucHk=) | `63.38% <0%> (-1.82%)` | :arrow_down: |
| [pandas/core/frame.py](https://codecov.io/gh/pandas-dev/pandas/pull/17755?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZnJhbWUucHk=) | `97.73% <0%> (-0.1%)` | :arrow_down: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/17755?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/17755?src=pr&el=footer). Last update [97fea48...6255812](https://codecov.io/gh/pandas-dev/pandas/pull/17755?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/17755?src=pr&el=h1) Report
> Merging [#17755](https://codecov.io/gh/pandas-dev/pandas/pull/17755?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/27bbea7ee125f4dc19dca2a7703c9a13ca754f9b?src=pr&el=desc) will **increase** coverage by `<.01%`.
> The diff coverage is `100%`.

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

```diff
@@            Coverage Diff             @@
##           master   #17755      +/-   ##
==========================================
+ Coverage   91.25%   91.26%   +<.01%     
==========================================
  Files         163      163              
  Lines       50120    50123       +3     
==========================================
+ Hits        45737    45744       +7     
+ Misses       4383     4379       -4
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `89.07% <100%> (+0.02%)` | :arrow_up: |
| #single | `40.32% <100%> (-0.06%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/17755?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/indexes/period.py](https://codecov.io/gh/pandas-dev/pandas/pull/17755?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9wZXJpb2QucHk=) | `92.87% <100%> (+0.19%)` | :arrow_up: |
| [pandas/io/gbq.py](https://codecov.io/gh/pandas-dev/pandas/pull/17755?src=pr&el=tree#diff-cGFuZGFzL2lvL2dicS5weQ==) | `25% <0%> (-58.34%)` | :arrow_down: |
| [pandas/core/frame.py](https://codecov.io/gh/pandas-dev/pandas/pull/17755?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZnJhbWUucHk=) | `97.75% <0%> (-0.1%)` | :arrow_down: |
| [pandas/core/reshape/merge.py](https://codecov.io/gh/pandas-dev/pandas/pull/17755?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvcmVzaGFwZS9tZXJnZS5weQ==) | `94.26% <0%> (ø)` | :arrow_up: |
| [pandas/plotting/\_converter.py](https://codecov.io/gh/pandas-dev/pandas/pull/17755?src=pr&el=tree#diff-cGFuZGFzL3Bsb3R0aW5nL19jb252ZXJ0ZXIucHk=) | `65.2% <0%> (+1.81%)` | :arrow_up: |

------

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

@jreback @MaximilianR Now revised. I implemented `PeriodEngine`.
@jreback Thank you! I'll add tests for `PeriodEngine`.
@jreback Added some tests.
Fixed conflicts.
can you rebase
pls add a note for 0.22
@jreback Rebased & added what's new note.
@jreback Almost fixed, except this.
https://github.com/pandas-dev/pandas/pull/17755#discussion_r148865409
@jreback Removed numpy test module.
thanks @Licht-T if you'd like to see what can be simplified in index.pyx from the type hierarchy and/or general refactoring would be welcome.
one more indexer issue
https://travis-ci.org/MacPython/pandas-wheels/jobs/297752871