Skip to content
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

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

Open
3 tasks done
Clifford-Yen opened this issue Jan 29, 2024 · 1 comment
Open
3 tasks done
Labels
Bug Conditionals E.g. where, mask, case_when DataFrame DataFrame data structure Dtype Conversions Unexpected or buggy dtype conversions Regression Functionality that used to work in a prior pandas version
Milestone

Comments

@Clifford-Yen
Copy link

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

@Clifford-Yen Clifford-Yen added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Jan 29, 2024
@rhshadrach
Copy link
Member

rhshadrach commented Feb 1, 2024

Thanks for the report. I haven't checked, but I believe this would be fixed by #55634. I recall that PR being pretty close to being ready, and could be revived. However, I'm not certain that PR would be appropriate for a patch version (it entirely changes the computation), so perhaps this should be handled independently.

@rhshadrach rhshadrach added Regression Functionality that used to work in a prior pandas version Conditionals E.g. where, mask, case_when and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Feb 1, 2024
@rhshadrach rhshadrach added this to the 2.2.1 milestone Feb 1, 2024
@rhshadrach rhshadrach added Dtype Conversions Unexpected or buggy dtype conversions DataFrame DataFrame data structure labels Feb 18, 2024
@lithomas1 lithomas1 modified the milestones: 2.2.1, 2.2.2 Feb 23, 2024
@lithomas1 lithomas1 modified the milestones: 2.2.2, 2.2.3 Apr 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Conditionals E.g. where, mask, case_when DataFrame DataFrame data structure Dtype Conversions Unexpected or buggy dtype conversions Regression Functionality that used to work in a prior pandas version
Projects
None yet
Development

No branches or pull requests

3 participants