# Buggy code
def convert_label_indexer(index, label, index_name="", method=None, tolerance=None):
    """Given a pandas.Index and labels (e.g., from __getitem__) for one
    dimension, return an indexer suitable for indexing an ndarray along that
    dimension. If `index` is a pandas.MultiIndex and depending on `label`,
    return a new pandas.Index or pandas.MultiIndex (otherwise return None).
    """
    new_index = None

    if isinstance(label, slice):
        if method is not None or tolerance is not None:
            raise NotImplementedError(
                "cannot use ``method`` argument if any indexers are slice objects"
            )
        indexer = index.slice_indexer(
            _try_get_item(label.start),
            _try_get_item(label.stop),
            _try_get_item(label.step),
        )
        if not isinstance(indexer, slice):
            # unlike pandas, in xarray we never want to silently convert a
            # slice indexer into an array indexer
            raise KeyError(
                "cannot represent labeled-based slice indexer for "
                "dimension %r with a slice over integer positions; "
                "the index is unsorted or non-unique" % index_name
            )

    elif is_dict_like(label):
        is_nested_vals = _is_nested_tuple(tuple(label.values()))
        if not isinstance(index, pd.MultiIndex):
            raise ValueError(
                "cannot use a dict-like object for selection on "
                "a dimension that does not have a MultiIndex"
            )
        elif len(label) == index.nlevels and not is_nested_vals:
            indexer = index.get_loc(tuple((label[k] for k in index.names)))
        else:
            for k, v in label.items():
                # index should be an item (i.e. Hashable) not an array-like
                if not isinstance(v, Hashable):
                    raise ValueError(
                        "Vectorized selection is not "
                        "available along level variable: " + k
                    )
            indexer, new_index = index.get_loc_level(
                tuple(label.values()), level=tuple(label.keys())
            )

    elif isinstance(label, tuple) and isinstance(index, pd.MultiIndex):
        if _is_nested_tuple(label):
            indexer = index.get_locs(label)
        elif len(label) == index.nlevels:
            indexer = index.get_loc(label)
        else:
            indexer, new_index = index.get_loc_level(
                label, level=list(range(len(label)))
            )

    else:
        label = (
            label
            if getattr(label, "ndim", 1) > 1  # vectorized-indexing
            else _asarray_tuplesafe(label)
        )
        if label.ndim == 0:
            if isinstance(index, pd.MultiIndex):
                indexer, new_index = index.get_loc_level(label.item(), level=0)
            else:
                indexer = get_loc(index, label.item(), method, tolerance)
        elif label.dtype.kind == "b":
            indexer = label
        else:
            if isinstance(index, pd.MultiIndex) and label.ndim > 1:
                raise ValueError(
                    "Vectorized selection is not available along "
                    "MultiIndex variable: " + index_name
                )
            indexer = get_indexer_nd(index, label, method, tolerance)
            if np.any(indexer < 0):
                raise KeyError("not all values found in index %r" % index_name)
    return indexer, new_index


# Traceback (TypeError)
In [282]: time = pd.date_range('2000-01-01', freq='H', periods=365 * 24)

In [283]: ds = xarray.Dataset({'foo': ('time', np.arange(365 * 24)), 'time': time})

In [284]: ds.sel(time=slice(ds["time"][0], ds["time"][10]))
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-284-a101e126e1b0> in <module>()
----> 1 ds.sel(time=slice(ds["time"][0], ds["time"][10]))

/dev/shm/gerrit/venv/stable-3.5/lib/python3.5/site-packages/xarray/core/dataset.py in sel(self, method, tolerance, drop, **indexers)
1180         """
1181         pos_indexers, new_indexes = indexing.remap_label_indexers(
-> 1182             self, indexers, method=method, tolerance=tolerance
1183         )
1184         result = self.isel(drop=drop, **pos_indexers)

/dev/shm/gerrit/venv/stable-3.5/lib/python3.5/site-packages/xarray/core/indexing.py in remap_label_indexers(data_obj, indexers, method, tolerance)
286         else:
287             idxr, new_idx = convert_label_indexer(index, label,
--> 288                                                   dim, method, tolerance)
289             pos_indexers[dim] = idxr
290             if new_idx is not None:

/dev/shm/gerrit/venv/stable-3.5/lib/python3.5/site-packages/xarray/core/indexing.py in convert_label_indexer(index, label, index_name, method, tolerance)
183         indexer = index.slice_indexer(_try_get_item(label.start),
184                                       _try_get_item(label.stop),
--> 185                                       _try_get_item(label.step))
186         if not isinstance(indexer, slice):
187             # unlike pandas, in xarray we never want to silently convert a slice

/dev/shm/gerrit/venv/stable-3.5/lib/python3.5/site-packages/pandas/tseries/index.py in slice_indexer(self, start, end, step, kind)
1496
1497         try:
-> 1498             return Index.slice_indexer(self, start, end, step, kind=kind)
1499         except KeyError:
1500             # For historical reasons DatetimeIndex by default supports

/dev/shm/gerrit/venv/stable-3.5/lib/python3.5/site-packages/pandas/indexes/base.py in slice_indexer(self, start, end, step, kind)
2995         """
2996         start_slice, end_slice = self.slice_locs(start, end, step=step,
-> 2997                                                  kind=kind)
2998
2999         # return a slice

