Guaranteed return of an indexer even when non-unique. This dispatches to get_indexer or get_indexer_non_unique as appropriate. Parameters ---------- target : Index An iterable containing the values to be used for computing indexer.
(self, target)
| 6251 | |
| 6252 | @final |
| 6253 | def get_indexer_for(self, target) -> npt.NDArray[np.intp]: |
| 6254 | """ |
| 6255 | Guaranteed return of an indexer even when non-unique. |
| 6256 | |
| 6257 | This dispatches to get_indexer or get_indexer_non_unique |
| 6258 | as appropriate. |
| 6259 | |
| 6260 | Parameters |
| 6261 | ---------- |
| 6262 | target : Index |
| 6263 | An iterable containing the values to be used for computing indexer. |
| 6264 | |
| 6265 | Returns |
| 6266 | ------- |
| 6267 | np.ndarray[np.intp] |
| 6268 | List of indices. |
| 6269 | |
| 6270 | See Also |
| 6271 | -------- |
| 6272 | Index.get_indexer : Computes indexer and mask for new index given |
| 6273 | the current index. |
| 6274 | Index.get_non_unique : Returns indexer and masks for new index given |
| 6275 | the current index. |
| 6276 | |
| 6277 | Examples |
| 6278 | -------- |
| 6279 | >>> idx = pd.Index([np.nan, "var1", np.nan]) |
| 6280 | >>> idx.get_indexer_for([np.nan]) |
| 6281 | array([0, 2]) |
| 6282 | """ |
| 6283 | if self._index_as_unique: |
| 6284 | return self.get_indexer(target) |
| 6285 | indexer, _ = self.get_indexer_non_unique(target) |
| 6286 | return indexer |
| 6287 | |
| 6288 | def _get_indexer_strict(self, key, axis_name: str_t) -> tuple[Index, np.ndarray]: |
| 6289 | """ |