Skip to content

Commit 0e620ca

Browse files
committed
BUG: Fix Series.str.contains with compiled regex on Arrow string dtype (#61942)
1 parent 4912758 commit 0e620ca

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

doc/source/whatsnew/v2.3.2.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Bug fixes
2626
"string" type in the JSON Table Schema for :class:`StringDtype` columns
2727
(:issue:`61889`)
2828
- Boolean operations (``|``, ``&``, ``^``) with bool-dtype objects on the left and :class:`StringDtype` objects on the right now cast the string to bool, with a deprecation warning (:issue:`60234`)
29+
- Fixed ``Series.str.contains`` with compiled regex on Arrow string dtype, which now correctly delegates to the object-dtype implementation. (:issue:`61942`)
2930

3031
.. ---------------------------------------------------------------------------
3132
.. _whatsnew_232.contributors:

pandas/tests/strings/test_find_replace.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -283,18 +283,17 @@ def test_contains_nan(any_string_dtype):
283283

284284
def test_str_contains_compiled_regex_arrow_dtype(any_string_dtype):
285285
# GH#61942
286+
if any_string_dtype == "string[pyarrow]":
287+
pytest.importorskip("pyarrow")
286288
ser = Series(["foo", "bar", "baz"], dtype=any_string_dtype)
287289
pat = re.compile("ba.")
288290
result = ser.str.contains(pat)
289291
# Determine expected dtype and values
290-
if any_string_dtype == "string[pyarrow]":
291-
expected_dtype = "bool[pyarrow]"
292-
elif any_string_dtype == "string":
293-
expected_dtype = "boolean"
294-
elif any_string_dtype == "str":
295-
expected_dtype = bool
296-
else:
297-
expected_dtype = object
292+
expected_dtype = {
293+
"string[pyarrow]": "bool[pyarrow]",
294+
"string": "boolean",
295+
"str": bool,
296+
}.get(any_string_dtype, object)
298297
expected = Series([False, True, True], dtype=expected_dtype)
299298
assert str(result.dtype) == str(expected.dtype)
300299
tm.assert_series_equal(result, expected)

0 commit comments

Comments
 (0)