Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v2.3.3.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Bug fixes
- Fix bug in :meth:`Series.str.replace` using named capture groups (e.g., ``\g<name>``) with the Arrow-backed dtype would raise an error (:issue:`57636`)
- Fix regression in ``~Series.str.contains``, ``~Series.str.match`` and ``~Series.str.fullmatch``
with a compiled regex and custom flags (:issue:`62240`)
- Fix :meth:`Series.str.fullmatch` not matching patterns with groups correctly for the Arrow-backed string dtype (:issue:`61072`)
- Fix :meth:`Series.str.match` and :meth:`Series.str.fullmatch` not matching patterns with groups correctly for the Arrow-backed string dtype (:issue:`61072`)

.. ---------------------------------------------------------------------------
.. _whatsnew_233.contributors:
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/arrays/_arrow_string_mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ def _str_match(
na: Scalar | lib.NoDefault = lib.no_default,
):
if not pat.startswith("^"):
pat = f"^{pat}"
pat = f"^({pat})"
return self._str_contains(pat, case, flags, na, regex=True)

def _str_fullmatch(
Expand Down
25 changes: 24 additions & 1 deletion pandas/tests/strings/test_find_replace.py
Original file line number Diff line number Diff line change
Expand Up @@ -977,6 +977,30 @@ def test_match_compiled_regex(any_string_dtype):
values.str.match(re.compile("ab"), flags=re.IGNORECASE)


@pytest.mark.parametrize(
"pat, case, exp",
[
["ab", False, [True, False]],
["Ab", True, [False, False]],
["bc", True, [False, False]],
["a[a-z]{1}", False, [True, False]],
["A[a-z]{1}", True, [False, False]],
# https://github.com/pandas-dev/pandas/issues/61072
["(bc)|(ab)", True, [True, False]],
["((bc)|(ab))", True, [True, False]],
],
)
def test_str_match_extra_cases(any_string_dtype, pat, case, exp):
ser = Series(["abc", "Xab"], dtype=any_string_dtype)
result = ser.str.match(pat, case=case)

expected_dtype = (
np.bool_ if is_object_or_nan_string_dtype(any_string_dtype) else "boolean"
)
expected = Series(exp, dtype=expected_dtype)
tm.assert_series_equal(result, expected)


# --------------------------------------------------------------------------------------
# str.fullmatch
# --------------------------------------------------------------------------------------
Expand Down Expand Up @@ -1112,7 +1136,6 @@ def test_str_fullmatch_extra_cases(any_string_dtype, pat, case, na, exp):
expected_dtype = (
"object" if is_object_or_nan_string_dtype(any_string_dtype) else "boolean"
)
expected = Series([True, False, np.nan, False], dtype=expected_dtype)
expected = Series(exp, dtype=expected_dtype)
tm.assert_series_equal(result, expected)

Expand Down
Loading