pandas
pandas copied to clipboard
BUG: int Overflow with DateFormatter
Pandas version checks
-
[X] I have checked that this issue has not already been reported.
-
[X] I have confirmed this bug exists on the latest version of pandas.
-
[ ] I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
import datetime as dt
from matplotlib import dates
import pandas as pd
dates.set_epoch("2023-01-01") # suggested workaround doesn't help
start = dt.datetime(2022, 4, 4, 7)
end = dt.datetime(2022, 4, 4, 16)
index = pd.date_range(start, end, freq="s")
df = pd.DataFrame(index=index)
df["col"] = 1
ax = df.plot()
ax.xaxis.set_major_formatter(dates.DateFormatter("%H:%M")) # breaks
Issue Description
See also: #18348
When setting a matplotlib.dates.DateFormatter
, I get the following exception:
OverflowError: int too big to convert
Full Traceback:
runfile('/home/lukas/.config/spyder-py3/temp.py', wdir='/home/lukas/.config/spyder-py3')
[autoreload of pandas.core.arrays.timedeltas failed: Traceback (most recent call last):
File "/home/lukas/mambaforge/envs/moma/lib/python3.11/site-packages/IPython/extensions/autoreload.py", line 273, in check
superreload(m, reload, self.old_objects)
File "/home/lukas/mambaforge/envs/moma/lib/python3.11/site-packages/IPython/extensions/autoreload.py", line 471, in superreload
module = reload(module)
^^^^^^^^^^^^^^
File "/home/lukas/mambaforge/envs/moma/lib/python3.11/importlib/__init__.py", line 169, in reload
_bootstrap._exec(spec, module)
File "<frozen importlib._bootstrap>", line 621, in _exec
File "<frozen importlib._bootstrap_external>", line 940, in exec_module
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "/home/lukas/mambaforge/envs/moma/lib/python3.11/site-packages/pandas/core/arrays/timedeltas.py", line 34, in <module>
from pandas._libs.tslibs.fields import (
ImportError: cannot import name 'get_timedelta_days' from 'pandas._libs.tslibs.fields' (/home/lukas/mambaforge/envs/moma/lib/python3.11/site-packages/pandas/_libs/tslibs/fields.cpython-311-x86_64-linux-gnu.so)
]
[autoreload of pandas._testing failed: Traceback (most recent call last):
File "/home/lukas/mambaforge/envs/moma/lib/python3.11/site-packages/IPython/extensions/autoreload.py", line 273, in check
superreload(m, reload, self.old_objects)
File "/home/lukas/mambaforge/envs/moma/lib/python3.11/site-packages/IPython/extensions/autoreload.py", line 471, in superreload
module = reload(module)
^^^^^^^^^^^^^^
File "/home/lukas/mambaforge/envs/moma/lib/python3.11/importlib/__init__.py", line 169, in reload
_bootstrap._exec(spec, module)
File "<frozen importlib._bootstrap>", line 621, in _exec
File "<frozen importlib._bootstrap_external>", line 940, in exec_module
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "/home/lukas/mambaforge/envs/moma/lib/python3.11/site-packages/pandas/_testing/__init__.py", line 914, in <module>
cython_table = pd.core.common._cython_table.items()
^^^^^^^^^^^^^^
AttributeError: module 'pandas.core' has no attribute 'common'
]
Error in callback <function _draw_all_if_interactive at 0x7f4dc0f96020> (for post_execute):
Traceback (most recent call last):
File ~/mambaforge/envs/moma/lib/python3.11/site-packages/matplotlib/pyplot.py:120 in _draw_all_if_interactive
draw_all()
File ~/mambaforge/envs/moma/lib/python3.11/site-packages/matplotlib/_pylab_helpers.py:132 in draw_all
manager.canvas.draw_idle()
File ~/mambaforge/envs/moma/lib/python3.11/site-packages/matplotlib/backend_bases.py:2082 in draw_idle
self.draw(*args, **kwargs)
File ~/mambaforge/envs/moma/lib/python3.11/site-packages/matplotlib/backends/backend_agg.py:400 in draw
self.figure.draw(self.renderer)
File ~/mambaforge/envs/moma/lib/python3.11/site-packages/matplotlib/artist.py:95 in draw_wrapper
result = draw(artist, renderer, *args, **kwargs)
File ~/mambaforge/envs/moma/lib/python3.11/site-packages/matplotlib/artist.py:72 in draw_wrapper
return draw(artist, renderer)
File ~/mambaforge/envs/moma/lib/python3.11/site-packages/matplotlib/figure.py:3140 in draw
mimage._draw_list_compositing_images(
File ~/mambaforge/envs/moma/lib/python3.11/site-packages/matplotlib/image.py:131 in _draw_list_compositing_images
a.draw(renderer)
File ~/mambaforge/envs/moma/lib/python3.11/site-packages/matplotlib/artist.py:72 in draw_wrapper
return draw(artist, renderer)
File ~/mambaforge/envs/moma/lib/python3.11/site-packages/matplotlib/axes/_base.py:3064 in draw
mimage._draw_list_compositing_images(
File ~/mambaforge/envs/moma/lib/python3.11/site-packages/matplotlib/image.py:131 in _draw_list_compositing_images
a.draw(renderer)
File ~/mambaforge/envs/moma/lib/python3.11/site-packages/matplotlib/artist.py:72 in draw_wrapper
return draw(artist, renderer)
File ~/mambaforge/envs/moma/lib/python3.11/site-packages/matplotlib/axis.py:1376 in draw
ticks_to_draw = self._update_ticks()
File ~/mambaforge/envs/moma/lib/python3.11/site-packages/matplotlib/axis.py:1263 in _update_ticks
major_labels = self.major.formatter.format_ticks(major_locs)
File ~/mambaforge/envs/moma/lib/python3.11/site-packages/matplotlib/ticker.py:218 in format_ticks
return [self(value, i) for i, value in enumerate(values)]
File ~/mambaforge/envs/moma/lib/python3.11/site-packages/matplotlib/ticker.py:218 in <listcomp>
return [self(value, i) for i, value in enumerate(values)]
File ~/mambaforge/envs/moma/lib/python3.11/site-packages/matplotlib/dates.py:651 in __call__
result = num2date(x, self.tz).strftime(self.fmt)
File ~/mambaforge/envs/moma/lib/python3.11/site-packages/matplotlib/dates.py:544 in num2date
return _from_ordinalf_np_vectorized(x, tz).tolist()
File ~/mambaforge/envs/moma/lib/python3.11/site-packages/numpy/lib/function_base.py:2329 in __call__
return self._vectorize_call(func=func, args=vargs)
File ~/mambaforge/envs/moma/lib/python3.11/site-packages/numpy/lib/function_base.py:2412 in _vectorize_call
outputs = ufunc(*inputs)
File ~/mambaforge/envs/moma/lib/python3.11/site-packages/matplotlib/dates.py:359 in _from_ordinalf
np.timedelta64(int(np.round(x * MUSECONDS_PER_DAY)), 'us'))
OverflowError: int too big to convert
Traceback (most recent call last):
File ~/mambaforge/envs/moma/lib/python3.11/site-packages/IPython/core/formatters.py:340 in __call__
return printer(obj)
File ~/mambaforge/envs/moma/lib/python3.11/site-packages/IPython/core/pylabtools.py:152 in print_figure
fig.canvas.print_figure(bytes_io, **kw)
File ~/mambaforge/envs/moma/lib/python3.11/site-packages/matplotlib/backend_bases.py:2342 in print_figure
self.figure.draw(renderer)
File ~/mambaforge/envs/moma/lib/python3.11/site-packages/matplotlib/artist.py:95 in draw_wrapper
result = draw(artist, renderer, *args, **kwargs)
File ~/mambaforge/envs/moma/lib/python3.11/site-packages/matplotlib/artist.py:72 in draw_wrapper
return draw(artist, renderer)
File ~/mambaforge/envs/moma/lib/python3.11/site-packages/matplotlib/figure.py:3140 in draw
mimage._draw_list_compositing_images(
File ~/mambaforge/envs/moma/lib/python3.11/site-packages/matplotlib/image.py:131 in _draw_list_compositing_images
a.draw(renderer)
File ~/mambaforge/envs/moma/lib/python3.11/site-packages/matplotlib/artist.py:72 in draw_wrapper
return draw(artist, renderer)
File ~/mambaforge/envs/moma/lib/python3.11/site-packages/matplotlib/axes/_base.py:3064 in draw
mimage._draw_list_compositing_images(
File ~/mambaforge/envs/moma/lib/python3.11/site-packages/matplotlib/image.py:131 in _draw_list_compositing_images
a.draw(renderer)
File ~/mambaforge/envs/moma/lib/python3.11/site-packages/matplotlib/artist.py:72 in draw_wrapper
return draw(artist, renderer)
File ~/mambaforge/envs/moma/lib/python3.11/site-packages/matplotlib/axis.py:1376 in draw
ticks_to_draw = self._update_ticks()
File ~/mambaforge/envs/moma/lib/python3.11/site-packages/matplotlib/axis.py:1263 in _update_ticks
major_labels = self.major.formatter.format_ticks(major_locs)
File ~/mambaforge/envs/moma/lib/python3.11/site-packages/matplotlib/ticker.py:218 in format_ticks
return [self(value, i) for i, value in enumerate(values)]
File ~/mambaforge/envs/moma/lib/python3.11/site-packages/matplotlib/ticker.py:218 in <listcomp>
return [self(value, i) for i, value in enumerate(values)]
File ~/mambaforge/envs/moma/lib/python3.11/site-packages/matplotlib/dates.py:651 in __call__
result = num2date(x, self.tz).strftime(self.fmt)
File ~/mambaforge/envs/moma/lib/python3.11/site-packages/matplotlib/dates.py:544 in num2date
return _from_ordinalf_np_vectorized(x, tz).tolist()
File ~/mambaforge/envs/moma/lib/python3.11/site-packages/numpy/lib/function_base.py:2329 in __call__
return self._vectorize_call(func=func, args=vargs)
File ~/mambaforge/envs/moma/lib/python3.11/site-packages/numpy/lib/function_base.py:2412 in _vectorize_call
outputs = ufunc(*inputs)
File ~/mambaforge/envs/moma/lib/python3.11/site-packages/matplotlib/dates.py:359 in _from_ordinalf
np.timedelta64(int(np.round(x * MUSECONDS_PER_DAY)), 'us'))
OverflowError: int too big to convert
<Figure size 432x288 with 1 Axes>
Expected Behavior
No exceptions are raised, and the major ticks selected by the AutoDateLocator are formatted in hh:mm format.
Installed Versions
INSTALLED VERSIONS
commit : 37ea63d540fd27274cad6585082c91b1283f963d python : 3.11.3.final.0 python-bits : 64 OS : Linux OS-release : 5.4.0-135-generic Version : #152-Ubuntu SMP Wed Nov 23 20:19:22 UTC 2022 machine : x86_64 processor : x86_64 byteorder : little LC_ALL : None LANG : en_US.UTF-8 LOCALE : en_US.UTF-8
pandas : 2.0.1 numpy : 1.24.2 pytz : 2023.3 dateutil : 2.8.2 setuptools : 67.6.1 pip : 23.1 Cython : None pytest : None hypothesis : None sphinx : None blosc : None feather : None xlsxwriter : None lxml.etree : None html5lib : None pymysql : None psycopg2 : None jinja2 : None IPython : 8.12.0 pandas_datareader: None bs4 : None bottleneck : None brotli : None fastparquet : None fsspec : None gcsfs : None matplotlib : 3.7.1 numba : None numexpr : None odfpy : None openpyxl : None pandas_gbq : None pyarrow : None pyreadstat : None pyxlsb : None s3fs : None scipy : None snappy : None sqlalchemy : None tables : None tabulate : None xarray : None xlrd : None zstandard : None tzdata : 2023.3 qtpy : None pyqt5 : None /home/lukas/mambaforge/envs/moma/lib/python3.11/site-packages/_distutils_hack/init.py:33: UserWarning: Setuptools is replacing distutils. warnings.warn("Setuptools is replacing distutils.")