Skip to content

Commit ccc34b2

Browse files
author
tp
committed
.slice_indexer correction + examples
1 parent 35590c6 commit ccc34b2

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
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

+14-2
Original file line numberDiff line numberDiff line change
@@ -3412,7 +3412,7 @@ def _get_string_slice(self, key, use_lhs=True, use_rhs=True):
34123412

34133413
def slice_indexer(self, start=None, end=None, step=None, kind=None):
34143414
"""
3415-
For an ordered Index, compute the slice indexer for input labels and
3415+
For an ordered index, compute the slice indexer for input labels and
34163416
step
34173417
34183418
Parameters
@@ -3426,11 +3426,23 @@ def slice_indexer(self, start=None, end=None, step=None, kind=None):
34263426
34273427
Returns
34283428
-------
3429-
indexer : ndarray or slice
3429+
indexer : slice
34303430
34313431
Notes
34323432
-----
34333433
This function assumes that the data is sorted, so use at your own peril
3434+
3435+
Examples
3436+
---------
3437+
This is a method on all index types. For example:
3438+
3439+
>>> idx = pd.Index(list('abcd'))
3440+
>>> idx.slice_indexer(start='b', end='c')
3441+
slice(1, 3)
3442+
3443+
>>> idx = pd.MultiIndex.from_arrays([list('abcd'), list('efgh')])
3444+
>>> idx.slice_indexer(start='b', end=('c', 'g'))
3445+
slice(1, 3)
34343446
"""
34353447
start_slice, end_slice = self.slice_locs(start, end, step=step,
34363448
kind=kind)

0 commit comments

Comments
 (0)