def get_loc(self, key, method=None, tolerance=None):
    '\n        Get integer location for requested label.\n\n        Parameters\n        ----------\n        key : Period, NaT, str, or datetime\n            String or datetime key must be parsable as Period.\n\n        Returns\n        -------\n        loc : int or ndarray[int64]\n\n        Raises\n        ------\n        KeyError\n            Key is not present in the index.\n        TypeError\n            If key is listlike or otherwise not hashable.\n        '
    orig_key = key
    if (not is_scalar(key)):
        raise InvalidIndexError(key)
    if is_valid_na_for_dtype(key, self.dtype):
        key = NaT
    elif isinstance(key, str):
        try:
            loc = self._get_string_slice(key)
            return loc
        except (TypeError, ValueError):
            pass
        try:
            (asdt, reso_str) = parse_time_string(key, self.freq)
        except (ValueError, DateParseError) as err:
            raise KeyError(f"Cannot interpret '{key}' as period") from err
        reso = Resolution.from_attrname(reso_str)
        grp = reso.freq_group.value
        freqn = self.dtype.freq_group_code
        assert (grp >= freqn)
        if ((grp == freqn) or ((reso == Resolution.RESO_DAY) and (self.dtype.freq.name == 'B'))):
            key = Period(asdt, freq=self.freq)
            loc = self.get_loc(key, method=method, tolerance=tolerance)
            return loc
        elif (method is None):
            raise KeyError(key)
        else:
            key = asdt
    elif isinstance(key, Period):
        sfreq = self.freq
        kfreq = key.freq
        if (not ((sfreq.n == kfreq.n) and (sfreq._period_dtype_code == kfreq._period_dtype_code))):
            raise KeyError(key)
    elif isinstance(key, datetime):
        try:
            key = Period(key, freq=self.freq)
        except ValueError as err:
            raise KeyError(orig_key) from err
    else:
        raise KeyError(key)
    try:
        key = Period(key, freq=self.freq)
    except ValueError as err:
        raise KeyError(orig_key) from err
    try:
        return Index.get_loc(self, key, method, tolerance)
    except KeyError as err:
        raise KeyError(orig_key) from err
Get integer location for requested label.

Parameters
----------
key : Period, NaT, str, or datetime
    String or datetime key must be parsable as Period.

Returns
-------
loc : int or ndarray[int64]

Raises
------
KeyError
    Key is not present in the index.
TypeError
    If key is listlike or otherwise not hashable.
def get_loc(self, key, method=None, tolerance=None):
    '\n        Get integer location for requested label.\n\n        Parameters\n        ----------\n        key : Period, NaT, str, or datetime\n            String or datetime key must be parsable as Period.\n\n        Returns\n        -------\n        loc : int or ndarray[int64]\n\n        Raises\n        ------\n        KeyError\n            Key is not present in the index.\n        TypeError\n            If key is listlike or otherwise not hashable.\n        '
    orig_key = key
    if (not is_scalar(key)):
        raise InvalidIndexError(key)
    if is_valid_na_for_dtype(key, self.dtype):
        key = NaT
    elif isinstance(key, str):
        try:
            loc = self._get_string_slice(key)
            return loc
        except (TypeError, ValueError):
            pass
        try:
            (asdt, reso_str) = parse_time_string(key, self.freq)
        except (ValueError, DateParseError) as err:
            raise KeyError(f"Cannot interpret '{key}' as period") from err
        reso = Resolution.from_attrname(reso_str)
        grp = reso.freq_group.value
        freqn = self.dtype.freq_group_code
        assert (grp >= freqn)
        if ((grp == freqn) or ((reso == Resolution.RESO_DAY) and (self.dtype.freq.name == 'B'))):
            key = Period(asdt, freq=self.freq)
            loc = self.get_loc(key, method=method, tolerance=tolerance)
            return loc
        elif (method is None):
            raise KeyError(key)
        else:
            key = asdt
    elif isinstance(key, Period):
        sfreq = self.freq
        kfreq = key.freq
        if (not ((sfreq.n == kfreq.n) and (sfreq._period_dtype_code == kfreq._period_dtype_code))):
            raise KeyError(key)
    elif isinstance(key, datetime):
        try:
            key = Period(key, freq=self.freq)
        except ValueError as err:
            raise KeyError(orig_key) from err
    else:
        raise KeyError(key)
    try:
        key = Period(key, freq=self.freq)
    except ValueError as err:
        raise KeyError(orig_key) from err
    try:
        return Index.get_loc(self, key, method, tolerance)
    except KeyError as err:
        raise KeyError(orig_key) from err