-
-
Notifications
You must be signed in to change notification settings - Fork 17.6k
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: Slow performance of to_dict("records")
#46470
Comments
Thanks for the report, I've confirmed the same behavior on main. It sounds like you may be onto the source of the issue, would be you be interested in submitting a PR to fix @RogerThomas? |
@rhshadrach sure, I'll give it a whirl |
…andas-devgh-46470-slow-performance-of-to-dict
I think this is a bit more complicated. In object dtype columns you can have many values, hence you have to check nevertheless. But you might be able to exclude all numeric columns from the cast |
@phofl i think my pr does basically does that, would you have time to take a look? |
Could you link it here? E.g. setting the closes field when opening the pr |
…andas-devgh-46470-slow-performance-of-to-dict
…andas-devgh-46470-slow-performance-of-to-dict Conflicts:
…andas-devgh-46470-slow-performance-of-to-dict
…andas-devgh-46470-slow-performance-of-to-dict
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
df.to_dict("records")
is slow compared to a purely Python implementation.For example
I get
Seems to spend most of it's time in maybe_box_native. Which probably could be avoided becuase we could determine the dtype of each column once at the start
Installed Versions
INSTALLED VERSIONS
commit : 66e3805
python : 3.7.13.final.0
python-bits : 64
OS : Darwin
OS-release : 20.6.0
Version : Darwin Kernel Version 20.6.0: Mon Aug 30 06:12:21 PDT 2021; root:xnu-7195.141.6~3/RELEASE_X86_64
machine : x86_64
processor : i386
byteorder : little
LC_ALL : None
LANG : en_GB.UTF-8
LOCALE : en_GB.UTF-8
pandas : 1.3.5
numpy : 1.21.1
pytz : 2021.1
dateutil : 2.8.2
pip : 22.0.4
setuptools : 57.0.0
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : 1.3.7
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : 2.9.3 (dt dec pq3 ext lo64)
jinja2 : 3.0.1
IPython : None
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : 2021.07.0
fastparquet : None
gcsfs : None
matplotlib : 3.5.0
numexpr : None
odfpy : None
openpyxl : 3.0.7
pandas_gbq : None
pyarrow : 4.0.1
pyxlsb : None
s3fs : None
scipy : 1.7.0
sqlalchemy : 1.4.32
tables : None
tabulate : 0.8.9
xarray : None
xlrd : 1.1.0
xlwt : None
numba : 0.53.1
Prior Performance
No response
The text was updated successfully, but these errors were encountered: