Skip to content

Commit d926d26

Browse files
DOC: start API docs for indexers (GH6920)
For now, start with copying the info in the tutorial docs.
1 parent 1775e92 commit d926d26

File tree

1 file changed

+75
-5
lines changed

1 file changed

+75
-5
lines changed

pandas/core/indexing.py

+75-5
Original file line numberDiff line numberDiff line change
@@ -1166,7 +1166,25 @@ def _get_slice_axis(self, slice_obj, axis=0):
11661166

11671167
class _IXIndexer(_NDFrameIndexer):
11681168

1169-
""" A primarily location based indexer, with integer fallback """
1169+
"""A primarily label-location based indexer, with integer position
1170+
fallback.
1171+
1172+
``.ix[]`` supports mixed integer and label based access. It is
1173+
primarily label based, but will fall back to integer positional
1174+
access unless the corresponding axis is of integer type.
1175+
1176+
``.ix`` is the most general indexer and will support any of the
1177+
inputs in ``.loc`` and ``.iloc``. ``.ix`` also supports floating
1178+
point label schemes. ``.ix`` is exceptionally useful when dealing
1179+
with mixed positional and label based hierachical indexes.
1180+
1181+
However, when an axis is integer based, ONLY label based access
1182+
and not positional access is supported. Thus, in such cases, it's
1183+
usually better to be explicit and use ``.iloc`` or ``.loc``.
1184+
1185+
See more at :ref:`Advanced Indexing <advanced>`.
1186+
1187+
"""
11701188

11711189
def _has_valid_type(self, key, axis):
11721190
if isinstance(key, slice):
@@ -1224,7 +1242,27 @@ def _get_slice_axis(self, slice_obj, axis=0):
12241242

12251243
class _LocIndexer(_LocationIndexer):
12261244

1227-
""" purely label based location based indexing """
1245+
"""Purely label-location based indexer for selection by label.
1246+
1247+
``.loc[]`` is primarily label based, but may also be used with a
1248+
boolean array.
1249+
1250+
Allowed inputs are:
1251+
1252+
- A single label, e.g. ``5`` or ``'a'``, (note that ``5`` is
1253+
interpreted as a *label* of the index, and **never** as an
1254+
integer position along the index).
1255+
- A list or array of labels, e.g. ``['a', 'b', 'c']``.
1256+
- A slice object with labels, e.g. ``'a':'f'`` (note that contrary
1257+
to usual python slices, **both** the start and the stop are included!).
1258+
- A boolean array.
1259+
1260+
``.loc`` will raise a ``KeyError`` when the items are not found.
1261+
1262+
See more at :ref:`Selection by Label <indexing.label>`
1263+
1264+
"""
1265+
12281266
_valid_types = ("labels (MUST BE IN THE INDEX), slices of labels (BOTH "
12291267
"endpoints included! Can be slices of integers if the "
12301268
"index is integers), listlike of labels, boolean")
@@ -1340,7 +1378,27 @@ def _getitem_axis(self, key, axis=0):
13401378

13411379
class _iLocIndexer(_LocationIndexer):
13421380

1343-
""" purely integer based location based indexing """
1381+
"""Purely integer-location based indexing for selection by position.
1382+
1383+
``.iloc[]`` is primarily integer position based (from ``0`` to
1384+
``length-1`` of the axis), but may also be used with a boolean
1385+
array.
1386+
1387+
Allowed inputs are:
1388+
1389+
- An integer, e.g. ``5``.
1390+
- A list or array of integers, e.g. ``[4, 3, 0]``.
1391+
- A slice object with ints, e.g. ``1:7``.
1392+
- A boolean array.
1393+
1394+
``.iloc`` will raise ``IndexError`` if a requested indexer is
1395+
out-of-bounds, except *slice* indexers which allow out-of-bounds
1396+
indexing (this conforms with python/numpy *slice* semantics).
1397+
1398+
See more at :ref:`Selection by Position <indexing.integer>`
1399+
1400+
"""
1401+
13441402
_valid_types = ("integer, integer slice (START point is INCLUDED, END "
13451403
"point is EXCLUDED), listlike of integers, boolean array")
13461404
_exception = IndexError
@@ -1512,7 +1570,13 @@ def __setitem__(self, key, value):
15121570

15131571
class _AtIndexer(_ScalarAccessIndexer):
15141572

1515-
""" label based scalar accessor """
1573+
"""Fast label-based scalar accessor
1574+
1575+
Similarly to ``loc``, ``at`` provides **label** based scalar lookups.
1576+
You can also set using these indexers.
1577+
1578+
"""
1579+
15161580
_takeable = False
15171581

15181582
def _convert_key(self, key, is_setter=False):
@@ -1535,7 +1599,13 @@ def _convert_key(self, key, is_setter=False):
15351599

15361600
class _iAtIndexer(_ScalarAccessIndexer):
15371601

1538-
""" integer based scalar accessor """
1602+
"""Fast integer location scalar accessor.
1603+
1604+
Similarly to ``iloc``, ``iat`` provides **integer** based lookups.
1605+
You can also set using these indexers.
1606+
1607+
"""
1608+
15391609
_takeable = True
15401610

15411611
def _has_valid_setitem_indexer(self, indexer):

0 commit comments

Comments
 (0)