pydata/pandas — pull request #7966 by sinhrks (2014-08-08 16:58:44+00:00)
Title: ENH/BUG: Period and PeriodIndex ops supports timedelta-like

Must be revisited after #7954 to remove ``_skip_if_not_numpy17_friendly``

Closes #7740.

Allow ``Period`` and ``PeriodIndex`` ``add`` and ``sub`` to support ``timedelta``-like. If period freq is ``offsets.Tick``, offsets can be added if the result can have same freq. Otherwise, ``ValueError`` will be raised.
```
idx = pd.period_range('2014-07-01 09:00', periods=5, freq='H')
idx + pd.offsets.Hour(2)
#
# [2014-07-01 11:00, ..., 2014-07-01 15:00]
# Length: 5, Freq: H

idx + datetime.timedelta(minutes=120)
#
# [2014-07-01 11:00, ..., 2014-07-01 15:00]
# Length: 5, Freq: H

idx + np.timedelta64(7200, 's')
#
# [2014-07-01 11:00, ..., 2014-07-01 15:00]
# Length: 5, Freq: H

idx + pd.offsets.Minute(5)
# ValueError: Input has different freq from PeriodIndex(freq=H)
```

If period freq isn't ``Tick``, only the same offset can be added. Otherwise, ``ValueError`` will be raised.

```
idx = pd.period_range('2014-07', periods=5, freq='M')
idx + pd.offsets.MonthEnd(3)
#
# [2014-10, ..., 2015-02]
# Length: 5, Freq: M
idx + pd.offsets.MonthBegin(3)
# ValueError: Input has different freq from PeriodIndex(freq=M)
```