Skip to content

Commit e6a5b6c

Browse files
committed
Merge pull request #7756 from lexual/indexing_docs_past_end
docs: rewrite .iloc accessing beyond ends.
2 parents 570584c + 634f3b9 commit e6a5b6c

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

doc/source/indexing.rst

+18-7
Original file line numberDiff line numberDiff line change
@@ -415,20 +415,29 @@ For getting a cross section using an integer position (equiv to ``df.xs(1)``)
415415
416416
df1.iloc[1]
417417
418-
There is one significant departure from standard python/numpy slicing semantics.
419-
python/numpy allow slicing past the end of an array without an associated error.
418+
Out of range slice indexes are handled gracefully just as in Python/Numpy.
420419

421420
.. ipython:: python
422421
423422
# these are allowed in python/numpy.
423+
# Only works in Pandas starting from v0.14.0.
424424
x = list('abcdef')
425+
x
425426
x[4:10]
426427
x[8:10]
428+
s = Series(x)
429+
s
430+
s.iloc[4:10]
431+
s.iloc[8:10]
427432
428-
- 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
429-
indexed. These will be excluded. This will make pandas conform more with pandas/numpy indexing of out-of-bounds
430-
values. A single indexer / list of indexers that is out-of-bounds will still raise
431-
``IndexError`` (:issue:`6296`, :issue:`6299`). This could result in an empty axis (e.g. an empty DataFrame being returned)
433+
.. note::
434+
435+
Prior to v0.14.0, ``iloc`` would not accept out of bounds indexers for
436+
slices, e.g. a value that exceeds the length of the object being indexed.
437+
438+
439+
Note that this could result in an empty axis (e.g. an empty DataFrame being
440+
returned)
432441

433442
.. ipython:: python
434443
@@ -438,7 +447,9 @@ python/numpy allow slicing past the end of an array without an associated error.
438447
dfl.iloc[:,1:3]
439448
dfl.iloc[4:6]
440449
441-
These are out-of-bounds selections
450+
A single indexer that is out of bounds will raise an ``IndexError``.
451+
A list of indexers where any element is out of bounds will raise an
452+
``IndexError``
442453

443454
.. code-block:: python
444455

0 commit comments

Comments
 (0)