Skip to content

Commit 7dccab1

Browse files
committed
move methods to subclass
1 parent 0e69bf6 commit 7dccab1

File tree

2 files changed

+23
-13
lines changed

2 files changed

+23
-13
lines changed

pandas/core/arrays/arrow/array.py

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -734,14 +734,7 @@ def _cmp_method(self, other, op) -> ArrowExtensionArray:
734734
raise NotImplementedError(
735735
f"{op.__name__} not implemented for {type(other)}"
736736
)
737-
result = ArrowExtensionArray(result)
738-
if self.dtype.na_value is np.nan: # type: ignore[comparison-overlap]
739-
# i.e. ArrowStringArray with Numpy Semantics
740-
if op == operator.ne:
741-
return result.to_numpy(np.bool_, na_value=True)
742-
else:
743-
return result.to_numpy(np.bool_, na_value=False)
744-
return result
737+
return ArrowExtensionArray(result)
745738

746739
def _evaluate_op_method(self, other, op, arrow_funcs) -> Self:
747740
pa_type = self._pa_array.type
@@ -1536,11 +1529,7 @@ def value_counts(self, dropna: bool = True) -> Series:
15361529

15371530
index = Index(type(self)(values))
15381531

1539-
result = Series(counts, index=index, name="count", copy=False)
1540-
if self.dtype.na_value is np.nan: # type: ignore[comparison-overlap]
1541-
# i.e. ArrowStringArray with Numpy Semantics
1542-
return Series(counts.to_numpy(), index=index, name="count", copy=False)
1543-
return result
1532+
return Series(counts, index=index, name="count", copy=False)
15441533

15451534
@classmethod
15461535
def _concat_same_type(cls, to_concat) -> Self:

pandas/core/arrays/string_arrow.py

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

3+
import operator
34
import re
45
from typing import (
56
TYPE_CHECKING,
@@ -60,6 +61,8 @@
6061

6162
from pandas.core.dtypes.dtypes import ExtensionDtype
6263

64+
from pandas import Series
65+
6366

6467
ArrowStringScalarOrNAT = Union[str, libmissing.NAType]
6568

@@ -551,6 +554,24 @@ def _rank(
551554
)
552555
)
553556

557+
def value_counts(self, dropna: bool = True) -> Series:
558+
result = super().value_counts(dropna=dropna)
559+
if self.dtype.na_value is np.nan:
560+
res_values = result._values.to_numpy()
561+
return result._constructor(
562+
res_values, index=result.index, name=result.name, copy=False
563+
)
564+
return result
565+
566+
def _cmp_method(self, other, op):
567+
result = super()._cmp_method(other, op)
568+
if self.dtype.na_value is np.nan:
569+
if op == operator.ne:
570+
return result.to_numpy(np.bool_, na_value=True)
571+
else:
572+
return result.to_numpy(np.bool_, na_value=False)
573+
return result
574+
554575

555576
class ArrowStringArrayNumpySemantics(ArrowStringArray):
556577
_na_value = np.nan

0 commit comments

Comments
 (0)