Skip to content

BUG: Different results from Series.replace with compiled regex #35680

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
pLeBlanc93 opened this issue Aug 11, 2020 · 2 comments · Fixed by #35697
Closed
3 tasks done

BUG: Different results from Series.replace with compiled regex #35680

pLeBlanc93 opened this issue Aug 11, 2020 · 2 comments · Fixed by #35697
Labels
Bug Regression Functionality that used to work in a prior pandas version replace replace method Strings String extension data type and string data
Milestone

Comments

@pLeBlanc93
Copy link

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • (optional) I have confirmed this bug exists on the master branch of pandas.


Note: Please read this guide detailing how to provide the necessary information for us to reproduce your bug.

Code Sample, a copy-pastable example

# Your code here
import re
import pandas as pd

print(pd.__version__)

s = pd.Series(['a', 'aa', 'b'])
regex = {'^a$': 1, '^b$': 2, '^aa$': 3}
print(s.replace(regex, regex=True)) 
print(s.replace({re.compile(k): v for k,v in regex.items()}, regex=True))

Problem description

These two .replace calls are equivalent on pandas 1.0.5. They are different on 1.1.0 and master.

1.2.0.dev0+79.g3c87b019b
0    1
1    3
2    2
dtype: int64
0     a
1    aa
2     b
dtype: object


1.0.5
0    1
1    3
2    2
dtype: int64
0    1
1    3
2    2
dtype: int64

Expected Output

Output of pd.show_versions()

INSTALLED VERSIONS

commit : None
python : 3.7.7.final.0
python-bits : 64
OS : Windows
OS-release : 10
machine : AMD64
processor : Intel64 Family 6 Model 63 Stepping 2, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : None.None

pandas : 1.0.5
numpy : 1.19.1
pytz : 2020.1
dateutil : 2.8.1
pip : 20.2.1
setuptools : 49.3.1.post20200810
Cython : 0.29.21
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : None
pandas_datareader: None
bs4 : None
bottleneck : None
fastparquet : None
gcsfs : None
lxml.etree : None
matplotlib : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pytables : None
pytest : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
xlsxwriter : None
numba : None

@pLeBlanc93 pLeBlanc93 added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Aug 11, 2020
@dsaxton dsaxton added the Strings String extension data type and string data label Aug 12, 2020
@dsaxton
Copy link
Member

dsaxton commented Aug 13, 2020

Thanks @pLeBlanc93, looks like this regression was caused by 3cca07c.

cc @chrispe92

@dsaxton dsaxton added Regression Functionality that used to work in a prior pandas version and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Aug 13, 2020
@simonjayhawkins simonjayhawkins added this to the 1.1.1 milestone Aug 13, 2020
@chrispe
Copy link
Contributor

chrispe commented Aug 16, 2020

Thanks @pLeBlanc93, looks like this regression was caused by 3cca07c.

cc @chrispe92

Hi @dsaxton, thanks for picking this up! I unfortunately didn't notice that behaviour change when I modified the regex condition.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Regression Functionality that used to work in a prior pandas version replace replace method Strings String extension data type and string data
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants