Skip to content

REF (string): de-duplicate str_isfoo methods #59705

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions pandas/core/arrays/_arrow_string_mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,39 @@ def _str_endswith(self, pat: str | tuple[str, ...], na: Scalar | None = None):
if not isna(na): # pyright: ignore [reportGeneralTypeIssues]
result = result.fill_null(na)
return self._convert_bool_result(result)

def _str_isalnum(self):
result = pc.utf8_is_alnum(self._pa_array)
return self._convert_bool_result(result)

def _str_isalpha(self):
result = pc.utf8_is_alpha(self._pa_array)
return self._convert_bool_result(result)

def _str_isdecimal(self):
result = pc.utf8_is_decimal(self._pa_array)
return self._convert_bool_result(result)

def _str_isdigit(self):
result = pc.utf8_is_digit(self._pa_array)
return self._convert_bool_result(result)

def _str_islower(self):
result = pc.utf8_is_lower(self._pa_array)
return self._convert_bool_result(result)

def _str_isnumeric(self):
result = pc.utf8_is_numeric(self._pa_array)
return self._convert_bool_result(result)

def _str_isspace(self):
result = pc.utf8_is_space(self._pa_array)
return self._convert_bool_result(result)

def _str_istitle(self):
result = pc.utf8_is_title(self._pa_array)
return self._convert_bool_result(result)

def _str_isupper(self):
result = pc.utf8_is_upper(self._pa_array)
return self._convert_bool_result(result)
27 changes: 0 additions & 27 deletions pandas/core/arrays/arrow/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -2442,33 +2442,6 @@ def _str_slice(
pc.utf8_slice_codeunits(self._pa_array, start=start, stop=stop, step=step)
)

def _str_isalnum(self) -> Self:
return type(self)(pc.utf8_is_alnum(self._pa_array))

def _str_isalpha(self) -> Self:
return type(self)(pc.utf8_is_alpha(self._pa_array))

def _str_isdecimal(self) -> Self:
return type(self)(pc.utf8_is_decimal(self._pa_array))

def _str_isdigit(self) -> Self:
return type(self)(pc.utf8_is_digit(self._pa_array))

def _str_islower(self) -> Self:
return type(self)(pc.utf8_is_lower(self._pa_array))

def _str_isnumeric(self) -> Self:
return type(self)(pc.utf8_is_numeric(self._pa_array))

def _str_isspace(self) -> Self:
return type(self)(pc.utf8_is_space(self._pa_array))

def _str_istitle(self) -> Self:
return type(self)(pc.utf8_is_title(self._pa_array))

def _str_isupper(self) -> Self:
return type(self)(pc.utf8_is_upper(self._pa_array))

def _str_len(self) -> Self:
return type(self)(pc.utf8_length(self._pa_array))

Expand Down
46 changes: 10 additions & 36 deletions pandas/core/arrays/string_arrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,16 @@ def astype(self, dtype, copy: bool = True):
# ------------------------------------------------------------------------
# String methods interface

_str_isalnum = ArrowStringArrayMixin._str_isalnum
_str_isalpha = ArrowStringArrayMixin._str_isalpha
_str_isdecimal = ArrowStringArrayMixin._str_isdecimal
_str_isdigit = ArrowStringArrayMixin._str_isdigit
_str_islower = ArrowStringArrayMixin._str_islower
_str_isnumeric = ArrowStringArrayMixin._str_isnumeric
_str_isspace = ArrowStringArrayMixin._str_isspace
_str_istitle = ArrowStringArrayMixin._str_istitle
_str_isupper = ArrowStringArrayMixin._str_isupper

_str_map = BaseStringArray._str_map
_str_startswith = ArrowStringArrayMixin._str_startswith
_str_endswith = ArrowStringArrayMixin._str_endswith
Expand Down Expand Up @@ -360,42 +370,6 @@ def _str_slice(
pc.utf8_slice_codeunits(self._pa_array, start=start, stop=stop, step=step)
)

def _str_isalnum(self):
result = pc.utf8_is_alnum(self._pa_array)
return self._convert_bool_result(result)

def _str_isalpha(self):
result = pc.utf8_is_alpha(self._pa_array)
return self._convert_bool_result(result)

def _str_isdecimal(self):
result = pc.utf8_is_decimal(self._pa_array)
return self._convert_bool_result(result)

def _str_isdigit(self):
result = pc.utf8_is_digit(self._pa_array)
return self._convert_bool_result(result)

def _str_islower(self):
result = pc.utf8_is_lower(self._pa_array)
return self._convert_bool_result(result)

def _str_isnumeric(self):
result = pc.utf8_is_numeric(self._pa_array)
return self._convert_bool_result(result)

def _str_isspace(self):
result = pc.utf8_is_space(self._pa_array)
return self._convert_bool_result(result)

def _str_istitle(self):
result = pc.utf8_is_title(self._pa_array)
return self._convert_bool_result(result)

def _str_isupper(self):
result = pc.utf8_is_upper(self._pa_array)
return self._convert_bool_result(result)

def _str_len(self):
result = pc.utf8_length(self._pa_array)
return self._convert_int_result(result)
Expand Down
Loading