Skip to content

Commit de53f6e

Browse files
jbrockmendeljreback
authored andcommitted
remove unnecessary validate_for_numeric_binop (#27886)
1 parent e47362a commit de53f6e

File tree

2 files changed

+3
-48
lines changed

2 files changed

+3
-48
lines changed

pandas/core/indexes/base.py

+1-47
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from datetime import datetime, timedelta
1+
from datetime import datetime
22
import operator
33
from textwrap import dedent
44
from typing import Union
@@ -50,7 +50,6 @@
5050
from pandas.core.dtypes.generic import (
5151
ABCCategorical,
5252
ABCDataFrame,
53-
ABCDateOffset,
5453
ABCDatetimeArray,
5554
ABCDatetimeIndex,
5655
ABCIndexClass,
@@ -5352,51 +5351,6 @@ def _validate_for_numeric_unaryop(self, op, opstr):
53525351
"{opstr} for type: {typ}".format(opstr=opstr, typ=type(self).__name__)
53535352
)
53545353

5355-
def _validate_for_numeric_binop(self, other, op):
5356-
"""
5357-
Return valid other; evaluate or raise TypeError if we are not of
5358-
the appropriate type.
5359-
5360-
Notes
5361-
-----
5362-
This is an internal method called by ops.
5363-
"""
5364-
opstr = "__{opname}__".format(opname=op.__name__)
5365-
# if we are an inheritor of numeric,
5366-
# but not actually numeric (e.g. DatetimeIndex/PeriodIndex)
5367-
if not self._is_numeric_dtype:
5368-
raise TypeError(
5369-
"cannot evaluate a numeric op {opstr} "
5370-
"for type: {typ}".format(opstr=opstr, typ=type(self).__name__)
5371-
)
5372-
5373-
if isinstance(other, Index):
5374-
if not other._is_numeric_dtype:
5375-
raise TypeError(
5376-
"cannot evaluate a numeric op "
5377-
"{opstr} with type: {typ}".format(opstr=opstr, typ=type(other))
5378-
)
5379-
elif isinstance(other, np.ndarray) and not other.ndim:
5380-
other = other.item()
5381-
5382-
if isinstance(other, (Index, ABCSeries, np.ndarray)):
5383-
if len(self) != len(other):
5384-
raise ValueError("cannot evaluate a numeric op with unequal lengths")
5385-
other = com.values_from_object(other)
5386-
if other.dtype.kind not in ["f", "i", "u"]:
5387-
raise TypeError("cannot evaluate a numeric op with a non-numeric dtype")
5388-
elif isinstance(other, (ABCDateOffset, np.timedelta64, timedelta)):
5389-
# higher up to handle
5390-
pass
5391-
elif isinstance(other, (datetime, np.datetime64)):
5392-
# higher up to handle
5393-
pass
5394-
else:
5395-
if not (is_float(other) or is_integer(other)):
5396-
raise TypeError("can only perform ops with scalar values")
5397-
5398-
return other
5399-
54005354
@classmethod
54015355
def _add_numeric_methods_binary(cls):
54025356
"""

pandas/core/indexes/range.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
from pandas.core import ops
2727
import pandas.core.common as com
28+
from pandas.core.construction import extract_array
2829
import pandas.core.indexes.base as ibase
2930
from pandas.core.indexes.base import Index, _index_shared_docs
3031
from pandas.core.indexes.numeric import Int64Index
@@ -782,7 +783,7 @@ def _evaluate_numeric_binop(self, other):
782783
# Must be an np.ndarray; GH#22390
783784
return op(self._int64index, other)
784785

785-
other = self._validate_for_numeric_binop(other, op)
786+
other = extract_array(other, extract_numpy=True)
786787
attrs = self._get_attributes_dict()
787788
attrs = self._maybe_update_attributes(attrs)
788789

0 commit comments

Comments
 (0)