|
15 | 15 | lib,
|
16 | 16 | missing as libmissing,
|
17 | 17 | )
|
18 |
| -from pandas.compat import pa_version_under7p0 |
| 18 | +from pandas.compat import ( |
| 19 | + pa_version_under7p0, |
| 20 | + pa_version_under13p0, |
| 21 | +) |
19 | 22 | from pandas.util._exceptions import find_stack_level
|
20 | 23 |
|
21 | 24 | from pandas.core.dtypes.common import (
|
@@ -446,6 +449,20 @@ def _str_rstrip(self, to_strip=None):
|
446 | 449 | result = pc.utf8_rtrim(self._pa_array, characters=to_strip)
|
447 | 450 | return type(self)(result)
|
448 | 451 |
|
| 452 | + def _str_removeprefix(self, prefix: str): |
| 453 | + if not pa_version_under13p0: |
| 454 | + starts_with = pc.starts_with(self._pa_array, pattern=prefix) |
| 455 | + removed = pc.utf8_slice_codeunits(self._pa_array, len(prefix)) |
| 456 | + result = pc.if_else(starts_with, removed, self._pa_array) |
| 457 | + return type(self)(result) |
| 458 | + return super()._str_removeprefix(prefix) |
| 459 | + |
| 460 | + def _str_removesuffix(self, suffix: str): |
| 461 | + ends_with = pc.ends_with(self._pa_array, pattern=suffix) |
| 462 | + removed = pc.utf8_slice_codeunits(self._pa_array, 0, stop=-len(suffix)) |
| 463 | + result = pc.if_else(ends_with, removed, self._pa_array) |
| 464 | + return type(self)(result) |
| 465 | + |
449 | 466 | def _str_count(self, pat: str, flags: int = 0):
|
450 | 467 | if flags:
|
451 | 468 | return super()._str_count(pat, flags)
|
|
0 commit comments