|
26 | 26 |
|
27 | 27 | from pandas.core.dtypes.common import (
|
28 | 28 | is_dtype_equal,
|
29 |
| - is_object_dtype, |
30 | 29 | pandas_dtype,
|
31 | 30 | )
|
32 |
| -from pandas.core.dtypes.generic import ( |
33 |
| - ABCDataFrame, |
34 |
| - ABCSeries, |
35 |
| -) |
| 31 | +from pandas.core.dtypes.generic import ABCDataFrame |
36 | 32 |
|
37 | 33 | from pandas.core.arrays import (
|
38 | 34 | Categorical,
|
|
45 | 41 | from pandas.core.arrays.base import ExtensionArray
|
46 | 42 | from pandas.core.indexers import deprecate_ndim_indexing
|
47 | 43 | from pandas.core.indexes.base import Index
|
48 |
| -from pandas.core.ops import get_op_result_name |
49 | 44 |
|
50 | 45 | if TYPE_CHECKING:
|
51 | 46 |
|
@@ -154,94 +149,6 @@ def wrapper(cls):
|
154 | 149 | return wrapper
|
155 | 150 |
|
156 | 151 |
|
157 |
| -def _make_wrapped_comparison_op(opname: str): |
158 |
| - """ |
159 |
| - Create a comparison method that dispatches to ``._data``. |
160 |
| - """ |
161 |
| - |
162 |
| - def wrapper(self, other): |
163 |
| - if isinstance(other, ABCSeries): |
164 |
| - # the arrays defer to Series for comparison ops but the indexes |
165 |
| - # don't, so we have to unwrap here. |
166 |
| - other = other._values |
167 |
| - |
168 |
| - other = _maybe_unwrap_index(other) |
169 |
| - |
170 |
| - op = getattr(self._data, opname) |
171 |
| - return op(other) |
172 |
| - |
173 |
| - wrapper.__name__ = opname |
174 |
| - return wrapper |
175 |
| - |
176 |
| - |
177 |
| -def _make_wrapped_arith_op(opname: str): |
178 |
| - def method(self, other): |
179 |
| - if ( |
180 |
| - isinstance(other, Index) |
181 |
| - and is_object_dtype(other.dtype) |
182 |
| - and type(other) is not Index |
183 |
| - ): |
184 |
| - # We return NotImplemented for object-dtype index *subclasses* so they have |
185 |
| - # a chance to implement ops before we unwrap them. |
186 |
| - # See https://github.com/pandas-dev/pandas/issues/31109 |
187 |
| - return NotImplemented |
188 |
| - |
189 |
| - try: |
190 |
| - meth = getattr(self._data, opname) |
191 |
| - except AttributeError as err: |
192 |
| - # e.g. Categorical, IntervalArray |
193 |
| - cls = type(self).__name__ |
194 |
| - raise TypeError( |
195 |
| - f"cannot perform {opname} with this index type: {cls}" |
196 |
| - ) from err |
197 |
| - |
198 |
| - result = meth(_maybe_unwrap_index(other)) |
199 |
| - return _wrap_arithmetic_op(self, other, result) |
200 |
| - |
201 |
| - method.__name__ = opname |
202 |
| - return method |
203 |
| - |
204 |
| - |
205 |
| -def _wrap_arithmetic_op(self, other, result): |
206 |
| - if result is NotImplemented: |
207 |
| - return NotImplemented |
208 |
| - |
209 |
| - if isinstance(result, tuple): |
210 |
| - # divmod, rdivmod |
211 |
| - assert len(result) == 2 |
212 |
| - return ( |
213 |
| - _wrap_arithmetic_op(self, other, result[0]), |
214 |
| - _wrap_arithmetic_op(self, other, result[1]), |
215 |
| - ) |
216 |
| - |
217 |
| - if not isinstance(result, Index): |
218 |
| - # Index.__new__ will choose appropriate subclass for dtype |
219 |
| - result = Index(result) |
220 |
| - |
221 |
| - res_name = get_op_result_name(self, other) |
222 |
| - result.name = res_name |
223 |
| - return result |
224 |
| - |
225 |
| - |
226 |
| -def _maybe_unwrap_index(obj): |
227 |
| - """ |
228 |
| - If operating against another Index object, we need to unwrap the underlying |
229 |
| - data before deferring to the DatetimeArray/TimedeltaArray/PeriodArray |
230 |
| - implementation, otherwise we will incorrectly return NotImplemented. |
231 |
| -
|
232 |
| - Parameters |
233 |
| - ---------- |
234 |
| - obj : object |
235 |
| -
|
236 |
| - Returns |
237 |
| - ------- |
238 |
| - unwrapped object |
239 |
| - """ |
240 |
| - if isinstance(obj, Index): |
241 |
| - return obj._data |
242 |
| - return obj |
243 |
| - |
244 |
| - |
245 | 152 | class ExtensionIndex(Index):
|
246 | 153 | """
|
247 | 154 | Index subclass for indexes backed by ExtensionArray.
|
@@ -284,30 +191,6 @@ def _simple_new(
|
284 | 191 | result._reset_identity()
|
285 | 192 | return result
|
286 | 193 |
|
287 |
| - __eq__ = _make_wrapped_comparison_op("__eq__") |
288 |
| - __ne__ = _make_wrapped_comparison_op("__ne__") |
289 |
| - __lt__ = _make_wrapped_comparison_op("__lt__") |
290 |
| - __gt__ = _make_wrapped_comparison_op("__gt__") |
291 |
| - __le__ = _make_wrapped_comparison_op("__le__") |
292 |
| - __ge__ = _make_wrapped_comparison_op("__ge__") |
293 |
| - |
294 |
| - __add__ = _make_wrapped_arith_op("__add__") |
295 |
| - __sub__ = _make_wrapped_arith_op("__sub__") |
296 |
| - __radd__ = _make_wrapped_arith_op("__radd__") |
297 |
| - __rsub__ = _make_wrapped_arith_op("__rsub__") |
298 |
| - __pow__ = _make_wrapped_arith_op("__pow__") |
299 |
| - __rpow__ = _make_wrapped_arith_op("__rpow__") |
300 |
| - __mul__ = _make_wrapped_arith_op("__mul__") |
301 |
| - __rmul__ = _make_wrapped_arith_op("__rmul__") |
302 |
| - __floordiv__ = _make_wrapped_arith_op("__floordiv__") |
303 |
| - __rfloordiv__ = _make_wrapped_arith_op("__rfloordiv__") |
304 |
| - __mod__ = _make_wrapped_arith_op("__mod__") |
305 |
| - __rmod__ = _make_wrapped_arith_op("__rmod__") |
306 |
| - __divmod__ = _make_wrapped_arith_op("__divmod__") |
307 |
| - __rdivmod__ = _make_wrapped_arith_op("__rdivmod__") |
308 |
| - __truediv__ = _make_wrapped_arith_op("__truediv__") |
309 |
| - __rtruediv__ = _make_wrapped_arith_op("__rtruediv__") |
310 |
| - |
311 | 194 | # ---------------------------------------------------------------------
|
312 | 195 | # NDarray-Like Methods
|
313 | 196 |
|
|
0 commit comments