MCPcopy
hub / github.com/pandas-dev/pandas / _intersection

Method _intersection

pandas/core/indexes/base.py:3338–3361  ·  view source on GitHub ↗

intersection specialized to the case with matching dtypes.

(self, other: Index, sort: bool = False)

Source from the content-addressed store, hash-verified

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

Callers 1

intersectionMethod · 0.95

Calls 7

_inner_indexerMethod · 0.95
takeMethod · 0.95
is_numeric_dtypeFunction · 0.90
_maybe_try_sortFunction · 0.85
drop_duplicatesMethod · 0.45

Tested by

no test coverage detected