Skip to content

Commit 9a526ea

Browse files
authored
Fix for failing cases
1 parent 2ec810d commit 9a526ea

File tree

1 file changed

+4
-22
lines changed

1 file changed

+4
-22
lines changed

pandas/core/arrays/_arrow_string_mixins.py

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -201,40 +201,22 @@ def _str_title(self) -> Self:
201201

202202
def _str_swapcase(self) -> Self:
203203
return self._from_pyarrow_array(pc.utf8_swapcase(self._pa_array))
204-
205204
def _str_removeprefix(self, prefix: str):
206-
if prefix == "":
207-
return self
208-
209205
starts_with = pc.starts_with(self._pa_array, pattern=prefix)
210206
removed = pc.utf8_slice_codeunits(self._pa_array, len(prefix))
211-
result = pc.if_else(
212-
starts_with,
213-
removed,
214-
self._pa_array,
215-
)
207+
result = pc.if_else(starts_with, removed, self._pa_array)
216208
return self._from_pyarrow_array(result)
217209

218210

219211
def _str_removesuffix(self, suffix: str):
220-
if suffix == "":
221-
return self
222-
223212
ends_with = pc.ends_with(self._pa_array, pattern=suffix)
224-
removed = pc.utf8_slice_codeunits(
225-
self._pa_array,
226-
0,
227-
stop=-len(suffix),
228-
)
229-
result = pc.if_else(
230-
ends_with,
231-
removed,
232-
self._pa_array,
233-
)
213+
removed = pc.utf8_slice_codeunits(self._pa_array, 0, stop=-len(suffix))
214+
result = pc.if_else(ends_with, removed, self._pa_array)
234215
return self._from_pyarrow_array(result)
235216

236217

237218

219+
238220
def _str_startswith(
239221
self, pat: str | tuple[str, ...], na: Scalar | lib.NoDefault = lib.no_default
240222
):

0 commit comments

Comments
 (0)