Skip to content

Period converted to overflowing Timestamp in DataFrame.to_csv #15982

Closed
@snorfalorpagus

Description

@snorfalorpagus

Code Sample

import pandas
dates = ["1990-01-01", "2000-01-01", "3005-01-01"]
index = pandas.PeriodIndex(dates, freq="D")
df = pandas.DataFrame([4, 5, 6], index=index)
print(df)
df.to_csv("bug.csv")

Problem description

I have some data with dates in the far future (e.g. 4000-01-01). Following the documentation I am using pandas.Period: http://pandas.pydata.org/pandas-docs/stable/timeseries.html#representing-out-of-bounds-spans

This works, until I come to export the dataframe to a CSV (demonstrated in the code above). Printing the dataframe works as expected:

        0

1990-01-01 4
2000-01-01 5
3005-01-01 6

But the CSV files looks like this:

,0
1990-01-01 00:00:00.000000000,4
2000-01-01 00:00:00.000000000,5
1835-11-23 00:50:52.580896768,6

It looks like the Period has been converted to a Timestamp and silently overflowed.

Related to #13346, but I think worth a distinct issue.

Output of pd.show_versions()

INSTALLED VERSIONS ------------------ commit: None python: 3.6.0.final.0 python-bits: 64 OS: Windows OS-release: 7 machine: AMD64 processor: Intel64 Family 6 Model 58 Stepping 9, GenuineIntel byteorder: little LC_ALL: None LANG: None LOCALE: None.None

pandas: 0.19.2
nose: None
pip: 9.0.1
setuptools: 33.1.0.post20170122
Cython: 0.25.2
numpy: 1.11.3
scipy: 0.18.1
statsmodels: 0.8.0
xarray: None
IPython: 5.3.0
sphinx: None
patsy: 0.4.1
dateutil: 2.6.0
pytz: 2016.10
blosc: None
bottleneck: None
tables: 3.3.0
numexpr: 2.6.2
matplotlib: 2.0.0
openpyxl: 2.4.1
xlrd: 1.0.0
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: 0.999
httplib2: None
apiclient: None
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.9.5
boto: 2.46.1
pandas_datareader: None

Metadata

Metadata

Assignees

No one assigned

    Labels

    Dtype ConversionsUnexpected or buggy dtype conversionsIO CSVread_csv, to_csvIO DataIO issues that don't fit into a more specific labelPeriodPeriod data type

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions