BUG: combine_first major performance regression · Issue #55845 · pandas-dev/pandas (original) (raw)
Pandas version checks
- I have checked that this issue has not already been reported.
- 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 pandas as pd import numpy as np import time
n = 40_000_000 addr_id2 = pd.Series(np.random.randint(1, high=1000000, size=n, dtype=np.uint32), dtype='UInt32') addr_id1 = addr_id2.copy()
Randomly replace 1% of addr_id1 with NA values (no specific impact of the percentage)
na_indices = np.random.choice(n, size=int(0.01 * n), replace=False) addr_id1.iloc[na_indices] = pd.NA
df = pd.DataFrame({ 'addr_id1': addr_id1, 'addr_id2': addr_id2 })
start = time.time() df["addr_id1"].combine_first(df["addr_id2"]) print(time.time()-start)
Issue Description
In the reproducible example, the combine_first
method takes 0.33s to run on my laptop with pandas 2.0.3, and 17s to runs on pandas 2.1.2
Expected Behavior
I expect combine_first to run as fast in pandas 2.1.2 as in pandas 2.0.3.
In my production code with production dataset, the performance penalty is even higher.
In the reproducible example combine_first
is 52 times slower. On my production dataset with 1B rows,combine_first
usually runs in 70s, but after 2 days of computation, I interrupted it without getting a result.
I can explore more if needed.
Installed Versions
In [17]: pd.show_versions()
INSTALLED VERSIONS
commit : a60ad39
python : 3.11.5.final.0
python-bits : 64
OS : Linux
OS-release : 6.5.6-200.fc38.x86_64
Version : #1 SMP PREEMPT_DYNAMIC Fri Oct 6 19:02:35 UTC 2023
machine : x86_64
processor :
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
pandas : 2.1.2
numpy : 1.24.3
pytz : 2023.3.post1
dateutil : 2.8.2
setuptools : 68.0.0
pip : 23.3
Cython : 3.0.0
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 4.9.3
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.1.2
IPython : 8.15.0
pandas_datareader : 0.10.0
bs4 : 4.12.2
bottleneck : 1.3.5
dataframe-api-compat: None
fastparquet : None
fsspec : 2023.9.2
gcsfs : None
matplotlib : 3.8.0
numba : 0.57.1
numexpr : 2.8.7
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 11.0.0
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : 1.11.3
sqlalchemy : 2.0.21
tables : None
tabulate : 0.8.10
xarray : 2023.6.0
xlrd : None
zstandard : None
tzdata : 2023.3
qtpy : 2.2.0
pyqt5 : None