Skip to content

Commit fc83d88

Browse files
committed
REF: de-duplicate ArrowStringArray methods
1 parent bd14d21 commit fc83d88

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
@@ -337,20 +337,6 @@ def _str_repeat(self, repeats: int | Sequence[int]):
337337
else:
338338
return ArrowExtensionArray._str_repeat(self, repeats=repeats)
339339

340-
def _str_match(
341-
self, pat: str, case: bool = True, flags: int = 0, na: Scalar | None = None
342-
):
343-
if not pat.startswith("^"):
344-
pat = f"^{pat}"
345-
return self._str_contains(pat, case, flags, na, regex=True)
346-
347-
def _str_fullmatch(
348-
self, pat, case: bool = True, flags: int = 0, na: Scalar | None = None
349-
):
350-
if not pat.endswith("$") or pat.endswith("\\$"):
351-
pat = f"{pat}$"
352-
return self._str_match(pat, case, flags, na)
353-
354340
def _str_slice(
355341
self, start: int | None = None, stop: int | None = None, step: int | None = None
356342
) -> Self:
@@ -362,23 +348,20 @@ def _str_len(self):
362348
result = pc.utf8_length(self._pa_array)
363349
return self._convert_int_result(result)
364350

351+
_str_match = ArrowExtensionArray._str_match
352+
_str_fullmatch = ArrowExtensionArray._str_fullmatch
365353
_str_lower = ArrowExtensionArray._str_lower
366354
_str_upper = ArrowExtensionArray._str_upper
367355
_str_strip = ArrowExtensionArray._str_strip
368356
_str_lstrip = ArrowExtensionArray._str_lstrip
369357
_str_rstrip = ArrowExtensionArray._str_rstrip
358+
_str_removesuffix = ArrowStringArrayMixin._str_removesuffix
370359

371360
def _str_removeprefix(self, prefix: str):
372361
if not pa_version_under13p0:
373362
return ArrowExtensionArray._str_removeprefix(self, prefix)
374363
return super()._str_removeprefix(prefix)
375364

376-
def _str_removesuffix(self, suffix: str):
377-
ends_with = pc.ends_with(self._pa_array, pattern=suffix)
378-
removed = pc.utf8_slice_codeunits(self._pa_array, 0, stop=-len(suffix))
379-
result = pc.if_else(ends_with, removed, self._pa_array)
380-
return type(self)(result)
381-
382365
def _str_count(self, pat: str, flags: int = 0):
383366
if flags:
384367
return super()._str_count(pat, flags)

0 commit comments

Comments
 (0)