BUG: Adjust time values with Period objects in Series.dt.end_time
State: closed

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


Labels:
name: Bug
name: API Design
name: Period
description: Period data type

Comments:
# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/18952?src=pr&el=h1) Report
> Merging [#18952](https://codecov.io/gh/pandas-dev/pandas/pull/18952?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/c272c52a548d4b75d32857d8b33821a3b0b41187?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/18952/graphs/tree.svg?height=150&width=650&token=eZ4WkYLtcO&src=pr)](https://codecov.io/gh/pandas-dev/pandas/pull/18952?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master   #18952      +/-   ##
==========================================
+ Coverage   92.07%   92.07%   +<.01%     
==========================================
  Files         170      170              
  Lines       50688    50693       +5     
==========================================
+ Hits        46671    46676       +5     
  Misses       4017     4017
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.48% <100%> (ø)` | :arrow_up: |
| #single | `42.3% <11.11%> (-0.01%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/18952?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/arrays/datetimes.py](https://codecov.io/gh/pandas-dev/pandas/pull/18952/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvYXJyYXlzL2RhdGV0aW1lcy5weQ==) | `95.44% <ø> (-0.03%)` | :arrow_down: |
| [pandas/tseries/offsets.py](https://codecov.io/gh/pandas-dev/pandas/pull/18952/diff?src=pr&el=tree#diff-cGFuZGFzL3RzZXJpZXMvb2Zmc2V0cy5weQ==) | `97.15% <100%> (ø)` | :arrow_up: |
| [pandas/core/indexes/period.py](https://codecov.io/gh/pandas-dev/pandas/pull/18952/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9wZXJpb2QucHk=) | `93.5% <100%> (+0.1%)` | :arrow_up: |

------

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

Ok I made some updates.

There are still a couple of tests failing that I need to spend some more time on. Some tests in ``tests/test_resample.py`` are failing because of problems with ``asfreq('B', 'ffill')`` or ``asfreq('M', 'ffill')`` but other offset aliases seem to be ok. For example, ``result`` and ``expected`` are no longer equal:
```
In [2]: ts = pd.Series([1.1, 1.2, 1.3, 1.4, 1.5], index=pd.period_range('1/1/1990', freq='W-MON', periods=5))            
    
In [3]: result = ts.resample('B', convention='end').ffill()
In [4]: result
Out[4]:
1990-01-01    1.1
1990-01-02    1.1
1990-01-03    1.1
1990-01-04    1.1
1990-01-05    1.1
1990-01-08    1.2
1990-01-09    1.2
1990-01-10    1.2
1990-01-11    1.2
1990-01-12    1.2
1990-01-15    1.3
1990-01-16    1.3
1990-01-17    1.3
1990-01-18    1.3
1990-01-19    1.3
1990-01-22    1.4
1990-01-23    1.4
1990-01-24    1.4
1990-01-25    1.4
1990-01-26    1.4
1990-01-29    1.5
Freq: B, dtype: float64

In [5]: expected = result.to_timestamp('B', how='end').asfreq('B', 'ffill').to_period()
In [6]: expected
Out[6]:
/Users/paul/Desktop/pandas-reidy-p/pandas/core/indexes/datetimes.py:581: 
UserWarning: Discarding nonzero nanoseconds in conversion
  index = _generate_regular_range(start, end, periods, offset)

1990-01-01    NaN
1990-01-02    1.1
1990-01-03    1.1
1990-01-04    1.1
1990-01-05    1.1
1990-01-08    1.1
1990-01-09    1.2
1990-01-10    1.2
1990-01-11    1.2
1990-01-12    1.2
1990-01-15    1.2
1990-01-16    1.3
1990-01-17    1.3
1990-01-18    1.3
1990-01-19    1.3
1990-01-22    1.3
1990-01-23    1.4
1990-01-24    1.4
1990-01-25    1.4
1990-01-26    1.4
1990-01-29    1.4
Freq: B, dtype: float64
```

I think the reason the two results above are not equal is that ``asfreq`` creates a new DatetimeIndex which then later calls ``to_pydatetime()`` to convert the Timestamps to native Python datetime objects. This leads to a loss of nanosecond precision as shown in the warning. I don't think this loss of precision occurs for ``resample``.
Hello @reidy-p! Thanks for updating the PR.





















Cheers ! There are no PEP8 issues in this Pull Request. :beers: 

##### Comment last updated on July 30, 2018 at 20:08 Hours UTC
cc @jbrockmendel if you'd have a look esp at the B arithmetic ops
LGTM
thanks @reidy-p nice patch!