|
11 | 11 | from pandas._libs.tslibs.parsing import DateParseError, parse_time_string |
12 | 12 | from pandas._typing import Dtype, DtypeObj |
13 | 13 | from pandas.errors import InvalidIndexError |
14 | | -from pandas.util._decorators import cache_readonly, doc |
| 14 | +from pandas.util._decorators import doc |
15 | 15 |
|
16 | 16 | from pandas.core.dtypes.common import ( |
17 | 17 | is_bool_dtype, |
@@ -324,10 +324,6 @@ def __contains__(self, key: Any) -> bool: |
324 | 324 | except KeyError: |
325 | 325 | return False |
326 | 326 |
|
327 | | - @cache_readonly |
328 | | - def _int64index(self) -> Int64Index: |
329 | | - return Int64Index._simple_new(self.asi8, name=self.name) |
330 | | - |
331 | 327 | # ------------------------------------------------------------------------ |
332 | 328 | # Index Methods |
333 | 329 |
|
@@ -424,24 +420,18 @@ def inferred_type(self) -> str: |
424 | 420 | # ------------------------------------------------------------------------ |
425 | 421 | # Indexing Methods |
426 | 422 |
|
427 | | - def _get_indexer(self, target: Index, method=None, limit=None, tolerance=None): |
428 | | - |
429 | | - if not self._should_compare(target): |
430 | | - return self._get_indexer_non_comparable(target, method, unique=True) |
431 | | - |
432 | | - if isinstance(target, PeriodIndex): |
433 | | - target = target._int64index # i.e. target.asi8 |
434 | | - self_index = self._int64index |
435 | | - else: |
436 | | - self_index = self |
| 423 | + def _convert_tolerance(self, tolerance, target): |
| 424 | + # Returned tolerance must be in dtype/units so that |
| 425 | + # `|self._get_engine_target() - target._engine_target()| <= tolerance` |
| 426 | + # is meaningful. Since PeriodIndex returns int64 for engine_target, |
| 427 | + # we may need to convert timedelta64 tolerance to int64. |
| 428 | + tolerance = super()._convert_tolerance(tolerance, target) |
437 | 429 |
|
438 | | - if tolerance is not None: |
439 | | - tolerance = self._convert_tolerance(tolerance, target) |
440 | | - if self_index is not self: |
441 | | - # convert tolerance to i8 |
442 | | - tolerance = self._maybe_convert_timedelta(tolerance) |
| 430 | + if self.dtype == target.dtype: |
| 431 | + # convert tolerance to i8 |
| 432 | + tolerance = self._maybe_convert_timedelta(tolerance) |
443 | 433 |
|
444 | | - return Index._get_indexer(self_index, target, method, limit, tolerance) |
| 434 | + return tolerance |
445 | 435 |
|
446 | 436 | def get_loc(self, key, method=None, tolerance=None): |
447 | 437 | """ |
@@ -579,14 +569,6 @@ def _get_string_slice(self, key: str): |
579 | 569 | except KeyError as err: |
580 | 570 | raise KeyError(key) from err |
581 | 571 |
|
582 | | - # ------------------------------------------------------------------------ |
583 | | - |
584 | | - def memory_usage(self, deep: bool = False) -> int: |
585 | | - result = super().memory_usage(deep=deep) |
586 | | - if hasattr(self, "_cache") and "_int64index" in self._cache: |
587 | | - result += self._int64index.memory_usage(deep=deep) |
588 | | - return result |
589 | | - |
590 | 572 |
|
591 | 573 | def period_range( |
592 | 574 | start=None, end=None, periods: Optional[int] = None, freq=None, name=None |
|
0 commit comments