Skip to content

Commit 066a16c

Browse files
Revert "DEPR: ExtensionOpsMixin -> OpsMixin (#38142)" (#38158)
This reverts commit f65f0d3.
1 parent 93db57e commit 066a16c

File tree

5 files changed

+11
-76
lines changed

5 files changed

+11
-76
lines changed

doc/source/whatsnew/v1.2.0.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,6 @@ Deprecations
492492
- Deprecated :meth:`Index.asi8` for :class:`Index` subclasses other than :class:`.DatetimeIndex`, :class:`.TimedeltaIndex`, and :class:`PeriodIndex` (:issue:`37877`)
493493
- The ``inplace`` parameter of :meth:`Categorical.remove_unused_categories` is deprecated and will be removed in a future version (:issue:`37643`)
494494
- 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`)
495-
- :class:`ExtensionOpsMixin` and :class:`ExtensionScalarOpsMixin` are deprecated and will be removed in a future version. Use ``pd.core.arraylike.OpsMixin`` instead (:issue:`37080`)
496495

497496
.. ---------------------------------------------------------------------------
498497

pandas/core/arrays/base.py

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
Union,
2222
cast,
2323
)
24-
import warnings
2524

2625
import numpy as np
2726

@@ -1238,21 +1237,6 @@ class ExtensionOpsMixin:
12381237
with NumPy arrays.
12391238
"""
12401239

1241-
def __init_subclass__(cls, **kwargs):
1242-
# We use __init_subclass__ to handle deprecations
1243-
super().__init_subclass__()
1244-
1245-
if cls.__name__ != "ExtensionScalarOpsMixin":
1246-
# We only want to warn for user-defined subclasses,
1247-
# and cannot reference ExtensionScalarOpsMixin directly at this point.
1248-
warnings.warn(
1249-
"ExtensionOpsMixin and ExtensionScalarOpsMixin are deprecated "
1250-
"and will be removed in a future version. Use "
1251-
"pd.core.arraylike.OpsMixin instead.",
1252-
FutureWarning,
1253-
stacklevel=2,
1254-
)
1255-
12561240
@classmethod
12571241
def _create_arithmetic_method(cls, op):
12581242
raise AbstractMethodError(cls)

pandas/tests/arrays/test_deprecations.py

Lines changed: 0 additions & 19 deletions
This file was deleted.

pandas/tests/extension/decimal/array.py

Lines changed: 5 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,12 @@
77
import numpy as np
88

99
from pandas.core.dtypes.base import ExtensionDtype
10-
from pandas.core.dtypes.cast import maybe_cast_to_extension_array
1110
from pandas.core.dtypes.common import is_dtype_equal, is_list_like, pandas_dtype
1211

1312
import pandas as pd
1413
from pandas.api.extensions import no_default, register_extension_dtype
1514
from pandas.core.arraylike import OpsMixin
16-
from pandas.core.arrays import ExtensionArray
15+
from pandas.core.arrays import ExtensionArray, ExtensionScalarOpsMixin
1716
from pandas.core.indexers import check_array_indexer
1817

1918

@@ -46,7 +45,7 @@ def _is_numeric(self) -> bool:
4645
return True
4746

4847

49-
class DecimalArray(OpsMixin, ExtensionArray):
48+
class DecimalArray(OpsMixin, ExtensionScalarOpsMixin, ExtensionArray):
5049
__array_priority__ = 1000
5150

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

227226
return np.asarray(res, dtype=bool)
228227

229-
_do_coerce = True # overriden in DecimalArrayWithoutCoercion
230-
231-
def _arith_method(self, other, op):
232-
def convert_values(param):
233-
if isinstance(param, ExtensionArray) or is_list_like(param):
234-
ovalues = param
235-
else: # Assume its an object
236-
ovalues = [param] * len(self)
237-
return ovalues
238-
239-
lvalues = self
240-
rvalues = convert_values(other)
241-
242-
# If the operator is not defined for the underlying objects,
243-
# a TypeError should be raised
244-
res = [op(a, b) for (a, b) in zip(lvalues, rvalues)]
245-
246-
def _maybe_convert(arr):
247-
if self._do_coerce:
248-
# https://github.com/pandas-dev/pandas/issues/22850
249-
# We catch all regular exceptions here, and fall back
250-
# to an ndarray.
251-
res = maybe_cast_to_extension_array(type(self), arr)
252-
if not isinstance(res, type(self)):
253-
# exception raised in _from_sequence; ensure we have ndarray
254-
res = np.asarray(arr)
255-
else:
256-
res = np.asarray(arr)
257-
return res
258-
259-
if op.__name__ in {"divmod", "rdivmod"}:
260-
a, b = zip(*res)
261-
return _maybe_convert(a), _maybe_convert(b)
262-
263-
return _maybe_convert(res)
264-
265228

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

269232

270233
def make_data():
271234
return [decimal.Decimal(random.random()) for _ in range(100)]
235+
236+
237+
DecimalArray._add_arithmetic_ops()

pandas/tests/extension/decimal/test_decimal.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,12 @@ def _from_sequence(cls, scalars, dtype=None, copy=False):
335335

336336

337337
class DecimalArrayWithoutCoercion(DecimalArrayWithoutFromSequence):
338-
_do_coerce = False
338+
@classmethod
339+
def _create_arithmetic_method(cls, op):
340+
return cls._create_method(op, coerce_to_dtype=False)
341+
342+
343+
DecimalArrayWithoutCoercion._add_arithmetic_ops()
339344

340345

341346
def test_combine_from_sequence_raises():

0 commit comments

Comments
 (0)