Skip to content

Commit 59ebd4e

Browse files
authored
REF (string): de-duplicate str_isfoo methods (#59705)
1 parent 197e8db commit 59ebd4e

File tree

3 files changed

+46
-63
lines changed

3 files changed

+46
-63
lines changed

pandas/core/arrays/_arrow_string_mixins.py

+36
Original file line numberDiff line numberDiff line change
@@ -154,3 +154,39 @@ def _str_endswith(self, pat: str | tuple[str, ...], na: Scalar | None = None):
154154
if not isna(na): # pyright: ignore [reportGeneralTypeIssues]
155155
result = result.fill_null(na)
156156
return self._convert_bool_result(result)
157+
158+
def _str_isalnum(self):
159+
result = pc.utf8_is_alnum(self._pa_array)
160+
return self._convert_bool_result(result)
161+
162+
def _str_isalpha(self):
163+
result = pc.utf8_is_alpha(self._pa_array)
164+
return self._convert_bool_result(result)
165+
166+
def _str_isdecimal(self):
167+
result = pc.utf8_is_decimal(self._pa_array)
168+
return self._convert_bool_result(result)
169+
170+
def _str_isdigit(self):
171+
result = pc.utf8_is_digit(self._pa_array)
172+
return self._convert_bool_result(result)
173+
174+
def _str_islower(self):
175+
result = pc.utf8_is_lower(self._pa_array)
176+
return self._convert_bool_result(result)
177+
178+
def _str_isnumeric(self):
179+
result = pc.utf8_is_numeric(self._pa_array)
180+
return self._convert_bool_result(result)
181+
182+
def _str_isspace(self):
183+
result = pc.utf8_is_space(self._pa_array)
184+
return self._convert_bool_result(result)
185+
186+
def _str_istitle(self):
187+
result = pc.utf8_is_title(self._pa_array)
188+
return self._convert_bool_result(result)
189+
190+
def _str_isupper(self):
191+
result = pc.utf8_is_upper(self._pa_array)
192+
return self._convert_bool_result(result)

pandas/core/arrays/arrow/array.py

-27
Original file line numberDiff line numberDiff line change
@@ -2442,33 +2442,6 @@ def _str_slice(
24422442
pc.utf8_slice_codeunits(self._pa_array, start=start, stop=stop, step=step)
24432443
)
24442444

2445-
def _str_isalnum(self) -> Self:
2446-
return type(self)(pc.utf8_is_alnum(self._pa_array))
2447-
2448-
def _str_isalpha(self) -> Self:
2449-
return type(self)(pc.utf8_is_alpha(self._pa_array))
2450-
2451-
def _str_isdecimal(self) -> Self:
2452-
return type(self)(pc.utf8_is_decimal(self._pa_array))
2453-
2454-
def _str_isdigit(self) -> Self:
2455-
return type(self)(pc.utf8_is_digit(self._pa_array))
2456-
2457-
def _str_islower(self) -> Self:
2458-
return type(self)(pc.utf8_is_lower(self._pa_array))
2459-
2460-
def _str_isnumeric(self) -> Self:
2461-
return type(self)(pc.utf8_is_numeric(self._pa_array))
2462-
2463-
def _str_isspace(self) -> Self:
2464-
return type(self)(pc.utf8_is_space(self._pa_array))
2465-
2466-
def _str_istitle(self) -> Self:
2467-
return type(self)(pc.utf8_is_title(self._pa_array))
2468-
2469-
def _str_isupper(self) -> Self:
2470-
return type(self)(pc.utf8_is_upper(self._pa_array))
2471-
24722445
def _str_len(self) -> Self:
24732446
return type(self)(pc.utf8_length(self._pa_array))
24742447

pandas/core/arrays/string_arrow.py

+10-36
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,16 @@ def astype(self, dtype, copy: bool = True):
281281
# ------------------------------------------------------------------------
282282
# String methods interface
283283

284+
_str_isalnum = ArrowStringArrayMixin._str_isalnum
285+
_str_isalpha = ArrowStringArrayMixin._str_isalpha
286+
_str_isdecimal = ArrowStringArrayMixin._str_isdecimal
287+
_str_isdigit = ArrowStringArrayMixin._str_isdigit
288+
_str_islower = ArrowStringArrayMixin._str_islower
289+
_str_isnumeric = ArrowStringArrayMixin._str_isnumeric
290+
_str_isspace = ArrowStringArrayMixin._str_isspace
291+
_str_istitle = ArrowStringArrayMixin._str_istitle
292+
_str_isupper = ArrowStringArrayMixin._str_isupper
293+
284294
_str_map = BaseStringArray._str_map
285295
_str_startswith = ArrowStringArrayMixin._str_startswith
286296
_str_endswith = ArrowStringArrayMixin._str_endswith
@@ -360,42 +370,6 @@ def _str_slice(
360370
pc.utf8_slice_codeunits(self._pa_array, start=start, stop=stop, step=step)
361371
)
362372

363-
def _str_isalnum(self):
364-
result = pc.utf8_is_alnum(self._pa_array)
365-
return self._convert_bool_result(result)
366-
367-
def _str_isalpha(self):
368-
result = pc.utf8_is_alpha(self._pa_array)
369-
return self._convert_bool_result(result)
370-
371-
def _str_isdecimal(self):
372-
result = pc.utf8_is_decimal(self._pa_array)
373-
return self._convert_bool_result(result)
374-
375-
def _str_isdigit(self):
376-
result = pc.utf8_is_digit(self._pa_array)
377-
return self._convert_bool_result(result)
378-
379-
def _str_islower(self):
380-
result = pc.utf8_is_lower(self._pa_array)
381-
return self._convert_bool_result(result)
382-
383-
def _str_isnumeric(self):
384-
result = pc.utf8_is_numeric(self._pa_array)
385-
return self._convert_bool_result(result)
386-
387-
def _str_isspace(self):
388-
result = pc.utf8_is_space(self._pa_array)
389-
return self._convert_bool_result(result)
390-
391-
def _str_istitle(self):
392-
result = pc.utf8_is_title(self._pa_array)
393-
return self._convert_bool_result(result)
394-
395-
def _str_isupper(self):
396-
result = pc.utf8_is_upper(self._pa_array)
397-
return self._convert_bool_result(result)
398-
399373
def _str_len(self):
400374
result = pc.utf8_length(self._pa_array)
401375
return self._convert_int_result(result)

0 commit comments

Comments
 (0)