Skip to content

BUG: pandas copy_on_write mode deprecation warning points to contextlib module #63399

@TomAugspurger

Description

@TomAugspurger

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 warnings

warnings.filterwarnings("once")

with pd.option_context("mode.copy_on_write", True):
    pass

Issue Description

Running this program shows the warning comes from contextlib rather than pandas

/Users/toaugspurger/miniforge3/lib/python3.12/contextlib.py:137: Pandas4Warning: The 'mode.copy_on_write' option is deprecated. Copy-on-Write can no longer be disabled (it is always enabled with pandas >= 3.0), and setting the option has no impact. This option will be removed in pandas 4.0.
  return next(self.gen)

Expected Behavior

The stacklevel should point back to somewhere in pandas (pandas._config.config, maybe). I think the problem with using find_stack_level here. Perhaps subtracting one to get out of the context manager? I'm not too sure.

Installed Versions

Details

INSTALLED VERSIONS

commit : b43b95d
python : 3.12.8
python-bits : 64
OS : Darwin
OS-release : 25.1.0
Version : Darwin Kernel Version 25.1.0: Mon Oct 20 19:34:05 PDT 2025; root:xnu-12377.41.6~2/RELEASE_ARM64_T6041
machine : arm64
processor : arm
byteorder : little
LC_ALL : None
LANG : C.UTF-8
LOCALE : C.UTF-8

pandas : 3.0.0rc0+52.gb43b95d2b4
numpy : 2.5.0.dev0+git20251209.0faa919
dateutil : 2.9.0.post0
pip : None
Cython : None
sphinx : None
IPython : 9.4.0
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : None
bottleneck : None
fastparquet : None
fsspec : 2025.3.2
html5lib : None
hypothesis : 6.136.1
gcsfs : None
jinja2 : 3.1.6
lxml.etree : None
matplotlib : 3.10.3
numba : None
numexpr : None
odfpy : None
openpyxl : None
psycopg2 : None
pymysql : None
pyarrow : 22.0.0
pyiceberg : None
pyreadstat : None
pytest : 8.4.2
python-calamine : None
pytz : 2025.2
pyxlsb : None
s3fs : 2025.7.0
scipy : None
sqlalchemy : 2.0.41
tables : None
tabulate : None
xarray : 2025.9.0
xlrd : None
xlsxwriter : None
zstandard : None
qtpy : None
pyqt5 : None

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugNeeds TriageIssue that has not been reviewed by a pandas team member

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions