BUG: DataFrame.update() raises FutureWarning due to the use of 'where' method · Issue #57124 · pandas-dev/pandas (original) (raw)

Pandas version checks

Reproducible Example

import pandas as pd from datetime import datetime columns = ['Open', 'High', 'Low', 'Close', 'Volume'] df = pd.DataFrame([[451.5, 458.0, 449.0, 455.5, 1239498]], columns=columns, index=[datetime(2024, 1, 29)]) df2 = pd.DataFrame([[450.5, 457.5, 450.0, 453.5, 1385875], [451.5, 458.0, 449.0, 455.5, 1284000]], columns=columns, index=[datetime(2024, 1, 26), datetime(2024, 1, 29)]) df2.update(df)

Issue Description

Due to the use of 'where' method in DataFrame.update() (self.loc[:, col] = self[col].where(mask, that)), it would raise FutureWarning as follows:

FutureWarning: Downcasting behavior in Series and DataFrame methods 'where', 'mask', and 'clip' is deprecated. In a future version this will not infer object dtypes or cast all-round floats to integers. Instead call result.infer_objects(copy=False) for object inference, or cast round floats explicitly. To opt-in to the future behavior, set pd.set_option('future.no_silent_downcasting', True)

Tried calling result.infer_objects(copy=False), but it's still the same. And all dtypes should be the same between these two DataFrames.

Expected Behavior

FutureWarning shouldn't be raised when using a non-deprecated method.

Installed Versions

INSTALLED VERSIONS

commit : fd3f571
python : 3.11.6.final.0
python-bits : 64
OS : Darwin
OS-release : 23.2.0
Version : Darwin Kernel Version 23.2.0: Wed Nov 15 21:53:34 PST 2023; root:xnu-10002.61.3~2/RELEASE_ARM64_T8103
machine : arm64
processor : arm
byteorder : little
LC_ALL : None
LANG : None
LOCALE : None.UTF-8

pandas : 2.2.0
numpy : 1.26.1
pytz : 2023.3.post1
dateutil : 2.8.2
setuptools : 68.2.2
pip : 23.3.2
Cython : None
pytest : None
hypothesis : None
sphinx : 7.2.6
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.1.2
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.1
numba : None
numexpr : 2.8.7
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 15.0.0
pyreadstat : None
python-calamine : None
pyxlsb : None
s3fs : None
scipy : 1.11.3
sqlalchemy : None
tables : 3.9.2
tabulate : None
xarray : None
xlrd : None
zstandard : None
tzdata : 2023.3
qtpy : None
pyqt5 : None