Skip to content

BUG: str.fullmatch behavior is not the same for object dtype and string[pyarrow] dtype #61072

Open
@ptth222

Description

@ptth222

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

test_series = pandas.Series(['asdf', 'as'], dtype='string[pyarrow]')
regex = r'((as)|(as))'
regex2 = r'(as)|(as)'

test_series.str.fullmatch(regex)
# False
# True
test_series.str.fullmatch(regex2)
# True
# True

test_series2 = pandas.Series(['asdf', 'as'], dtype=str)

test_series2.str.fullmatch(regex)
# False
# True
test_series2.str.fullmatch(regex2)
# False
# True

Issue Description

As the example shows you can use the same regular expression for the str.fullmatch method when using a str dtype and string[pyarrow] dtype and get different results. This seems to stem from Apache Arrow not having a dedicated fullmatch or match, so the regular expression has to be edited with "^" and "$" characters before being delivered to its search function. There might also be some special handling in Python's fullmatch method with the "|" operator. Long story short, at least some regular expressions delivered to PyArrow need additional surrounding parentheses to get the same fullmatch results as when using Python's fullmatch.

I have submitted #61073 to try and address this.

Expected Behavior

The second set of fullmatch results in the example shows the expected behavior. The str.fullmatch method should behave the same for either dtype.

Installed Versions

INSTALLED VERSIONS

commit : 0691c5c
python : 3.10.5
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.19045
machine : AMD64
processor : Intel64 Family 6 Model 158 Stepping 12, GenuineIntel
byteorder : little
LC_ALL : None
LANG : en
LOCALE : English_United States.1252

pandas : 2.2.3
numpy : 1.24.4
pytz : 2022.1
dateutil : 2.8.2
pip : 25.0.1
Cython : 3.0.11
sphinx : 5.1.1
IPython : 8.21.0
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : None
blosc : None
bottleneck : None
dataframe-api-compat : None
fastparquet : None
fsspec : None
html5lib : 1.1
hypothesis : None
gcsfs : None
jinja2 : None
lxml.etree : 4.9.1
matplotlib : None
numba : None
numexpr : None
odfpy : None
openpyxl : 3.1.4
pandas_gbq : None
psycopg2 : None
pymysql : None
pyarrow : 19.0.1
pyreadstat : None
pytest : None
python-calamine : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : 2.0.9
tables : None
tabulate : 0.9.0
xarray : None
xlrd : None
xlsxwriter : 3.2.0
zstandard : None
tzdata : 2024.1
qtpy : 2.4.1
pyqt5 : None

Activity

added
Needs TriageIssue that has not been reviewed by a pandas team member
on Mar 7, 2025
added a commit that references this issue on Mar 7, 2025
added
StringsString extension data type and string data
Arrowpyarrow functionality
on Mar 7, 2025
removed
Needs TriageIssue that has not been reviewed by a pandas team member
on Mar 7, 2025
Pedro-Santos04

Pedro-Santos04 commented on Mar 14, 2025

@Pedro-Santos04

take

ak47me

ak47me commented on Mar 20, 2025

@ak47me

take

added 9 commits that reference this issue on Mar 23, 2025

Fix pandas-dev#61072: inconsistent fullmatch results with regex alter…

1dc4117

Fix pandas-dev#61072: inconsistent fullmatch results with regex alter…

101ebf5

Fix pandas-dev#61072: inconsistent fullmatch results using PyArrow

c4b4183

Fix pandas-dev#61072: inconsistent fullmatch results using PyArrow

743101a

Fix pandas-dev#61072: inconsistent fullmatch results using PyArrow

a8c0b0c

Fix pandas-dev#61072: different fullmatch results using PyArrow

a6d1d7f

Fix pandas-dev#61072: inconsistent fullmatch results with regex alter…

40b5f54

Fix pandas-dev#61072: inconsistent fullmatch results with regex alter…

d0086b2

Fix pandas-dev#61072: inconsistent fullmatch results with regex alter…

7e06033
added a commit that references this issue on Apr 22, 2025

Fix pandas-dev#61072: inconsistent fullmatch results with regex alter…

c2b768b
added 2 commits that reference this issue on Apr 29, 2025

Fix pandas-dev#61072: inconsistent fullmatch results with regex alter…

5463b28

Fix pandas-dev#61072: Fix regex grouping for PyArrow fullmatch tests

9b917a2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Arrowpyarrow functionalityBugStringsString extension data type and string data

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Participants

    @asishm@ptth222@rhshadrach@ak47me@Pedro-Santos04

    Issue actions

      BUG: str.fullmatch behavior is not the same for object dtype and string[pyarrow] dtype · Issue #61072 · pandas-dev/pandas