Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pd.to_timedelta now raise an OverflowError when plot time series data using matplotlib #18322

Closed
liubenyuan opened this issue Nov 16, 2017 · 2 comments
Labels
Duplicate Report Duplicate issue or pull request Timedelta Timedelta data type Visualization plotting

Comments

@liubenyuan
Copy link

Code Sample, a copy-pastable example if possible

# Your code here
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from matplotlib import dates

t = np.arange(10)
ts = pd.datetime(2017, 11, 16) + pd.to_timedelta(t, 's')
df = pd.DataFrame(t, index=ts)

fig, ax = plt.subplots()
ax.plot(df)
# workaround:
# ax.plot(df.index.to_pydatetime(), df)

# format time axis
hfmt = dates.DateFormatter('%m/%d %H:%M')
ax.xaxis.set_major_formatter(hfmt)
fig.autofmt_xdate()
plt.show()

Problem description

Version: pandas-0.21.0

trace:

Traceback (most recent call last):

  File "D:\Anaconda3\lib\site-packages\IPython\core\formatters.py", line 332, in __call__
    return printer(obj)

  File "D:\Anaconda3\lib\site-packages\IPython\core\pylabtools.py", line 237, in <lambda>
    png_formatter.for_type(Figure, lambda fig: print_figure(fig, 'png', **kwargs))

  File "D:\Anaconda3\lib\site-packages\IPython\core\pylabtools.py", line 121, in print_figure
    fig.canvas.print_figure(bytes_io, **kw)

  File "D:\Anaconda3\lib\site-packages\matplotlib\backend_bases.py", line 2208, in print_figure
    **kwargs)

  File "D:\Anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py", line 507, in print_png
    FigureCanvasAgg.draw(self)

  File "D:\Anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py", line 430, in draw
    self.figure.draw(self.renderer)

  File "D:\Anaconda3\lib\site-packages\matplotlib\artist.py", line 55, in draw_wrapper
    return draw(artist, renderer, *args, **kwargs)

  File "D:\Anaconda3\lib\site-packages\matplotlib\figure.py", line 1295, in draw
    renderer, self, artists, self.suppressComposite)

  File "D:\Anaconda3\lib\site-packages\matplotlib\image.py", line 138, in _draw_list_compositing_images
    a.draw(renderer)

  File "D:\Anaconda3\lib\site-packages\matplotlib\artist.py", line 55, in draw_wrapper
    return draw(artist, renderer, *args, **kwargs)

  File "D:\Anaconda3\lib\site-packages\matplotlib\axes\_base.py", line 2399, in draw
    mimage._draw_list_compositing_images(renderer, self, artists)

  File "D:\Anaconda3\lib\site-packages\matplotlib\image.py", line 138, in _draw_list_compositing_images
    a.draw(renderer)

  File "D:\Anaconda3\lib\site-packages\matplotlib\artist.py", line 55, in draw_wrapper
    return draw(artist, renderer, *args, **kwargs)

  File "D:\Anaconda3\lib\site-packages\matplotlib\axis.py", line 1133, in draw
    ticks_to_draw = self._update_ticks(renderer)

  File "D:\Anaconda3\lib\site-packages\matplotlib\axis.py", line 974, in _update_ticks
    tick_tups = list(self.iter_ticks())

  File "D:\Anaconda3\lib\site-packages\matplotlib\axis.py", line 921, in iter_ticks
    for i, val in enumerate(majorLocs)]

  File "D:\Anaconda3\lib\site-packages\matplotlib\axis.py", line 921, in <listcomp>
    for i, val in enumerate(majorLocs)]

  File "D:\Anaconda3\lib\site-packages\matplotlib\dates.py", line 538, in __call__
    dt = num2date(x, self.tz)

  File "D:\Anaconda3\lib\site-packages\matplotlib\dates.py", line 441, in num2date
    return _from_ordinalf(x, tz)

  File "D:\Anaconda3\lib\site-packages\matplotlib\dates.py", line 256, in _from_ordinalf
    dt = datetime.datetime.fromordinal(ix).replace(tzinfo=UTC)

OverflowError: Python int too large to convert to C long

<matplotlib.figure.Figure at 0xebecc88>

Expected Output

Output of pd.show_versions()

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

pandas: 0.21.0
pytest: 3.2.1
pip: 9.0.1
setuptools: 36.5.0.post20170921
Cython: 0.26.1
numpy: 1.13.3
scipy: 1.0.0
pyarrow: None
xarray: 0.9.6
IPython: 6.1.0
sphinx: 1.6.3
patsy: 0.4.1
dateutil: 2.6.1
pytz: 2017.2
blosc: None
bottleneck: 1.2.1
tables: 3.4.2
numexpr: 2.6.2
feather: None
matplotlib: 2.1.0
openpyxl: 2.4.8
xlrd: 1.1.0
xlwt: 1.3.0
xlsxwriter: 1.0.2
lxml: 4.1.0
bs4: 4.6.0
html5lib: 0.999999999
sqlalchemy: 1.1.13
pymysql: None
psycopg2: None
jinja2: 2.9.6
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None

workarounds

using

ax.plot(df.index.to_pydatetime(), df)

instead

ax.plot(df)

This problem does not occur prior to 0.21.0

@sinhrks sinhrks added Bug Regression Functionality that used to work in a prior pandas version Timedelta Timedelta data type Visualization plotting labels Nov 16, 2017
@sinhrks
Copy link
Member

sinhrks commented Nov 16, 2017

xref #18301

@jorisvandenbossche
Copy link
Member

Yes, this is a duplicate of that. See also the explanation in http://pandas-docs.github.io/pandas-docs-travis/whatsnew.html#no-automatic-matplotlib-converters

@jorisvandenbossche jorisvandenbossche added Duplicate Report Duplicate issue or pull request and removed Bug Regression Functionality that used to work in a prior pandas version labels Nov 17, 2017
@jorisvandenbossche jorisvandenbossche added this to the No action milestone Nov 17, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate Report Duplicate issue or pull request Timedelta Timedelta data type Visualization plotting
Projects
None yet
Development

No branches or pull requests

3 participants