intersection specialized to the case with matching dtypes.
(self, other: Index, sort: bool = False)
| 3336 | return self._wrap_intersection_result(other, result) |
| 3337 | |
| 3338 | def _intersection(self, other: Index, sort: bool = False): |
| 3339 | """ |
| 3340 | intersection specialized to the case with matching dtypes. |
| 3341 | """ |
| 3342 | if self._can_use_libjoin and other._can_use_libjoin: |
| 3343 | try: |
| 3344 | res_indexer, indexer, _ = self._inner_indexer(other) |
| 3345 | except TypeError: |
| 3346 | # non-comparable; should only be for object dtype |
| 3347 | pass |
| 3348 | else: |
| 3349 | # TODO: algos.unique1d should preserve DTA/TDA |
| 3350 | if is_numeric_dtype(self.dtype): |
| 3351 | # This is faster, because Index.unique() checks for uniqueness |
| 3352 | # before calculating the unique values. |
| 3353 | res = algos.unique1d(res_indexer) |
| 3354 | else: |
| 3355 | result = self.take(indexer) |
| 3356 | res = result.drop_duplicates() # type: ignore[assignment] |
| 3357 | return ensure_wrapped_if_datetimelike(res) |
| 3358 | |
| 3359 | res_values = self._intersection_via_get_indexer(other, sort=sort) |
| 3360 | res_values = _maybe_try_sort(res_values, sort) |
| 3361 | return res_values |
| 3362 | |
| 3363 | def _wrap_intersection_result(self, other, result): |
| 3364 | # We will override for MultiIndex to handle empty results |
no test coverage detected