-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: .str.contains()
regex lookbehind and lookahead fail for data type string[pyarrow]
#60833
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
Comments
Thanks for the report! This also fails when |
The Arrow library does not use the Python standard library for regular expressions, but rather re2. It looks like re2 does not support lookahead and lookbehinds, and doesn't really plan on doing so given the time complexity of it. See apache/arrow#40220 and the re2 documentation https://github.com/google/re2/wiki/Syntax |
Thanks @WillAyd - I think the conclusion is therefore that pandas needs to implement something internally to achieve feature parity, would you agree? |
This is probably something worth documenting in the conversion guide. Something to the effect of "for X list of regular expressions, users are advised to do |
Thanks @WillAyd - I am personally of the opinion that documenting differences in behavior here is not sufficient, but do not feel strongly so. |
Looks like we replied at the same time :-) A fallback to the object dtype internally is also an option. The downside to that is it could be a rather expensive operation to go from Arrow -> Python -> Arrow to compute a result. It might be faster to work with object storage in this very specific case, and by forcing end users down that path it helps signal performance implications. Not a strong feeling either way though. There are merits to both approaches |
This is also a good conversation for PDEP-13 #58455 |
I dunno, it appears to me my comment is above yours 😆 Agreed relying on conversion to object is not great, my personal preference would still be to do this rather than require users to do it on their own. This would be a case where #55385 could be useful. |
It should be possible for us to reliably detect if the user is passing a regex using lookbehind and lookahead? (not very familiar here, quick google says that this is with |
Yea - it appears so. I haven't looked at this in detail yet, but the 2nd answer makes me think this might be not so reliable. https://stackoverflow.com/questions/79423223/tell-if-a-python-regex-string-has-a-lookaround I think we'd be okay using |
We can also ensure to put the code doing that in a try/except, so that at least we would not fail this is python would change that private API somehow |
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
Issue Description
.str.contains()
regex lookbehind and lookahead fail for data typestring[pyarrow]
.Expected Behavior
I believe
string[pyarrow]
should produce the same results asstring[python]
andstr
.Installed Versions
INSTALLED VERSIONS
commit : 0691c5c
python : 3.10.16
python-bits : 64
OS : Linux
OS-release : 6.8.0-1020-azure
Version : #23-Ubuntu SMP Mon Dec 9 16:58:58 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.3
numpy : 2.2.2
pytz : 2024.2
dateutil : 2.9.0.post0
pip : 24.2
Cython : None
sphinx : None
IPython : 8.31.0
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : 4.12.3
blosc : None
bottleneck : None
dataframe-api-compat : None
fastparquet : None
fsspec : 2024.12.0
html5lib : None
hypothesis : None
gcsfs : None
jinja2 : 3.1.5
lxml.etree : None
matplotlib : 3.10.0
numba : None
numexpr : None
odfpy : None
openpyxl : 3.1.5
pandas_gbq : None
psycopg2 : None
pymysql : None
pyarrow : 19.0.0
pyreadstat : None
pytest : None
python-calamine : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : 2.0.1
xlsxwriter : None
zstandard : None
tzdata : 2024.2
qtpy : None
pyqt5 : None
The text was updated successfully, but these errors were encountered: