Skip to content

Commit

Permalink
No need for _object_compat
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrockmendel committed Aug 27, 2024
1 parent 310bf82 commit 08691d4
Showing 1 changed file with 6 additions and 26 deletions.
32 changes: 6 additions & 26 deletions pandas/core/arrays/_arrow_string_mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@


class ArrowStringArrayMixin:
# _object_compat specifies whether we should 1) attempt to match behaviors
# of the object-backed StringDtype and 2) fall back to object-based
# computation for cases that pyarrow does not support natively.
_object_compat = False
_pa_array: Sized

def __init__(self, *args, **kwargs) -> None:
Expand Down Expand Up @@ -110,17 +106,9 @@ def _str_startswith(self, pat: str | tuple[str, ...], na: Scalar | None = None):
result = pc.starts_with(self._pa_array, pattern=pat)
else:
if len(pat) == 0:
if self._object_compat:
# mimic existing behaviour of string extension array
# and python string method
result = pa.array(
np.zeros(len(self._pa_array), dtype=np.bool_),
mask=isna(self._pa_array),
)
else:
# For empty tuple, pd.StringDtype() returns null for missing values
# and false for valid values.
result = pc.if_else(pc.is_null(self._pa_array), None, False)
# For empty tuple we return null for missing values and False
# for valid values.
result = pc.if_else(pc.is_null(self._pa_array), None, False)
else:
result = pc.starts_with(self._pa_array, pattern=pat[0])

Expand All @@ -135,17 +123,9 @@ def _str_endswith(self, pat: str | tuple[str, ...], na: Scalar | None = None):
result = pc.ends_with(self._pa_array, pattern=pat)
else:
if len(pat) == 0:
if self._object_compat:
# mimic existing behaviour of string extension array
# and python string method
result = pa.array(
np.zeros(len(self._pa_array), dtype=np.bool_),
mask=isna(self._pa_array),
)
else:
# For empty tuple, pd.StringDtype() returns null for missing values
# and false for valid values.
result = pc.if_else(pc.is_null(self._pa_array), None, False)
# For empty tuple we return null for missing values and False
# for valid values.
result = pc.if_else(pc.is_null(self._pa_array), None, False)
else:
result = pc.ends_with(self._pa_array, pattern=pat[0])

Expand Down

0 comments on commit 08691d4

Please sign in to comment.