Skip to content

Commit 6cab315

Browse files
author
tp
committed
.slice_indexer correction + examples
1 parent a355ed2 commit 6cab315

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
@@ -3430,7 +3430,7 @@ def _get_string_slice(self, key, use_lhs=True, use_rhs=True):
34303430

34313431
def slice_indexer(self, start=None, end=None, step=None, kind=None):
34323432
"""
3433-
For an ordered Index, compute the slice indexer for input labels and
3433+
For an ordered index, compute the slice indexer for input labels and
34343434
step
34353435
34363436
Parameters
@@ -3444,11 +3444,23 @@ def slice_indexer(self, start=None, end=None, step=None, kind=None):
34443444
34453445
Returns
34463446
-------
3447-
indexer : ndarray or slice
3447+
indexer : slice
34483448
34493449
Notes
34503450
-----
34513451
This function assumes that the data is sorted, so use at your own peril
3452+
3453+
Examples
3454+
---------
3455+
This is a method on all index types. For example you can do:
3456+
3457+
>>> idx = pd.Index(list('abcd'))
3458+
>>> idx.slice_indexer(start='b', end='c')
3459+
slice(1, 3)
3460+
3461+
>>> idx = pd.MultiIndex.from_arrays([list('abcd'), list('efgh')])
3462+
>>> idx.slice_indexer(start='b', end=('c', 'g'))
3463+
slice(1, 3)
34523464
"""
34533465
start_slice, end_slice = self.slice_locs(start, end, step=step,
34543466
kind=kind)

0 commit comments

Comments
 (0)