Skip to content

Commit

Permalink
Revert "DEPR: ExtensionOpsMixin -> OpsMixin (#38142)" (#38158)
Browse files Browse the repository at this point in the history
This reverts commit f65f0d3.
  • Loading branch information
jorisvandenbossche authored Nov 30, 2020
1 parent 93db57e commit 066a16c
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 76 deletions.
1 change: 0 additions & 1 deletion doc/source/whatsnew/v1.2.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,6 @@ Deprecations
- Deprecated :meth:`Index.asi8` for :class:`Index` subclasses other than :class:`.DatetimeIndex`, :class:`.TimedeltaIndex`, and :class:`PeriodIndex` (:issue:`37877`)
- The ``inplace`` parameter of :meth:`Categorical.remove_unused_categories` is deprecated and will be removed in a future version (:issue:`37643`)
- The ``null_counts`` parameter of :meth:`DataFrame.info` is deprecated and replaced by ``show_counts``. It will be removed in a future version (:issue:`37999`)
- :class:`ExtensionOpsMixin` and :class:`ExtensionScalarOpsMixin` are deprecated and will be removed in a future version. Use ``pd.core.arraylike.OpsMixin`` instead (:issue:`37080`)

.. ---------------------------------------------------------------------------
Expand Down
16 changes: 0 additions & 16 deletions pandas/core/arrays/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
Union,
cast,
)
import warnings

import numpy as np

Expand Down Expand Up @@ -1238,21 +1237,6 @@ class ExtensionOpsMixin:
with NumPy arrays.
"""

def __init_subclass__(cls, **kwargs):
# We use __init_subclass__ to handle deprecations
super().__init_subclass__()

if cls.__name__ != "ExtensionScalarOpsMixin":
# We only want to warn for user-defined subclasses,
# and cannot reference ExtensionScalarOpsMixin directly at this point.
warnings.warn(
"ExtensionOpsMixin and ExtensionScalarOpsMixin are deprecated "
"and will be removed in a future version. Use "
"pd.core.arraylike.OpsMixin instead.",
FutureWarning,
stacklevel=2,
)

@classmethod
def _create_arithmetic_method(cls, op):
raise AbstractMethodError(cls)
Expand Down
19 changes: 0 additions & 19 deletions pandas/tests/arrays/test_deprecations.py

This file was deleted.

44 changes: 5 additions & 39 deletions pandas/tests/extension/decimal/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@
import numpy as np

from pandas.core.dtypes.base import ExtensionDtype
from pandas.core.dtypes.cast import maybe_cast_to_extension_array
from pandas.core.dtypes.common import is_dtype_equal, is_list_like, pandas_dtype

import pandas as pd
from pandas.api.extensions import no_default, register_extension_dtype
from pandas.core.arraylike import OpsMixin
from pandas.core.arrays import ExtensionArray
from pandas.core.arrays import ExtensionArray, ExtensionScalarOpsMixin
from pandas.core.indexers import check_array_indexer


Expand Down Expand Up @@ -46,7 +45,7 @@ def _is_numeric(self) -> bool:
return True


class DecimalArray(OpsMixin, ExtensionArray):
class DecimalArray(OpsMixin, ExtensionScalarOpsMixin, ExtensionArray):
__array_priority__ = 1000

def __init__(self, values, dtype=None, copy=False, context=None):
Expand Down Expand Up @@ -226,46 +225,13 @@ def convert_values(param):

return np.asarray(res, dtype=bool)

_do_coerce = True # overriden in DecimalArrayWithoutCoercion

def _arith_method(self, other, op):
def convert_values(param):
if isinstance(param, ExtensionArray) or is_list_like(param):
ovalues = param
else: # Assume its an object
ovalues = [param] * len(self)
return ovalues

lvalues = self
rvalues = convert_values(other)

# If the operator is not defined for the underlying objects,
# a TypeError should be raised
res = [op(a, b) for (a, b) in zip(lvalues, rvalues)]

def _maybe_convert(arr):
if self._do_coerce:
# https://github.com/pandas-dev/pandas/issues/22850
# We catch all regular exceptions here, and fall back
# to an ndarray.
res = maybe_cast_to_extension_array(type(self), arr)
if not isinstance(res, type(self)):
# exception raised in _from_sequence; ensure we have ndarray
res = np.asarray(arr)
else:
res = np.asarray(arr)
return res

if op.__name__ in {"divmod", "rdivmod"}:
a, b = zip(*res)
return _maybe_convert(a), _maybe_convert(b)

return _maybe_convert(res)


def to_decimal(values, context=None):
return DecimalArray([decimal.Decimal(x) for x in values], context=context)


def make_data():
return [decimal.Decimal(random.random()) for _ in range(100)]


DecimalArray._add_arithmetic_ops()
7 changes: 6 additions & 1 deletion pandas/tests/extension/decimal/test_decimal.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,12 @@ def _from_sequence(cls, scalars, dtype=None, copy=False):


class DecimalArrayWithoutCoercion(DecimalArrayWithoutFromSequence):
_do_coerce = False
@classmethod
def _create_arithmetic_method(cls, op):
return cls._create_method(op, coerce_to_dtype=False)


DecimalArrayWithoutCoercion._add_arithmetic_ops()


def test_combine_from_sequence_raises():
Expand Down

0 comments on commit 066a16c

Please sign in to comment.