Skip to content

Commit 475b17e

Browse files
committed
REF: de-duplicate ArrowStringArray methods
1 parent d37a010 commit 475b17e

File tree

1 file changed

+3
-20
lines changed

1 file changed

+3
-20
lines changed

pandas/core/arrays/string_arrow.py

+3-20
Original file line numberDiff line numberDiff line change
@@ -360,20 +360,6 @@ def _str_repeat(self, repeats: int | Sequence[int]):
360360
else:
361361
return ArrowExtensionArray._str_repeat(self, repeats=repeats)
362362

363-
def _str_match(
364-
self, pat: str, case: bool = True, flags: int = 0, na: Scalar | None = None
365-
):
366-
if not pat.startswith("^"):
367-
pat = f"^{pat}"
368-
return self._str_contains(pat, case, flags, na, regex=True)
369-
370-
def _str_fullmatch(
371-
self, pat, case: bool = True, flags: int = 0, na: Scalar | None = None
372-
):
373-
if not pat.endswith("$") or pat.endswith("\\$"):
374-
pat = f"{pat}$"
375-
return self._str_match(pat, case, flags, na)
376-
377363
def _str_slice(
378364
self, start: int | None = None, stop: int | None = None, step: int | None = None
379365
) -> Self:
@@ -421,23 +407,20 @@ def _str_len(self):
421407
result = pc.utf8_length(self._pa_array)
422408
return self._convert_int_dtype(result)
423409

410+
_str_match = ArrowExtensionArray._str_match
411+
_str_fullmatch = ArrowExtensionArray._str_fullmatch
424412
_str_lower = ArrowExtensionArray._str_lower
425413
_str_upper = ArrowExtensionArray._str_upper
426414
_str_strip = ArrowExtensionArray._str_strip
427415
_str_lstrip = ArrowExtensionArray._str_lstrip
428416
_str_rstrip = ArrowExtensionArray._str_rstrip
417+
_str_removesuffix = ArrowStringArrayMixin._str_removesuffix
429418

430419
def _str_removeprefix(self, prefix: str):
431420
if not pa_version_under13p0:
432421
return ArrowExtensionArray._str_removeprefix(self, prefix)
433422
return super()._str_removeprefix(prefix)
434423

435-
def _str_removesuffix(self, suffix: str):
436-
ends_with = pc.ends_with(self._pa_array, pattern=suffix)
437-
removed = pc.utf8_slice_codeunits(self._pa_array, 0, stop=-len(suffix))
438-
result = pc.if_else(ends_with, removed, self._pa_array)
439-
return type(self)(result)
440-
441424
def _str_count(self, pat: str, flags: int = 0):
442425
if flags:
443426
return super()._str_count(pat, flags)

0 commit comments

Comments
 (0)