BUG: fix Period.asfreq conversion near datetime(1, 1, 1)
State: closed

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


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

Comments:
Is there a reason you moved the tests?
> Is there a reason you moved the tests?

Ongoing process of centralizing and de-duplicating tests.  The moved tests cover code near the bug being fixed, so it seemed close enough to in-scope.
# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/19650?src=pr&el=h1) Report
> Merging [#19650](https://codecov.io/gh/pandas-dev/pandas/pull/19650?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/740ad9aabda113e34de0d30c78b8aec40414daf7?src=pr&el=desc) will **increase** coverage by `<.01%`.
> The diff coverage is `n/a`.

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

```diff
@@            Coverage Diff             @@
##           master   #19650      +/-   ##
==========================================
+ Coverage   91.61%   91.61%   +<.01%     
==========================================
  Files         150      150              
  Lines       48887    48882       -5     
==========================================
- Hits        44786    44782       -4     
+ Misses       4101     4100       -1
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `89.98% <ø> (ø)` | :arrow_up: |
| #single | `41.79% <ø> (-0.01%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/19650?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/sparse/series.py](https://codecov.io/gh/pandas-dev/pandas/pull/19650/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvc3BhcnNlL3Nlcmllcy5weQ==) | `95.25% <0%> (-0.02%)` | :arrow_down: |
| [pandas/core/sparse/frame.py](https://codecov.io/gh/pandas-dev/pandas/pull/19650/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvc3BhcnNlL2ZyYW1lLnB5) | `94.81% <0%> (ø)` | :arrow_up: |
| [pandas/core/sparse/array.py](https://codecov.io/gh/pandas-dev/pandas/pull/19650/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvc3BhcnNlL2FycmF5LnB5) | `91.46% <0%> (+0.08%)` | :arrow_up: |
| [pandas/core/ops.py](https://codecov.io/gh/pandas-dev/pandas/pull/19650/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvb3BzLnB5) | `96.86% <0%> (+0.12%)` | :arrow_up: |

------

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

It feels you are rather spreading the Period tests to me? This are tests for the public Period class, and tests related to our scalar classes (Timestamp, Period, Timedelta, Interval) are centralized in the `/tests/scalar/` directory. My preference is to keep it that way. 
(I think the tslibs tests are currently tests on functionality contained in tslibs we want to test but is not public?)
lets create ``pandas/tests/scalar/period`` and move these tests to freq.py
re test location: will change.
small comment. ping on green. ok with moving tests in another PR (to a period scalar sub-module) as discussed.
```
The following asvs benchmarks (if any) failed.
[ 43.09%] ··· Running io.excel.Excel.time_read_excel                  1/3 failed
                   xlwt      failed 
```

its possible this actually broke this asv
> its possible this actually broke this asv

Is there a test this corresponds to?
It executes fine locally, will run asv on it to see if the timing is massively changed.
asv runs fine on both 3.5 and 2.7
Thoughts on this?  I assumed the asv concern superseded the "ping on green"
I think all the requests have been hit.
Is there a reason you are adding the test in `/tests/tslibs/test_period_asfreq.py` and not in `tests/scalar/test_period_asfreq.py` ?
> Is there a reason you are adding the test in /tests/tslibs/test_period_asfreq.py and not in tests/scalar/test_period_asfreq.py ?

test.tslibs is intended for testing tslibs _in isolation_.  These asfreq tests are largely for period_helper (or were until recently) and so are self-contained.  This is the right long-term home for these tests.
> test.tslibs is intended for testing tslibs in isolation. 

Yes, and the tests you added are testing behaviour of the Period class (not a private utility of tslib), which for the rest is tested in `tests/scalar/test_period(_asfreq).py` ?
@jorisvandenbossche I asked @jbrockmendel mendel to move these. not quite happy where the scalar tests are ATM, now whether actualy in tslib or the scalar/period is a matter of opinion here. I agree if these are actually user facing then they should be in the scalar/period/....

however as that doesn't exist yet (well in a minute it will), it was a bit confusing.
> however as that doesn't exist yet (well in a minute it will)

`tests/scalar/test_period_asfreq.py` does actually already exist

>  agree if these are actually user facing then they should be in the scalar/period/....

This is the case here

We can reorganize tests, but let's do that in a separate PR, and add the tests here in the location where similar tests already are? (which is AFAIK tests/scalar/test_period_asfreq.py)
@jorisvandenbossche  you will see shortly. the test reorg has been going on for quite a while and is moving in the right direction. 
lgtm. I changed the whatsnew slightly, so needs a rebase. ping on green. can fixup period tests after.
ping
Thanks!