/dev/shm/gerrit/venv/stable-3.5/lib/python3.5/site-packages/pandas/indexes/base.py in slice_locs(self, start, end, step, kind)
3174         start_slice = None
3175         if start is not None:
-> 3176             start_slice = self.get_slice_bound(start, 'left', kind)
3177         if start_slice is None:
3178             start_slice = 0

/dev/shm/gerrit/venv/stable-3.5/lib/python3.5/site-packages/pandas/indexes/base.py in get_slice_bound(self, label, side, kind)
3113         # For datetime indices label may be a string that has to be converted
3114         # to datetime boundary according to its resolution.
-> 3115         label = self._maybe_cast_slice_bound(label, side, kind)
3116
3117         # we need to look up the label

/dev/shm/gerrit/venv/stable-3.5/lib/python3.5/site-packages/pandas/tseries/index.py in _maybe_cast_slice_bound(self, label, side, kind)
1444
1445         if is_float(label) or isinstance(label, time) or is_integer(label):
-> 1446             self._invalid_indexer('slice', label)
1447
1448         if isinstance(label, compat.string_types):

/dev/shm/gerrit/venv/stable-3.5/lib/python3.5/site-packages/pandas/indexes/base.py in _invalid_indexer(self, form, key)
1282                         "indexers [{key}] of {kind}".format(
1283                             form=form, klass=type(self), key=key,
-> 1284                             kind=type(key)))
1285
1286     def get_duplicates(self):

TypeError: cannot do slice indexing on <class 'pandas.tseries.index.DatetimeIndex'> with these indexers [946684800000000000] of <class 'int'>

# Fixed code
def convert_label_indexer(index, label, index_name="", method=None, tolerance=None):
    """Given a pandas.Index and labels (e.g., from __getitem__) for one
    dimension, return an indexer suitable for indexing an ndarray along that
    dimension. If `index` is a pandas.MultiIndex and depending on `label`,
    return a new pandas.Index or pandas.MultiIndex (otherwise return None).
    """
    new_index = None

    if isinstance(label, slice):
        if method is not None or tolerance is not None:
            raise NotImplementedError(
                "cannot use ``method`` argument if any indexers are slice objects"
            )
        indexer = index.slice_indexer(
            _sanitize_slice_element(label.start),
            _sanitize_slice_element(label.stop),
            _sanitize_slice_element(label.step),
        )
        if not isinstance(indexer, slice):
            # unlike pandas, in xarray we never want to silently convert a
            # slice indexer into an array indexer
            raise KeyError(
                "cannot represent labeled-based slice indexer for "
                "dimension %r with a slice over integer positions; "
                "the index is unsorted or non-unique" % index_name
            )

    elif is_dict_like(label):
        is_nested_vals = _is_nested_tuple(tuple(label.values()))
        if not isinstance(index, pd.MultiIndex):
            raise ValueError(
                "cannot use a dict-like object for selection on "
                "a dimension that does not have a MultiIndex"
            )
        elif len(label) == index.nlevels and not is_nested_vals:
            indexer = index.get_loc(tuple((label[k] for k in index.names)))
        else:
            for k, v in label.items():
                # index should be an item (i.e. Hashable) not an array-like
                if not isinstance(v, Hashable):
                    raise ValueError(
                        "Vectorized selection is not "
                        "available along level variable: " + k
                    )
            indexer, new_index = index.get_loc_level(
                tuple(label.values()), level=tuple(label.keys())
            )

    elif isinstance(label, tuple) and isinstance(index, pd.MultiIndex):
        if _is_nested_tuple(label):
            indexer = index.get_locs(label)
        elif len(label) == index.nlevels:
            indexer = index.get_loc(label)
        else:
            indexer, new_index = index.get_loc_level(
                label, level=list(range(len(label)))
            )

    else:
        label = (
            label
            if getattr(label, "ndim", 1) > 1  # vectorized-indexing
            else _asarray_tuplesafe(label)
        )
        if label.ndim == 0:
            if isinstance(index, pd.MultiIndex):
                indexer, new_index = index.get_loc_level(label.item(), level=0)
            else:
                indexer = get_loc(index, label.item(), method, tolerance)
        elif label.dtype.kind == "b":
            indexer = label
        else:
            if isinstance(index, pd.MultiIndex) and label.ndim > 1:
                raise ValueError(
                    "Vectorized selection is not available along "
                    "MultiIndex variable: " + index_name
                )
            indexer = get_indexer_nd(index, label, method, tolerance)
            if np.any(indexer < 0):
                raise KeyError("not all values found in index %r" % index_name)
    return indexer, new_index