-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
PERF: Slow Series.plot() for DatetimeIndex for pandas 2.2.0 compared to 2.1.4 #57035
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
Comments
I'm seeing the same thing. Plotting a column with DatetimeIndex index is slow vs plotting with integer index. Can verify by dropping the DatetimeIndex before plot via .reset_index(drop=True) |
Here is another example...about 33x slower on my machine (pandas 2.1.4 vs 2.2.1): import time
import pandas as pd
import matplotlib.pyplot as plt
index = pd.date_range('2020-01-01 00:00', periods=500_000, freq='10min')
s1 = pd.Series(data=1, index=index)
t1a = time.time()
s1.plot()
plt.show()
t1z = time.time()
print(f"Time elapsed Series.plot() for pandas {pd.__version__} datetime index: {(t1z-t1a):.2f} seconds")
s2 = s1.reset_index(drop=True)
t2a = time.time()
s2.plot()
plt.show()
t2z = time.time()
print(f"Time elapsed Series.plot() for pandas {pd.__version__} integer index: {(t2z-t2a):.2f} seconds") Output with pandas 2.1.4:
Output with pandas 2.2.1:
|
I've tried to further track this down via profiling, but no luck. Anyone have any ideas? Something changed between 2.1.4 and 2.2.0. |
Pandas version checks
I have checked that this issue has not already been reported.
I have confirmed this issue exists on the latest version of pandas.
I have confirmed this issue exists on the main branch of pandas.
Reproducible Example
Using pandas 2.2.0 I'm experiencing very slow plotting of pd.Series objects with DatetimeIndex. I'm comparing below the time to plot using 2.2.0 and 2.1.4, as well as using matplotlib ax.plot().
Could this be related to the date formatting that pandas applies to the matplotlib axis?
Using an integer index (pd.RangeIndex(start=0, stop=500_000)) does not result in slow Series.plot() with pandas 2.2.0
Related, but not to the possible 2.2.0 regression: #50355
Outputs for pandas 2.2.0:
Installed Versions
Environment with pandas 2.2.0
INSTALLED VERSIONS
commit : f538741
python : 3.11.7.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.19045
machine : AMD64
processor : Intel64 Family 6 Model 186 Stepping 3, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : English_Europe.1252
pandas : 2.2.0
numpy : 1.26.3
pytz : 2023.3.post1
dateutil : 2.8.2
setuptools : 69.0.3
pip : 23.3.2
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 : None
pandas_datareader : None
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : None
bottleneck : None
dataframe-api-compat : None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : 3.8.2
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyreadstat : None
python-calamine : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
zstandard : None
tzdata : 2023.4
qtpy : None
pyqt5 : None
Environment with pandas 2.1.4
pandas : 2.1.4
numpy : 1.26.3
pytz : 2023.3.post1
dateutil : 2.8.2
setuptools : 69.0.3
pip : 23.3.2
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 : None
pandas_datareader : None
bs4 : None
bottleneck : None
dataframe-api-compat: None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : 3.8.2
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
zstandard : None
tzdata : 2023.4
qtpy : None
pyqt5 : None
Prior Performance
Output for pandas 2.1.4:
The text was updated successfully, but these errors were encountered: