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

PERF: groupby on an unsorted index slows to a crawl. works fine if index is sorted. #46527

Closed
3 tasks done
furechan opened this issue Mar 27, 2022 · 0 comments · Fixed by #47234
Closed
3 tasks done

PERF: groupby on an unsorted index slows to a crawl. works fine if index is sorted. #46527

furechan opened this issue Mar 27, 2022 · 0 comments · Fixed by #47234
Labels
Groupby Performance Memory or execution speed performance
Milestone

Comments

@furechan
Copy link

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

import numpy as np
import pandas as pd

nkeys, nrows, ncols = 50, 5000, 10

tickers = ["X%04d" % i for i in range(nkeys)]
columns = ["C%d" % i for i in range(ncols)]
sample = pd.DataFrame(np.zeros((nrows, ncols)), columns=columns)

tickers = tickers[::-1] # to reverse the tickers

data = {t: sample for t in tickers}

rawdata = pd.concat(data, names=["ticker"])
rawdata = rawdata.reset_index().drop(columns="level_1")

indexed = rawdata.set_index('ticker')
indexed.groupby('ticker').apply(lambda x:x)

Installed Versions

INSTALLED VERSIONS

commit : 06d2301
python : 3.8.8.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.22000
machine : AMD64
processor : Intel64 Family 6 Model 158 Stepping 13, GenuineIntel
byteorder : little
LC_ALL : en_US.UTF-8
LANG : en_US.UTF-8
LOCALE : English_United States.1252

pandas : 1.4.1
numpy : 1.20.1
pytz : 2021.1
dateutil : 2.8.1
pip : 21.0.1
setuptools : 52.0.0.post20210125
Cython : 0.29.23
pytest : 6.2.3
hypothesis : None
sphinx : 4.0.1
blosc : None
feather : None
xlsxwriter : 1.3.8
lxml.etree : 4.6.3
html5lib : 1.1
pymysql : 1.0.2
psycopg2 : None
jinja2 : 2.11.3
IPython : 7.22.0
pandas_datareader: 0.10.0
bs4 : 4.9.3
bottleneck : 1.3.2
fastparquet : None
fsspec : 0.9.0
gcsfs : None
matplotlib : 3.3.4
numba : 0.53.1
numexpr : 2.7.3
odfpy : None
openpyxl : 3.0.7
pandas_gbq : None
pyarrow : 7.0.0
pyreadstat : None
pyxlsb : None
s3fs : 0.4.2
scipy : 1.6.2
sqlalchemy : 1.4.7
tables : 3.6.1
tabulate : None
xarray : None
xlrd : 2.0.1
xlwt : 1.3.0
zstandard : None

Prior Performance

When indexed is sorted runs under 100 ms.
When not indexed (ie ticker as column) also runs under 100 ms.

Just remove the following code to check :

tickers = tickers[::-1]

@furechan furechan added Needs Triage Issue that has not been reviewed by a pandas team member Performance Memory or execution speed performance labels Mar 27, 2022
@furechan furechan changed the title groupby on an unsorted index slows to a crawl. works fine if index is sorted. PERF: groupby on an unsorted index slows to a crawl. works fine if index is sorted. Mar 27, 2022
@lukemanley lukemanley added Groupby and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Jun 4, 2022
@jreback jreback added this to the 1.5 milestone Jun 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Groupby Performance Memory or execution speed performance
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants