# Buggy code
def _parsed_string_to_bounds(self, reso: Resolution, parsed: datetime):
    """
    Calculate datetime bounds for parsed time string and its resolution.

    Parameters
    ----------
    reso : str
        Resolution provided by parsed string.
    parsed : datetime
        Datetime from parsed string.

    Returns
    -------
    lower, upper: pd.Timestamp
    """
    assert isinstance(reso, Resolution), (type(reso), reso)
    valid_resos = {
        "year",
        "month",
        "quarter",
        "day",
        "hour",
        "minute",
        "second",
        "minute",
        "second",
        "microsecond",
    }
    if reso.attrname not in valid_resos:
        raise KeyError

    grp = reso.freq_group
    per = Period(parsed, freq=grp.value)
    start, end = per.start_time, per.end_time

    # GH 24076
    # If an incoming date string contained a UTC offset, need to localize
    # the parsed date to this offset first before aligning with the index's
    # timezone
    if parsed.tzinfo is not None:
        if self.tz is None:
            raise ValueError(
                "The index must be timezone aware when indexing "
                "with a date string with a UTC offset"
            )
        start = start.tz_localize(parsed.tzinfo).tz_convert(self.tz)
        end = end.tz_localize(parsed.tzinfo).tz_convert(self.tz)
    elif self.tz is not None:
        start = start.tz_localize(self.tz)
        end = end.tz_localize(self.tz)
    return start, end


# Traceback (KeyError)
During handling of the above exception, another exception occurred:

KeyError                                  Traceback (most recent call last)
<ipython-input-20-482a9c5e8c58> in <module>
----> 1 df['2017-10-25T16:25:04.252':'2017-10-25T16:50:05.237']

/opt/conda/lib/python3.7/site-packages/pandas/core/frame.py in __getitem__(self, key)
2777
2778         # Do we have a slicer (on rows)?
-> 2779         indexer = convert_to_index_sliceable(self, key)
2780         if indexer is not None:
2781             # either we have a slice or we have a string that can be converted

/opt/conda/lib/python3.7/site-packages/pandas/core/indexing.py in convert_to_index_sliceable(obj, key)
2265     idx = obj.index
2266     if isinstance(key, slice):
-> 2267         return idx._convert_slice_indexer(key, kind="getitem")
2268
2269     elif isinstance(key, str):

/opt/conda/lib/python3.7/site-packages/pandas/core/indexes/base.py in _convert_slice_indexer(self, key, kind)
2960             indexer = key
2961         else:
-> 2962             indexer = self.slice_indexer(start, stop, step, kind=kind)
2963
2964         return indexer

/opt/conda/lib/python3.7/site-packages/pandas/core/indexes/datetimes.py in slice_indexer(self, start, end, step, kind)
823                 mask = True
824                 if start is not None:
--> 825                     start_casted = self._maybe_cast_slice_bound(start, "left", kind)
826                     mask = start_casted <= self
827

/opt/conda/lib/python3.7/site-packages/pandas/core/indexes/datetimes.py in _maybe_cast_slice_bound(self, label, side, kind)
761             freq = getattr(self, "freqstr", getattr(self, "inferred_freq", None))
762             _, parsed, reso = parsing.parse_time_string(label, freq)
--> 763             lower, upper = self._parsed_string_to_bounds(reso, parsed)
764             # lower, upper form the half-open interval:
765             #   [parsed, parsed + 1 freq)

/opt/conda/lib/python3.7/site-packages/pandas/core/indexes/datetimes.py in _parsed_string_to_bounds(self, reso, parsed)
517         }
518         if reso not in valid_resos:
--> 519             raise KeyError
520         if reso == "year":
521             start = Timestamp(parsed.year, 1, 1)

KeyError:

# Fixed code
def _parsed_string_to_bounds(self, reso: Resolution, parsed: datetime):
    """
    Calculate datetime bounds for parsed time string and its resolution.

    Parameters
    ----------
    reso : str
        Resolution provided by parsed string.
    parsed : datetime
        Datetime from parsed string.

    Returns
    -------
    lower, upper: pd.Timestamp
    """
    assert isinstance(reso, Resolution), (type(reso), reso)
    valid_resos = {
        "year",
        "month",
        "quarter",
        "day",
        "hour",
        "minute",
        "second",
        "minute",
        "second",
        "millisecond",
        "microsecond",
    }
    if reso.attrname not in valid_resos:
        raise KeyError

    grp = reso.freq_group
    per = Period(parsed, freq=grp.value)
    start, end = per.start_time, per.end_time

    # GH 24076
    # If an incoming date string contained a UTC offset, need to localize
    # the parsed date to this offset first before aligning with the index's
    # timezone
    if parsed.tzinfo is not None:
        if self.tz is None:
            raise ValueError(
                "The index must be timezone aware when indexing "
                "with a date string with a UTC offset"
            )
        start = start.tz_localize(parsed.tzinfo).tz_convert(self.tz)
        end = end.tz_localize(parsed.tzinfo).tz_convert(self.tz)
    elif self.tz is not None:
        start = start.tz_localize(self.tz)
        end = end.tz_localize(self.tz)
    return start, end