Skip to content

BUG: Replace fails after NaN in a Series of string #59499

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
2 of 3 tasks
mhabets opened this issue Aug 13, 2024 · 2 comments
Closed
2 of 3 tasks

BUG: Replace fails after NaN in a Series of string #59499

mhabets opened this issue Aug 13, 2024 · 2 comments
Labels
Bug Needs Triage Issue that has not been reviewed by a pandas team member

Comments

@mhabets
Copy link

mhabets commented Aug 13, 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.options.future.infer_string = True
df = pd.Series(["toto", pd.NA, "titi", "tata"])
df.replace({"tata": "tutu"})

Issue Description

Regex replace fails after the NaN value in a Series of string.
Result :

0    toto
1     NaN
2    titi
3    tata # Expecting: "tutu"

Note :

  1. if NaN is before the value to be replaced like in pd.Series(["toto", "titi", "tata", pd.NA]), it works
  2. df.dropna().replace({"tata": "tutu"}) works as expected

Expected Behavior

0    toto
1     NaN
2    titi
3    tutu

Installed Versions

INSTALLED VERSIONS

commit : d9cdd2e
python : 3.10.14.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.22631
machine : AMD64
processor : Intel64 Family 6 Model 186 Stepping 2, GenuineIntel
byteorder : little
LC_ALL : None
LANG : en
LOCALE : English_United Kingdom.1252

pandas : 2.2.2
numpy : 1.26.3
pytz : 2023.3.post1
dateutil : 2.8.2
setuptools : 69.0.3
pip : 23.3.2
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : 2.9.9
jinja2 : 3.1.3
IPython : 8.20.0
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.9.1
numba : None
numexpr : None
odfpy : None
openpyxl : 3.1.2
pandas_gbq : None
pyarrow : 16.1.0
pyreadstat : None
python-calamine : None
pyxlsb : None
s3fs : None
scipy : 1.11.4
sqlalchemy : 2.0.25
tables : None
tabulate : None
xarray : None
xlrd : 2.0.1
zstandard : None
tzdata : 2023.4
qtpy : None
pyqt5 : None

@mhabets mhabets added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Aug 13, 2024
@mhabets mhabets changed the title BUG: Regex replace fails after NaN in a Series of string BUG: Replace fails after NaN in a Series of string Aug 13, 2024
@asishm
Copy link
Contributor

asishm commented Aug 13, 2024

Thanks for the report. This seems to be a duplicate of #56599 which is fixed on main and will be available in v3.0

@mroeschke
Copy link
Member

Closing as a duplicate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Needs Triage Issue that has not been reviewed by a pandas team member
Projects
None yet
Development

No branches or pull requests

3 participants