Skip to content
9 changes: 9 additions & 0 deletions pandas/core/arrays/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,11 @@ class ExtensionOpsMixin(object):
"""
A base class for linking the operators to their dunder names
"""

@classmethod
def _create_arithmetic_method(cls, op):
raise AbstractMethodError(cls)

@classmethod
def _add_arithmetic_ops(cls):
cls.__add__ = cls._create_arithmetic_method(operator.add)
Expand All @@ -657,6 +662,10 @@ def _add_arithmetic_ops(cls):
cls.__divmod__ = cls._create_arithmetic_method(divmod)
cls.__rdivmod__ = cls._create_arithmetic_method(ops.rdivmod)

@classmethod
def _create_comparison_method(cls, op):
raise AbstractMethodError(cls)

@classmethod
def _add_comparison_ops(cls):
cls.__eq__ = cls._create_comparison_method(operator.eq)
Expand Down
19 changes: 4 additions & 15 deletions pandas/tests/series/test_arithmetic.py
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,6 @@ def test_td64series_add_int_series_invalid(self, tdser):
with pytest.raises(TypeError):
tdser + Series([2, 3, 4])

@pytest.mark.xfail(reason='GH#19123 integer interpreted as nanoseconds')
def test_td64series_radd_int_series_invalid(self, tdser):
with pytest.raises(TypeError):
Series([2, 3, 4]) + tdser
Expand All @@ -570,7 +569,6 @@ def test_td64series_sub_int_series_invalid(self, tdser):
with pytest.raises(TypeError):
tdser - Series([2, 3, 4])

@pytest.mark.xfail(reason='GH#19123 integer interpreted as nanoseconds')
def test_td64series_rsub_int_series_invalid(self, tdser):
with pytest.raises(TypeError):
Series([2, 3, 4]) - tdser
Expand Down Expand Up @@ -611,9 +609,7 @@ def test_td64series_add_sub_numeric_scalar_invalid(self, scalar, tdser):
@pytest.mark.parametrize('vector', [
np.array([1, 2, 3]),
pd.Index([1, 2, 3]),
pytest.param(Series([1, 2, 3]),
marks=pytest.mark.xfail(reason='GH#19123 integer '
'interpreted as nanos'))
Series([1, 2, 3])
])
def test_td64series_add_sub_numeric_array_invalid(self, vector,
dtype, tdser):
Expand Down Expand Up @@ -777,10 +773,7 @@ def test_td64series_mul_numeric_array(self, vector, dtype, tdser):
'float64', 'float32', 'float16'])
@pytest.mark.parametrize('vector', [
np.array([20, 30, 40]),
pytest.param(pd.Index([20, 30, 40]),
marks=pytest.mark.xfail(reason='__mul__ raises '
'instead of returning '
'NotImplemented')),
pd.Index([20, 30, 40]),
Series([20, 30, 40])
])
def test_td64series_rmul_numeric_array(self, vector, dtype, tdser):
Expand Down Expand Up @@ -816,12 +809,8 @@ def test_td64series_mul_numeric_scalar(self, one, tdser):

@pytest.mark.parametrize('two', [
2, 2.0,
pytest.param(np.array(2),
marks=pytest.mark.xfail(reason='GH#19011 is_list_like '
'incorrectly True.')),
pytest.param(np.array(2.0),
marks=pytest.mark.xfail(reason='GH#19011 is_list_like '
'incorrectly True.')),
np.array(2),
np.array(2.0),
])
def test_td64series_div_numeric_scalar(self, two, tdser):
# GH#4521
Expand Down
45 changes: 0 additions & 45 deletions pandas/util/_decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,48 +339,3 @@ def make_signature(func):
if spec.keywords:
args.append('**' + spec.keywords)
return args, spec.args


class docstring_wrapper(object):
"""
Decorator to wrap a function and provide
a dynamically evaluated doc-string.

Parameters
----------
func : callable
creator : callable
return the doc-string
default : str, optional
return this doc-string on error
"""
_attrs = ['__module__', '__name__',
'__qualname__', '__annotations__']

def __init__(self, func, creator, default=None):
self.func = func
self.creator = creator
self.default = default
update_wrapper(
self, func, [attr for attr in self._attrs
if hasattr(func, attr)])

def __get__(self, instance, cls=None):

# we are called with a class
if instance is None:
return self

# we want to return the actual passed instance
return types.MethodType(self, instance)

def __call__(self, *args, **kwargs):
return self.func(*args, **kwargs)

@property
def __doc__(self):
try:
return self.creator()
except Exception as exc:
msg = self.default or str(exc)
return msg