Skip to content

Commit f618751

Browse files
committed
Move fix into _str_contains of ArrowExtensionArray
1 parent 9f3b34f commit f618751

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

pandas/core/arrays/arrow/array.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2467,6 +2467,36 @@ def _convert_int_result(self, result):
24672467
def _convert_rank_result(self, result):
24682468
return type(self)(result)
24692469

2470+
def _str_contains(self, pat, case=True, flags=0, na=lib.no_default, regex=True):
2471+
import re
2472+
2473+
if isinstance(pat, re.Pattern):
2474+
if flags != 0:
2475+
# fallback to python object implementation
2476+
return BaseStringArrayMethods._str_contains(
2477+
self, pat, case, flags, na, regex
2478+
)
2479+
pat = pat.pattern
2480+
regex = True
2481+
2482+
try:
2483+
if not regex:
2484+
result = pc.match_substring(self._pa_array, pat, ignore_case=not case)
2485+
else:
2486+
result = pc.match_substring_regex(
2487+
self._pa_array, pat, ignore_case=not case, options=None
2488+
)
2489+
return self._convert_bool_result(result, na=na, method_name="contains")
2490+
except (AttributeError, NotImplementedError, pa.ArrowNotImplementedError):
2491+
return BaseStringArrayMethods._str_contains(
2492+
self, pat, case, flags, na, regex
2493+
)
2494+
2495+
def _str_count(self, pat: str, flags: int = 0) -> Self:
2496+
if flags:
2497+
raise NotImplementedError(f"count not implemented with {flags=}")
2498+
return type(self)(pc.count_substring_regex(self._pa_array, pat))
2499+
24702500
def _str_count(self, pat: str, flags: int = 0) -> Self:
24712501
if flags:
24722502
raise NotImplementedError(f"count not implemented with {flags=}")

0 commit comments

Comments
 (0)