Skip to content

docs: rewrite .iloc accessing beyond ends. #7756

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 1 commit into from
Jul 15, 2014
Merged
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
25 changes: 18 additions & 7 deletions doc/source/indexing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -415,20 +415,29 @@ For getting a cross section using an integer position (equiv to ``df.xs(1)``)

df1.iloc[1]

There is one significant departure from standard python/numpy slicing semantics.
python/numpy allow slicing past the end of an array without an associated error.
Out of range slice indexes are handled gracefully just as in Python/Numpy.

.. ipython:: python

# these are allowed in python/numpy.
# Only works in Pandas starting from v0.14.0.
x = list('abcdef')
x
x[4:10]
x[8:10]
s = Series(x)
s
s.iloc[4:10]
s.iloc[8:10]

- as of v0.14.0, ``iloc`` will now accept out-of-bounds indexers for slices, e.g. a value that exceeds the length of the object being
indexed. These will be excluded. This will make pandas conform more with pandas/numpy indexing of out-of-bounds
values. A single indexer / list of indexers that is out-of-bounds will still raise
``IndexError`` (:issue:`6296`, :issue:`6299`). This could result in an empty axis (e.g. an empty DataFrame being returned)
.. note::

Prior to v0.14.0, ``iloc`` would not accept out of bounds indexers for
slices, e.g. a value that exceeds the length of the object being indexed.


Note that this could result in an empty axis (e.g. an empty DataFrame being
returned)

.. ipython:: python

Expand All @@ -438,7 +447,9 @@ python/numpy allow slicing past the end of an array without an associated error.
dfl.iloc[:,1:3]
dfl.iloc[4:6]

These are out-of-bounds selections
A single indexer that is out of bounds will raise an ``IndexError``.
A list of indexers where any element is out of bounds will raise an
``IndexError``

.. code-block:: python

Expand Down