|
70 | 70 | from pandas.core.indexes.frozen import FrozenList
|
71 | 71 | import pandas.core.missing as missing
|
72 | 72 | from pandas.core.ops import get_op_result_name, make_invalid_op
|
73 |
| -from pandas.core.ops.missing import dispatch_missing |
74 | 73 | import pandas.core.sorting as sorting
|
75 | 74 | from pandas.core.strings import StringMethods
|
76 | 75 |
|
@@ -144,27 +143,18 @@ def index_arithmetic_method(self, other):
|
144 | 143 | out = op(self, other)
|
145 | 144 | return Index(out, name=self.name)
|
146 | 145 |
|
147 |
| - other = self._validate_for_numeric_binop(other, op) |
148 |
| - |
149 | 146 | # handle time-based others
|
150 | 147 | if isinstance(other, (ABCDateOffset, np.timedelta64, timedelta)):
|
151 | 148 | return self._evaluate_with_timedelta_like(other, op)
|
152 |
| - elif isinstance(other, (datetime, np.datetime64)): |
153 |
| - return self._evaluate_with_datetime_like(other, op) |
154 | 149 |
|
155 |
| - values = self.values |
156 |
| - with np.errstate(all="ignore"): |
157 |
| - result = op(values, other) |
| 150 | + other = self._validate_for_numeric_binop(other, op) |
158 | 151 |
|
159 |
| - result = dispatch_missing(op, values, other, result) |
| 152 | + from pandas import Series |
160 | 153 |
|
161 |
| - attrs = self._get_attributes_dict() |
162 |
| - attrs = self._maybe_update_attributes(attrs) |
163 |
| - if op is divmod: |
164 |
| - result = (Index(result[0], **attrs), Index(result[1], **attrs)) |
165 |
| - else: |
166 |
| - result = Index(result, **attrs) |
167 |
| - return result |
| 154 | + result = op(Series(self), other) |
| 155 | + if isinstance(result, tuple): |
| 156 | + return (Index(result[0]), Index(result[1])) |
| 157 | + return Index(result) |
168 | 158 |
|
169 | 159 | name = "__{name}__".format(name=op.__name__)
|
170 | 160 | # TODO: docstring?
|
@@ -2361,10 +2351,14 @@ def _get_unique_index(self, dropna=False):
|
2361 | 2351 | def __add__(self, other):
|
2362 | 2352 | if isinstance(other, (ABCSeries, ABCDataFrame)):
|
2363 | 2353 | return NotImplemented
|
2364 |
| - return Index(np.array(self) + other) |
| 2354 | + from pandas import Series |
| 2355 | + |
| 2356 | + return Index(Series(self) + other) |
2365 | 2357 |
|
2366 | 2358 | def __radd__(self, other):
|
2367 |
| - return Index(other + np.array(self)) |
| 2359 | + from pandas import Series |
| 2360 | + |
| 2361 | + return Index(other + Series(self)) |
2368 | 2362 |
|
2369 | 2363 | def __iadd__(self, other):
|
2370 | 2364 | # alias for __add__
|
|
0 commit comments