def intersection(self, other, sort=False):
self._validate_sort_keyword(sort)<EOL>self._assert_can_do_setop(other)<EOL>other = ensure_index(other)<EOL>if self.equals(other):<EOL><INDENT>return self._get_reconciled_name_object(other)<EOL><DEDENT>if not is_dtype_equal(self.dtype, other.dtype):<EOL><INDENT>this = self.astype('<STR_LIT:O>')<EOL>other = other.astype('<STR_LIT:O>')<EOL>return this.intersection(other, sort=sort)<EOL><DEDENT>if is_period_dtype(self):<EOL><INDENT>lvals = self._ndarray_values<EOL><DEDENT>else:<EOL><INDENT>lvals = self._values<EOL><DEDENT>if is_period_dtype(other):<EOL><INDENT>rvals = other._ndarray_values<EOL><DEDENT>else:<EOL><INDENT>rvals = other._values<EOL><DEDENT>if self.is_monotonic and other.is_monotonic:<EOL><INDENT>try:<EOL><INDENT>result = self._inner_indexer(lvals, rvals)[<NUM_LIT:0>]<EOL>return self._wrap_setop_result(other, result)<EOL><DEDENT>except TypeError:<EOL><INDENT>pass<EOL><DEDENT><DEDENT>try:<EOL><INDENT>indexer = Index(rvals).get_indexer(lvals)<EOL>indexer = indexer.take((indexer != -<NUM_LIT:1>).nonzero()[<NUM_LIT:0>])<EOL><DEDENT>except Exception:<EOL><INDENT>indexer = algos.unique1d(<EOL>Index(rvals).get_indexer_non_unique(lvals)[<NUM_LIT:0>])<EOL>indexer = indexer[indexer != -<NUM_LIT:1>]<EOL><DEDENT>taken = other.take(indexer)<EOL>if sort is None:<EOL><INDENT>taken = sorting.safe_sort(taken.values)<EOL>if self.name != other.name:<EOL><INDENT>name = None<EOL><DEDENT>else:<EOL><INDENT>name = self.name<EOL><DEDENT>return self._shallow_copy(taken, name=name)<EOL><DEDENT>if self.name != other.name:<EOL><INDENT>taken.name = None<EOL><DEDENT>return taken<EOL>
Form the intersection of two Index objects.

This returns a new Index with elements common to the index and `other`.

Parameters
----------
other : Index or array-like
sort : False or None, default False
    Whether to sort the resulting index.

    * False : do not sort the result.
    * None : sort the result, except when `self` and `other` are equal
      or when the values cannot be compared.

    .. versionadded:: 0.24.0

    .. versionchanged:: 0.24.1

       Changed the default from ``True`` to ``False``, to match
       the behaviour of 0.23.4 and earlier.

Returns
-------
intersection : Index

Examples
--------

>>> idx1 = pd.Index([1, 2, 3, 4])
>>> idx2 = pd.Index([3, 4, 5, 6])
>>> idx1.intersection(idx2)
Int64Index([3, 4], dtype='int64')