BUG: Don't overflow PeriodIndex in to_csv
State: closed

Don't overflow time-stamp objects if being used as index in `to_csv`.

Closes #15982.

Labels:
name: IO CSV
description: read_csv, to_csv
name: Period
description: Period data type

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

```diff
@@            Coverage Diff             @@
##           master   #15984      +/-   ##
==========================================
+ Coverage      91%      91%   +<.01%     
==========================================
  Files         145      145              
  Lines       49641    49639       -2     
==========================================
  Hits        45175    45175              
+ Misses       4466     4464       -2
```

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

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/15984?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/indexes/base.py](https://codecov.io/gh/pandas-dev/pandas/pull/15984?src=pr&el=tree#diff-cGFuZGFzL2luZGV4ZXMvYmFzZS5weQ==) | `96.09% <ø> (ø)` | :arrow_up: |
| [pandas/formats/format.py](https://codecov.io/gh/pandas-dev/pandas/pull/15984?src=pr&el=tree#diff-cGFuZGFzL2Zvcm1hdHMvZm9ybWF0LnB5) | `95.4% <100%> (+0.05%)` | :arrow_up: |
| [pandas/core/common.py](https://codecov.io/gh/pandas-dev/pandas/pull/15984?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvY29tbW9uLnB5) | `91.03% <0%> (+0.34%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/15984?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/15984?src=pr&el=footer). Last update [f2ed595...5939a24](https://codecov.io/gh/pandas-dev/pandas/pull/15984?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).
can you also tests ``.to_native_types()`` for a PI (and DTI if not already tested). 
> can you also tests .to_native_types() for a PI (and DTI if not already tested).

Slightly outside of the scope of this PR, but I can squeeze that in with another commit.
> Slightly outside of the scope of this PR, but I can squeeze that in with another commit.

Ha, tests are *never* out of scope!
> Ha, tests are never out of scope!

Well, I was focusing `to_csv`, not `to_native_types` :smile:
@jreback , @TomAugspurger : All comments have been addressed, and everything is green.
mostly about putting tests in better places, otherwise lgtm.
@jreback : Build machines running into SSL errors when cloning repository.  `[ci skip]` for now.
Addressed all comments, and everything is green.
thanks @gfyoung !