Skip to content

BUG: replace with 3 or more None values fails when copy_on_write is enabled #59770

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

Closed
3 tasks done
timvink opened this issue Sep 10, 2024 · 2 comments · Fixed by #59807
Closed
3 tasks done

BUG: replace with 3 or more None values fails when copy_on_write is enabled #59770

timvink opened this issue Sep 10, 2024 · 2 comments · Fixed by #59807
Milestone

Comments

@timvink
Copy link

timvink commented Sep 10, 2024

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
pd.DataFrame({'mycol' : ['one','two']}).replace({'mycol': {'<NA>': None, 'null': None, '': None}}) #  all good
pd.options.mode.copy_on_write = True
pd.DataFrame({'mycol' : ['one','two']}).replace({'mycol': {'<NA>': None, 'null': None, '': None}}) # error

Issue Description

When enabling copy_on_write, if you replace dictionary has 3 or more None values, it will return an error.

Interestingly, if you use two, it works:

import pandas as pd
pd.DataFrame({'mycol' : ['one','two']}).replace({'mycol': {'<NA>': None, 'null': None, '': None}}) #  all good
pd.options.mode.copy_on_write = True
pd.DataFrame({'mycol' : ['one','two']}).replace({'mycol': {'<NA>': None, 'null': None, '': None}}) # error
pd.DataFrame({'mycol' : ['one','two']}).replace({'mycol': {'<NA>': None, 'null': None}}) # works

Also, if you use pd.NA instead of None, it also works

Expected Behavior

Normal replacement, just like when copy_on_write is not enabled

Installed Versions

INSTALLED VERSIONS

commit : d9cdd2e
python : 3.10.14.final.0
python-bits : 64
OS : Linux
OS-release : 5.15.0-1064-azure
Version : #73~20.04.1-Ubuntu SMP Mon May 6 09:43:44 UTC 2024
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : C.UTF-8
LOCALE : en_US.UTF-8

pandas : 2.2.2
numpy : 2.1.1
pytz : 2024.1
dateutil : 2.9.0.post0
setuptools : 70.1.1
pip : 24.0
Cython : None
pytest : 8.2.2
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.1.4
IPython : 8.26.0
pandas_datareader : None
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : 4.12.3
bottleneck : None
dataframe-api-compat : None
fastparquet : None
fsspec : 2023.10.0
gcsfs : None
matplotlib : 3.9.2
numba : None
numexpr : None
odfpy : None
openpyxl : 3.1.5
pandas_gbq : None
pyarrow : None
pyreadstat : None
python-calamine : None
pyxlsb : None
s3fs : None
scipy : 1.14.1
sqlalchemy : 2.0.31
tables : None
tabulate : 0.9.0
xarray : None
xlrd : None
zstandard : None
tzdata : 2024.1
qtpy : None
pyqt5 : None

@timvink timvink added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Sep 10, 2024
@rhshadrach rhshadrach added Copy / view semantics replace replace method and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Sep 14, 2024
@rhshadrach
Copy link
Member

Thanks for the report, confirmed on main. This also happens for string[python] and string[pyarrow]. I get the error

ValueError: <weakref at 0x78ca411edda0; to 'NumpyBlock' at 0x78ca411d64b0> is not in list

Further investigations and PRs to fix are welcome!

cc @phofl

@jorisvandenbossche
Copy link
Member

I have a PR to fix this at #59807

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants