Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
BUG: fix empty prefix/suffix handling in pyarrow-backed string methods
  • Loading branch information
vkverma9534 authored Dec 17, 2025
commit f71a75c19080a5335da132a8dc0c1977fc543e71
44 changes: 30 additions & 14 deletions pandas/core/arrays/_arrow_string_mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,21 +202,37 @@ def _str_title(self) -> Self:
def _str_swapcase(self) -> Self:
return self._from_pyarrow_array(pc.utf8_swapcase(self._pa_array))

def _str_removeprefix(self, prefix: str):
if prefix == "":
return self
starts_with = pc.starts_with(self._pa_array, pattern=prefix)
removed = pc.utf8_slice_codeunits(self._pa_array, len(prefix))
result = pc.if_else(starts_with, removed, self._pa_array)
return self._from_pyarrow_array(result)
def _str_removeprefix(self, prefix: str):
if prefix == "":
return self

starts_with = pc.starts_with(self._pa_array, pattern=prefix)
removed = pc.utf8_slice_codeunits(self._pa_array, len(prefix))
result = pc.if_else(
starts_with,
removed,
self._pa_array,
)
return self._from_pyarrow_array(result)


def _str_removesuffix(self, suffix: str):
if suffix == "":
return self

ends_with = pc.ends_with(self._pa_array, pattern=suffix)
removed = pc.utf8_slice_codeunits(
self._pa_array,
0,
stop=-len(suffix),
)
result = pc.if_else(
ends_with,
removed,
self._pa_array,
)
return self._from_pyarrow_array(result)

def _str_removesuffix(self, suffix: str):
if suffix == "":
return self
ends_with = pc.ends_with(self._pa_array, pattern=suffix)
removed = pc.utf8_slice_codeunits(self._pa_array, 0, stop=-len(suffix))
result = pc.if_else(ends_with, removed, self._pa_array)
return self._from_pyarrow_array(result)


def _str_startswith(
Expand Down
Loading