diff --git a/doc/source/advanced.rst b/doc/source/advanced.rst index 44358593793bc..db1780e88baef 100644 --- a/doc/source/advanced.rst +++ b/doc/source/advanced.rst @@ -833,6 +833,8 @@ Of course if you need integer based selection, then use ``iloc`` IntervalIndex ~~~~~~~~~~~~~ +.. versionadded:: 0.20.0 + :class:`IntervalIndex` together with its own dtype, ``interval`` as well as the :class:`Interval` scalar type, allow first-class support in pandas for interval notation. @@ -840,8 +842,6 @@ notation. The ``IntervalIndex`` allows some unique indexing and is also used as a return type for the categories in :func:`cut` and :func:`qcut`. -.. versionadded:: 0.20.0 - .. warning:: These indexing behaviors are provisional and may change in a future version of pandas. @@ -862,7 +862,7 @@ selecting that particular interval. df.loc[2] df.loc[[2, 3]] -If you select a lable *contained* within an interval, this will also select the interval. +If you select a label *contained* within an interval, this will also select the interval. .. ipython:: python diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index a995fc10a6674..7b59a9fd33f6d 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -3430,8 +3430,8 @@ def _get_string_slice(self, key, use_lhs=True, use_rhs=True): def slice_indexer(self, start=None, end=None, step=None, kind=None): """ - For an ordered Index, compute the slice indexer for input labels and - step + For an ordered or unique index, compute the slice indexer for input + labels and step. Parameters ---------- @@ -3444,11 +3444,28 @@ def slice_indexer(self, start=None, end=None, step=None, kind=None): Returns ------- - indexer : ndarray or slice + indexer : slice + + Raises + ------ + KeyError : If key does not exist, or key is not unique and index is + not ordered. Notes ----- This function assumes that the data is sorted, so use at your own peril + + Examples + --------- + This is a method on all index types. For example you can do: + + >>> idx = pd.Index(list('abcd')) + >>> idx.slice_indexer(start='b', end='c') + slice(1, 3) + + >>> idx = pd.MultiIndex.from_arrays([list('abcd'), list('efgh')]) + >>> idx.slice_indexer(start='b', end=('c', 'g')) + slice(1, 3) """ start_slice, end_slice = self.slice_locs(start, end, step=step, kind=kind)