Skip to content

Commit 6768fb1

Browse files
committed
BUG: Fix Series.str.contains with compiled regex on Arrow string dtype (#61942) and add whatsnew note
1 parent 8e226cd commit 6768fb1

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

pandas/core/arrays/string_arrow.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ def _str_contains(
344344
na=lib.no_default,
345345
regex: bool = True,
346346
):
347-
if (isinstance(pat, re.Pattern) and regex) or flags:
347+
if regex and (isinstance(pat, re.Pattern) or flags):
348348
return super()._str_contains(pat, case, flags, na, regex)
349349

350350
return ArrowStringArrayMixin._str_contains(self, pat, case, flags, na, regex)

pandas/tests/strings/test_strings.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
pytest.importorskip("pyarrow")
1111

1212
from pandas import (
13-
NA,
1413
DataFrame,
1514
Index,
1615
MultiIndex,
@@ -180,13 +179,14 @@ def test_empty_str_methods(any_string_dtype):
180179
tm.assert_series_equal(empty_str, empty.str.translate(table))
181180

182181

183-
def test_str_contains_compiled_regex_arrow():
184-
# GH#61942
185-
ser = Series(["foo", "bar", "baz", None], dtype="string[pyarrow]")
186-
pat = re.compile(r"ba.")
182+
@pytest.mark.parametrize("dtype", ["string[pyarrow]"])
183+
def test_str_contains_compiled_regex_arrow_dtype(dtype):
184+
ser = Series(["foo", "bar", "baz"], dtype=dtype)
185+
pat = re.compile("ba.")
187186
result = ser.str.contains(pat)
188-
expected = Series([False, True, True, NA], dtype="boolean[pyarrow]")
189-
tm.assert_series_equal(result, expected)
187+
assert str(result.dtype) == "bool[pyarrow]"
188+
expected = Series([False, True, True], dtype="bool[pyarrow]")
189+
tm.testing.assert_series_equal(result, expected)
190190

191191

192192
@pytest.mark.parametrize(

0 commit comments

Comments
 (0)