diff --git a/doc/source/user_guide/advanced.rst b/doc/source/user_guide/advanced.rst index 280eb05964787..20cde34baf373 100644 --- a/doc/source/user_guide/advanced.rst +++ b/doc/source/user_guide/advanced.rst @@ -1108,6 +1108,8 @@ the :meth:`~Index.is_unique` attribute. weakly_monotonic.is_monotonic_increasing weakly_monotonic.is_monotonic_increasing & weakly_monotonic.is_unique +.. _advanced.endpoints_are_inclusive: + Endpoints are inclusive ~~~~~~~~~~~~~~~~~~~~~~~ @@ -1137,7 +1139,7 @@ index can be somewhat complicated. For example, the following does not work: s.loc['c':'e' + 1] A very common use case is to limit a time series to start and end at two -specific dates. To enable this, we made the design to make label-based +specific dates. To enable this, we made the design choice to make label-based slicing include both endpoints: .. ipython:: python diff --git a/doc/source/user_guide/indexing.rst b/doc/source/user_guide/indexing.rst index c09eb87df0368..888266c3cfa55 100644 --- a/doc/source/user_guide/indexing.rst +++ b/doc/source/user_guide/indexing.rst @@ -61,8 +61,8 @@ of multi-axis indexing. * A list or array of labels ``['a', 'b', 'c']``. * A slice object with labels ``'a':'f'`` (Note that contrary to usual python slices, **both** the start and the stop are included, when present in the - index! See :ref:`Slicing with labels - `.). + index! See :ref:`Slicing with labels ` + and :ref:`Endpoints are inclusive `.) * A boolean array * A ``callable`` function with one argument (the calling Series or DataFrame) and that returns valid output for indexing (one of the above). @@ -335,8 +335,7 @@ The ``.loc`` attribute is the primary access method. The following are valid inp * A list or array of labels ``['a', 'b', 'c']``. * A slice object with labels ``'a':'f'`` (Note that contrary to usual python slices, **both** the start and the stop are included, when present in the - index! See :ref:`Slicing with labels - `.). + index! See :ref:`Slicing with labels `. * A boolean array. * A ``callable``, see :ref:`Selection By Callable `. @@ -418,6 +417,9 @@ error will be raised (since doing otherwise would be computationally expensive, as well as potentially ambiguous for mixed type indexes). For instance, in the above example, ``s.loc[1:6]`` would raise ``KeyError``. +For the rationale behind this behavior, see +:ref:`Endpoints are inclusive `. + .. _indexing.integer: Selection by position