Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

BUG: DataFrame.update() raises FutureWarning due to the use of 'where' method #57124

Copy link
Copy link
Open
@Clifford-Yen

Description

@Clifford-Yen
Issue body actions

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
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

davidlatte

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugConditionalsE.g. where, mask, case_whenE.g. where, mask, case_whenDataFrameDataFrame data structureDataFrame data structureDtype ConversionsUnexpected or buggy dtype conversionsUnexpected or buggy dtype conversionsRegressionFunctionality that used to work in a prior pandas versionFunctionality that used to work in a prior pandas version

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.