Skip to content

Commit 80458c7

Browse files
jbrockmendelpull[bot]
authored andcommitted
REF/TYP: use OpsMixin for StringArray (#37061)
1 parent e9967d9 commit 80458c7

File tree

1 file changed

+1
-25
lines changed

1 file changed

+1
-25
lines changed

pandas/core/arrays/string_.py

+1-25
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import operator
21
from typing import TYPE_CHECKING, Type, Union
32

43
import numpy as np
@@ -15,7 +14,6 @@
1514
pandas_dtype,
1615
)
1716

18-
from pandas import compat
1917
from pandas.core import ops
2018
from pandas.core.arrays import IntegerArray, PandasArray
2119
from pandas.core.arrays.integer import _IntegerDtype
@@ -344,26 +342,7 @@ def _cmp_method(self, other, op):
344342
result[valid] = op(self._ndarray[valid], other)
345343
return BooleanArray(result, mask)
346344

347-
# Override parent because we have different return types.
348-
@classmethod
349-
def _create_arithmetic_method(cls, op):
350-
# Note: this handles both arithmetic and comparison methods.
351-
352-
assert op.__name__ in ops.ARITHMETIC_BINOPS | ops.COMPARISON_BINOPS
353-
354-
@ops.unpack_zerodim_and_defer(op.__name__)
355-
def method(self, other):
356-
return self._cmp_method(other, op)
357-
358-
return compat.set_function_name(method, f"__{op.__name__}__", cls)
359-
360-
@classmethod
361-
def _add_arithmetic_ops(cls):
362-
cls.__add__ = cls._create_arithmetic_method(operator.add)
363-
cls.__radd__ = cls._create_arithmetic_method(ops.radd)
364-
365-
cls.__mul__ = cls._create_arithmetic_method(operator.mul)
366-
cls.__rmul__ = cls._create_arithmetic_method(ops.rmul)
345+
_arith_method = _cmp_method
367346

368347
# ------------------------------------------------------------------------
369348
# String methods interface
@@ -417,6 +396,3 @@ def _str_map(self, f, na_value=None, dtype=None):
417396
# or .findall returns a list).
418397
# -> We don't know the result type. E.g. `.get` can return anything.
419398
return lib.map_infer_mask(arr, f, mask.view("uint8"))
420-
421-
422-
StringArray._add_arithmetic_ops()

0 commit comments

Comments
 (0)