Skip to content

Implement Arrow String Array that is compatible with NumPy semantics #54533

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 24 commits into from
Aug 23, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
12 changes: 6 additions & 6 deletions pandas/core/arrays/string_arrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@ def insert(self, loc: int, item) -> ArrowStringArray:
raise TypeError("Scalar must be NA or str")
return super().insert(loc, item)

@staticmethod
def _result_converter(values, **kwargs):
@classmethod
def _result_converter(cls, values, na=None):
return BooleanDtype().__from_arrow__(values)

def _maybe_convert_setitem_value(self, value):
Expand Down Expand Up @@ -448,15 +448,15 @@ def _str_rstrip(self, to_strip=None):
class ArrowStringArrayNumpySemantics(ArrowStringArray):
_storage = "pyarrow_numpy"

@staticmethod
def _result_converter(values, na=None):
@classmethod
def _result_converter(cls, values, na=None):
if not isna(na):
values = values.fill_null(bool(na))
return ArrowExtensionArray(values).to_numpy(na_value=np.nan)

def __getattribute__(self, item):
# ArrowStringArray and we both inherit from ArrowExtensionArray, which
# creates inheritance problems (Diamnond inheritance)
# creates inheritance problems (Diamond inheritance)
if item in ArrowStringArrayMixin.__dict__ and item != "_pa_array":
return partial(getattr(ArrowStringArrayMixin, item), self)
return super().__getattribute__(item)
Expand Down Expand Up @@ -545,7 +545,7 @@ def _str_find(self, sub: str, start: int = 0, end: int | None = None):

def _cmp_method(self, other, op):
result = super()._cmp_method(other, op)
return result.to_numpy(na_value=False).astype(np.bool_)
return result.to_numpy(np.bool_, na_value=False)

def value_counts(self, dropna: bool = True):
from pandas import Series
Expand Down
5 changes: 4 additions & 1 deletion pandas/tests/strings/test_case_justify.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,10 @@ def test_center_ljust_rjust_mixed_object():

def test_center_ljust_rjust_fillchar(any_string_dtype):
if any_string_dtype == "string[pyarrow_numpy]":
pytest.skip("Arrow logic is different")
pytest.skip(
"Arrow logic is different, "
"see https://github.com/pandas-dev/pandas/pull/54533/files#r1299808126",
)
s = Series(["a", "bb", "cccc", "ddddd", "eeeeee"], dtype=any_string_dtype)

result = s.str.center(5, fillchar="X")
Expand Down