|
8 | 8 |
|
9 | 9 | from pandas._libs import NaT, iNaT, join as libjoin, lib
|
10 | 10 | from pandas._libs.tslibs import timezones
|
11 |
| -from pandas._typing import Label |
| 11 | +from pandas._typing import DtypeObj, Label |
12 | 12 | from pandas.compat.numpy import function as nv
|
13 | 13 | from pandas.errors import AbstractMethodError
|
14 | 14 | from pandas.util._decorators import Appender, cache_readonly, doc
|
15 | 15 |
|
16 | 16 | from pandas.core.dtypes.common import (
|
17 | 17 | ensure_int64,
|
| 18 | + ensure_platform_int, |
18 | 19 | is_bool_dtype,
|
19 | 20 | is_categorical_dtype,
|
20 | 21 | is_dtype_equal,
|
|
32 | 33 | from pandas.core.arrays.datetimelike import DatetimeLikeArrayMixin
|
33 | 34 | from pandas.core.base import IndexOpsMixin
|
34 | 35 | import pandas.core.indexes.base as ibase
|
35 |
| -from pandas.core.indexes.base import Index, _index_shared_docs |
| 36 | +from pandas.core.indexes.base import Index, _index_shared_docs, ensure_index |
36 | 37 | from pandas.core.indexes.extension import (
|
37 | 38 | ExtensionIndex,
|
38 | 39 | inherit_names,
|
@@ -101,6 +102,12 @@ class DatetimeIndexOpsMixin(ExtensionIndex):
|
101 | 102 | def is_all_dates(self) -> bool:
|
102 | 103 | return True
|
103 | 104 |
|
| 105 | + def _is_comparable_dtype(self, dtype: DtypeObj) -> bool: |
| 106 | + """ |
| 107 | + Can we compare values of the given dtype to our own? |
| 108 | + """ |
| 109 | + raise AbstractMethodError(self) |
| 110 | + |
104 | 111 | # ------------------------------------------------------------------------
|
105 | 112 | # Abstract data attributes
|
106 | 113 |
|
@@ -426,6 +433,21 @@ def _partial_date_slice(
|
426 | 433 | # try to find the dates
|
427 | 434 | return (lhs_mask & rhs_mask).nonzero()[0]
|
428 | 435 |
|
| 436 | + @Appender(Index.get_indexer_non_unique.__doc__) |
| 437 | + def get_indexer_non_unique(self, target): |
| 438 | + target = ensure_index(target) |
| 439 | + pself, ptarget = self._maybe_promote(target) |
| 440 | + if pself is not self or ptarget is not target: |
| 441 | + return pself.get_indexer_non_unique(ptarget) |
| 442 | + |
| 443 | + if not self._is_comparable_dtype(target.dtype): |
| 444 | + no_matches = -1 * np.ones(self.shape, dtype=np.intp) |
| 445 | + return no_matches, no_matches |
| 446 | + |
| 447 | + tgt_values = target.asi8 |
| 448 | + indexer, missing = self._engine.get_indexer_non_unique(tgt_values) |
| 449 | + return ensure_platform_int(indexer), missing |
| 450 | + |
429 | 451 | # --------------------------------------------------------------------
|
430 | 452 |
|
431 | 453 | __add__ = make_wrapped_arith_op("__add__")
|
|
0 commit comments