Skip to content

BUG: potential unexpected side-effects of "copy-on-write" in case of multiple imports of pandas #58901

Closed
@jxrossel

Description

@jxrossel

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

Not necessary

Issue Description

If I understand correctly https://pandas.pydata.org/docs/user_guide/copy_on_write.html#copy-on-write-enabling, setting the "copy-on-write" mode through pd.set_option("mode.copy_on_write", True) will activate the mode globally. Am I correct to understand that:

  1. If pandas is imported elsewhere, e.g. in another library on which my library depends, that library will also be affected by this setting, with potentially unpredictable effect on that library outputs?
  2. In the same spirit, if that library also sets this mode, the mode actually used in my code will depend on the import order?

Expected Behavior

If I am correct, would there be a way to at least ensure this mode is not overwritten if it has been explicitly set once? So that if pandas is imported twice with conflicting mode setting, an error is raised

Installed Versions

INSTALLED VERSIONS

commit : d9cdd2e
python : 3.9.13.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.19045
machine : AMD64
processor : Intel64 Family 6 Model 85 Stepping 4, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : French_Switzerland.1252

pandas : 2.2.2
numpy : 1.26.4
pytz : 2024.1
dateutil : 2.9.0.post0
setuptools : None
pip : None
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : 8.18.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 : 0.59.1
numexpr : 2.10.0
odfpy : None
openpyxl : None
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 : None
zstandard : None
tzdata : 2024.1
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