Skip to content

Commit 459d655

Browse files
committed
REF: move methods to ArrowStringArray
1 parent c802535 commit 459d655

File tree

2 files changed

+20
-23
lines changed

2 files changed

+20
-23
lines changed

pandas/core/arrays/arrow/array.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -728,7 +728,14 @@ def _cmp_method(self, other, op) -> ArrowExtensionArray:
728728
raise NotImplementedError(
729729
f"{op.__name__} not implemented for {type(other)}"
730730
)
731-
return ArrowExtensionArray(result)
731+
result = ArrowExtensionArray(result)
732+
if self.dtype.na_value is np.nan:
733+
# i.e. ArrowStringArray with Numpy Semantics
734+
if op == operator.ne:
735+
return result.to_numpy(np.bool_, na_value=True)
736+
else:
737+
return result.to_numpy(np.bool_, na_value=False)
738+
return result
732739

733740
def _evaluate_op_method(self, other, op, arrow_funcs) -> Self:
734741
pa_type = self._pa_array.type
@@ -1523,7 +1530,11 @@ def value_counts(self, dropna: bool = True) -> Series:
15231530

15241531
index = Index(type(self)(values))
15251532

1526-
return Series(counts, index=index, name="count", copy=False)
1533+
result = Series(counts, index=index, name="count", copy=False)
1534+
if self.dtype.na_value is np.nan:
1535+
# i.e. ArrowStringArray with Numpy Semantics
1536+
return Series(counts.to_numpy(), index=index, name="count", copy=False)
1537+
return result
15271538

15281539
@classmethod
15291540
def _concat_same_type(cls, to_concat) -> Self:

pandas/core/arrays/string_arrow.py

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from __future__ import annotations
22

3-
from functools import partial
43
import operator
54
import re
65
from typing import (
@@ -63,8 +62,6 @@
6362

6463
from pandas.core.dtypes.dtypes import ExtensionDtype
6564

66-
from pandas import Series
67-
6865

6966
ArrowStringScalarOrNAT = Union[str, libmissing.NAType]
7067

@@ -559,16 +556,13 @@ def _rank(
559556

560557
class ArrowStringArrayNumpySemantics(ArrowStringArray):
561558
_na_value = np.nan
562-
563-
def __getattribute__(self, item):
564-
# ArrowStringArray and we both inherit from ArrowExtensionArray, which
565-
# creates inheritance problems (Diamond inheritance)
566-
if item in ArrowStringArrayMixin.__dict__ and item not in (
567-
"_pa_array",
568-
"__dict__",
569-
):
570-
return partial(getattr(ArrowStringArrayMixin, item), self)
571-
return super().__getattribute__(item)
559+
_str_get = ArrowStringArrayMixin._str_get
560+
_str_removesuffix = ArrowStringArrayMixin._str_removesuffix
561+
_str_capitalize = ArrowStringArrayMixin._str_capitalize
562+
_str_pad = ArrowStringArrayMixin._str_pad
563+
_str_title = ArrowStringArrayMixin._str_title
564+
_str_swapcase = ArrowStringArrayMixin._str_swapcase
565+
_str_slice_replace = ArrowStringArrayMixin._str_slice_replace
572566

573567
def _cmp_method(self, other, op):
574568
try:
@@ -579,11 +573,3 @@ def _cmp_method(self, other, op):
579573
return result.to_numpy(np.bool_, na_value=True)
580574
else:
581575
return result.to_numpy(np.bool_, na_value=False)
582-
583-
def value_counts(self, dropna: bool = True) -> Series:
584-
from pandas import Series
585-
586-
result = super().value_counts(dropna)
587-
return Series(
588-
result._values.to_numpy(), index=result.index, name=result.name, copy=False
589-
)

0 commit comments

Comments
 (0)