Skip to content

DOC: slice_indexer correction + examples #17829

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions doc/source/advanced.rst
Original file line number Diff line number Diff line change
Expand Up @@ -833,15 +833,15 @@ 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.

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.
Expand All @@ -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

Expand Down
23 changes: 20 additions & 3 deletions pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
----------
Expand All @@ -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)
Expand Down