Skip to content

Commit 52fe6bc

Browse files
topper-123jorisvandenbossche
authored andcommitted
DOC: slice_indexer correction + examples (#17829)
1 parent 3f4089d commit 52fe6bc

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

doc/source/advanced.rst

+3-3
Original file line numberDiff line numberDiff line change
@@ -833,15 +833,15 @@ Of course if you need integer based selection, then use ``iloc``
833833
IntervalIndex
834834
~~~~~~~~~~~~~
835835
836+
.. versionadded:: 0.20.0
837+
836838
:class:`IntervalIndex` together with its own dtype, ``interval`` as well as the
837839
:class:`Interval` scalar type, allow first-class support in pandas for interval
838840
notation.
839841
840842
The ``IntervalIndex`` allows some unique indexing and is also used as a
841843
return type for the categories in :func:`cut` and :func:`qcut`.
842844
843-
.. versionadded:: 0.20.0
844-
845845
.. warning::
846846
847847
These indexing behaviors are provisional and may change in a future version of pandas.
@@ -862,7 +862,7 @@ selecting that particular interval.
862862
df.loc[2]
863863
df.loc[[2, 3]]
864864
865-
If you select a lable *contained* within an interval, this will also select the interval.
865+
If you select a label *contained* within an interval, this will also select the interval.
866866
867867
.. ipython:: python
868868

pandas/core/indexes/base.py

+20-3
Original file line numberDiff line numberDiff line change
@@ -3428,8 +3428,8 @@ def _get_string_slice(self, key, use_lhs=True, use_rhs=True):
34283428

34293429
def slice_indexer(self, start=None, end=None, step=None, kind=None):
34303430
"""
3431-
For an ordered Index, compute the slice indexer for input labels and
3432-
step
3431+
For an ordered or unique index, compute the slice indexer for input
3432+
labels and step.
34333433
34343434
Parameters
34353435
----------
@@ -3442,11 +3442,28 @@ def slice_indexer(self, start=None, end=None, step=None, kind=None):
34423442
34433443
Returns
34443444
-------
3445-
indexer : ndarray or slice
3445+
indexer : slice
3446+
3447+
Raises
3448+
------
3449+
KeyError : If key does not exist, or key is not unique and index is
3450+
not ordered.
34463451
34473452
Notes
34483453
-----
34493454
This function assumes that the data is sorted, so use at your own peril
3455+
3456+
Examples
3457+
---------
3458+
This is a method on all index types. For example you can do:
3459+
3460+
>>> idx = pd.Index(list('abcd'))
3461+
>>> idx.slice_indexer(start='b', end='c')
3462+
slice(1, 3)
3463+
3464+
>>> idx = pd.MultiIndex.from_arrays([list('abcd'), list('efgh')])
3465+
>>> idx.slice_indexer(start='b', end=('c', 'g'))
3466+
slice(1, 3)
34503467
"""
34513468
start_slice, end_slice = self.slice_locs(start, end, step=step,
34523469
kind=kind)

0 commit comments

Comments
 (0)