def get_loc(self, key, method=None):
if method is not None:<EOL><INDENT>raise NotImplementedError('<STR_LIT>'<EOL>'<STR_LIT>')<EOL><DEDENT>def _maybe_to_slice(loc):<EOL><INDENT>"""<STR_LIT>"""<EOL>if not isinstance(loc, np.ndarray) or loc.dtype != '<STR_LIT>':<EOL><INDENT>return loc<EOL><DEDENT>loc = lib.maybe_indices_to_slice(loc, len(self))<EOL>if isinstance(loc, slice):<EOL><INDENT>return loc<EOL><DEDENT>mask = np.empty(len(self), dtype='<STR_LIT:bool>')<EOL>mask.fill(False)<EOL>mask[loc] = True<EOL>return mask<EOL><DEDENT>if not isinstance(key, tuple):<EOL><INDENT>loc = self._get_level_indexer(key, level=<NUM_LIT:0>)<EOL>return _maybe_to_slice(loc)<EOL><DEDENT>keylen = len(key)<EOL>if self.nlevels < keylen:<EOL><INDENT>raise KeyError('<STR_LIT>'<EOL>'<STR_LIT>'.format(keylen, self.nlevels))<EOL><DEDENT>if keylen == self.nlevels and self.is_unique:<EOL><INDENT>return self._engine.get_loc(key)<EOL><DEDENT>i = self.lexsort_depth<EOL>lead_key, follow_key = key[:i], key[i:]<EOL>start, stop = (self.slice_locs(lead_key, lead_key)<EOL>if lead_key else (<NUM_LIT:0>, len(self)))<EOL>if start == stop:<EOL><INDENT>raise KeyError(key)<EOL><DEDENT>if not follow_key:<EOL><INDENT>return slice(start, stop)<EOL><DEDENT>warnings.warn('<STR_LIT>',<EOL>PerformanceWarning, stacklevel=<NUM_LIT:10>)<EOL>loc = np.arange(start, stop, dtype='<STR_LIT>')<EOL>for i, k in enumerate(follow_key, len(lead_key)):<EOL><INDENT>mask = self.codes[i][loc] == self.levels[i].get_loc(k)<EOL>if not mask.all():<EOL><INDENT>loc = loc[mask]<EOL><DEDENT>if not len(loc):<EOL><INDENT>raise KeyError(key)<EOL><DEDENT><DEDENT>return (_maybe_to_slice(loc) if len(loc) != stop - start else<EOL>slice(start, stop))<EOL>
Get location for a label or a tuple of labels as an integer, slice or
boolean mask.

Parameters
----------
key : label or tuple of labels (one for each level)
method : None

Returns
-------
loc : int, slice object or boolean mask
    If the key is past the lexsort depth, the return may be a
    boolean mask array, otherwise it is always a slice or int.

Examples
---------
>>> mi = pd.MultiIndex.from_arrays([list('abb'), list('def')])

>>> mi.get_loc('b')
slice(1, 3, None)

>>> mi.get_loc(('b', 'e'))
1

Notes
------
The key cannot be a slice, list of same-level labels, a boolean mask,
or a sequence of such. If you want to use those, use
:meth:`MultiIndex.get_locs` instead.

See Also
--------
Index.get_loc : The get_loc method for (single-level) index.
MultiIndex.slice_locs : Get slice location given start label(s) and
                        end label(s).
MultiIndex.get_locs : Get location for a label/slice/list/mask or a
                      sequence of such.