Skip to content

PERF: DataFrame.update of pandas version is slower than the older version #47392

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

Closed
2 tasks done
warm200 opened this issue Jun 16, 2022 · 2 comments
Closed
2 tasks done
Labels
Duplicate Report Duplicate issue or pull request Indexing Related to indexing on series/frames, not to indexes themselves Performance Memory or execution speed performance

Comments

@warm200
Copy link

warm200 commented Jun 16, 2022

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.

Reproducible Example

import pandas as pd
from time import time

data = {}
for i in range(0, 10000):
    data[i] = [100] * 100

 

new_data = {}
for i in range(2000):
    new_data[i] = [1000] * 100

df = pd.DataFrame(data)
new_df = pd.DataFrame(new_data)

 
start = time()
df.update(new_df)
end = time()
print("DataFrame took: ", end - start)

Installed Versions

for latest version:

pandas.show_versions()

INSTALLED VERSIONS

commit : 4bfe3d0
python : 3.9.2.final.0
python-bits : 64
OS : Darwin
OS-release : 21.4.0
Version : Darwin Kernel Version 21.4.0: Fri Mar 18 00:45:05 PDT 2022; root:xnu-8020.101.4~15/RELEASE_X86_64
machine : x86_64
processor : i386
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 1.4.2
numpy : 1.22.4
pytz : 2022.1
dateutil : 2.8.2
pip : 20.2.3
setuptools : 49.2.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 : None
pandas_datareader: None
bs4 : None
bottleneck : None
brotli : None
fastparquet : None
fsspec : None
gcsfs : None
markupsafe : None
matplotlib : None
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
xlwt : None
zstandard : None

for older version 1.1.5

INSTALLED VERSIONS ------------------ commit : b5958ee python : 3.9.2.final.0 python-bits : 64 OS : Darwin OS-release : 21.4.0 Version : Darwin Kernel Version 21.4.0: Fri Mar 18 00:45:05 PDT 2022; root:xnu-8020.101.4~15/RELEASE_X86_64 machine : x86_64 processor : i386 byteorder : little LC_ALL : None LANG : en_US.UTF-8 LOCALE : en_US.UTF-8

pandas : 1.1.5
numpy : 1.22.4
pytz : 2022.1
dateutil : 2.8.2
pip : 20.2.3
setuptools : 49.2.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 : None
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pytables : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : None

Prior Performance

Pandas 1.1.5 result

here is the result from same code example above but run with pandas v1.1.5
1.031 is in seconds.

DataFrame update took:  0.7426297664642334

pandas 1.4.2 result

Here is the result from save code example above but run with pandas v.1.4.2

DataFrame update took:  2.155642032623291

you can see the latest version is almost double in running time than older version.

@warm200 warm200 added Needs Triage Issue that has not been reviewed by a pandas team member Performance Memory or execution speed performance labels Jun 16, 2022
@warm200 warm200 changed the title PERF: DataFrame.update is slower than the older version PERF: DataFrame.update of pandas version is slower than the older version Jun 16, 2022
@phofl
Copy link
Member

phofl commented Jun 16, 2022

Hi, thanks for your report. Update uses setitem under the hood, hence this is a duplicate of #46267

@phofl phofl closed this as completed Jun 16, 2022
@phofl phofl added Duplicate Report Duplicate issue or pull request Indexing Related to indexing on series/frames, not to indexes themselves and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Jun 16, 2022
@warm200
Copy link
Author

warm200 commented Jun 17, 2022

@phofl thanks for redirecting link, I have read everything through and I think this line is cuprit https://github.com/pandas-dev/pandas/blob/main/pandas/core/frame.py#L8003
when I changed it to
self.loc[:, col] = expressions.where(mask, this, that)
the run time is a lot faster. do you think i should report this as a improvement or a bug?
or this is already in the roadmap?

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 Indexing Related to indexing on series/frames, not to indexes themselves Performance Memory or execution speed performance
Projects
None yet
2 participants