Skip to content

Revert "DEPR: ExtensionOpsMixin -> OpsMixin" #38158

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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