Skip to content

BUG: FutureWarning when following documentation #58952

Closed
@matthewsqor

Description

@matthewsqor

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

df.replace({'..': np.nan})
responds with
FutureWarning: Downcasting behavior in `replace` is deprecated and will be removed in a future version. To retain the old behavior, explicitly call `result.infer_objects(copy=False)`. To opt-in to the future behavior, set `pd.set_option('future.no_silent_downcasting', True)`
  df.replace({'..': np.nan})

Issue Description

This is directly copied from the latest Pandas documentation, which supports this type of replace behavior. It should not generate a FutureWarning.

Either this code will be deprecated and the documentation needs to be updated so I know what to do...

Or this code is correct and should not generate a warning.

I do not want any false errors, I want to know when I have an error that it is something I need to investigate.

Expected Behavior

If I directly follow code examples from the latest documentation, I should have no warnings or errors. The documentation should clearly point me to the supported and preferred way to write my code as the first example. The first example should never generate a warning. It makes me worry my code is going to deprecate, and this wastes my time. I have written a lot of code over time, and I do my best to write code as up-to-date as possible to ensure I don't have to revise my code every year because I don't have time for that.

Installed Versions

INSTALLED VERSIONS

commit : d9cdd2e
python : 3.9.13.final.0
python-bits : 64
OS : Darwin
OS-release : 23.5.0
Version : Darwin Kernel Version 23.5.0: Wed May 1 20:19:05 PDT 2024; root:xnu-10063.121.3~5/RELEASE_ARM64_T8112
machine : x86_64
processor : i386
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 2.2.2
numpy : 1.23.5
pytz : 2022.1
dateutil : 2.8.2
setuptools : 63.4.1
pip : 22.2.2
Cython : 0.29.32
pytest : 8.0.2
hypothesis : None
sphinx : 5.0.2
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 4.9.1
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.1.3
IPython : 7.31.1
pandas_datareader : None
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : None
bottleneck : 1.3.8
dataframe-api-compat : None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : None
numba : None
numexpr : 2.10.0
odfpy : None
openpyxl : 3.1.3
pandas_gbq : None
pyarrow : None
pyreadstat : None
python-calamine : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : 2.0.1
zstandard : None
tzdata : 2024.1
qtpy : None
pyqt5 : None

Metadata

Metadata

Assignees

No one assigned

    Labels

    DocsNeeds InfoClarification about behavior needed to assess issuePDEP6-relatedrelated to PDEP6 (not upcasting during setitem-like Series operations)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions