

def intersection(self, other):
    "\n        Form the intersection of two Index objects.\n\n        This returns a new Index with elements common to the index and `other`.\n        Sortedness of the result is not guaranteed.\n\n        Parameters\n        ----------\n        other : Index or array-like\n\n        Returns\n        -------\n        intersection : Index\n\n        Examples\n        --------\n\n        >>> idx1 = pd.Index([1, 2, 3, 4])\n        >>> idx2 = pd.Index([3, 4, 5, 6])\n        >>> idx1.intersection(idx2)\n        Int64Index([3, 4], dtype='int64')\n\n        "
    self._assert_can_do_setop(other)
    other = _ensure_index(other)
    if self.equals(other):
        return self
    if (not com.is_dtype_equal(self.dtype, other.dtype)):
        this = self.astype('O')
        other = other.astype('O')
        return this.intersection(other)
    if (self.is_monotonic and other.is_monotonic):
        try:
            result = self._inner_indexer(self.values, other._values)[0]
            return self._wrap_union_result(other, result)
        except TypeError:
            pass
    try:
        indexer = Index(self.values).get_indexer(other._values)
        indexer = indexer.take((indexer != (- 1)).nonzero()[0])
    except:
        indexer = Index(self.values).get_indexer_non_unique(other._values)[0].unique()
        indexer = indexer[(indexer != (- 1))]
    taken = self.take(indexer)
    if (self.name != other.name):
        taken.name = None
    return taken

dataset/ETHPy150Open pydata/pandas/pandas/indexes/base.py Index.intersection/original