Skip to content

Commit 3d5a598

Browse files
committed
Merge pull request #9316 from jorisvandenbossche/doc-indexing
Doc: API docstrings for indexers (GH6920)
2 parents e651138 + d926d26 commit 3d5a598

File tree

2 files changed

+76
-6
lines changed

2 files changed

+76
-6
lines changed

pandas/core/generic.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1043,7 +1043,7 @@ def _indexer(self):
10431043
setattr(self, iname, i)
10441044
return i
10451045

1046-
setattr(cls, name, property(_indexer))
1046+
setattr(cls, name, property(_indexer, doc=indexer.__doc__))
10471047

10481048
# add to our internal names set
10491049
cls._internal_names_set.add(iname)

pandas/core/indexing.py

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

11711171
class _IXIndexer(_NDFrameIndexer):
11721172

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

11751193
def _has_valid_type(self, key, axis):
11761194
if isinstance(key, slice):
@@ -1228,7 +1246,27 @@ def _get_slice_axis(self, slice_obj, axis=0):
12281246

12291247
class _LocIndexer(_LocationIndexer):
12301248

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

13271365
class _iLocIndexer(_LocationIndexer):
13281366

1329-
""" purely integer based location based indexing """
1367+
"""Purely integer-location based indexing for selection by position.
1368+
1369+
``.iloc[]`` is primarily integer position based (from ``0`` to
1370+
``length-1`` of the axis), but may also be used with a boolean
1371+
array.
1372+
1373+
Allowed inputs are:
1374+
1375+
- An integer, e.g. ``5``.
1376+
- A list or array of integers, e.g. ``[4, 3, 0]``.
1377+
- A slice object with ints, e.g. ``1:7``.
1378+
- A boolean array.
1379+
1380+
``.iloc`` will raise ``IndexError`` if a requested indexer is
1381+
out-of-bounds, except *slice* indexers which allow out-of-bounds
1382+
indexing (this conforms with python/numpy *slice* semantics).
1383+
1384+
See more at :ref:`Selection by Position <indexing.integer>`
1385+
1386+
"""
1387+
13301388
_valid_types = ("integer, integer slice (START point is INCLUDED, END "
13311389
"point is EXCLUDED), listlike of integers, boolean array")
13321390
_exception = IndexError
@@ -1498,7 +1556,13 @@ def __setitem__(self, key, value):
14981556

14991557
class _AtIndexer(_ScalarAccessIndexer):
15001558

1501-
""" label based scalar accessor """
1559+
"""Fast label-based scalar accessor
1560+
1561+
Similarly to ``loc``, ``at`` provides **label** based scalar lookups.
1562+
You can also set using these indexers.
1563+
1564+
"""
1565+
15021566
_takeable = False
15031567

15041568
def _convert_key(self, key, is_setter=False):
@@ -1521,7 +1585,13 @@ def _convert_key(self, key, is_setter=False):
15211585

15221586
class _iAtIndexer(_ScalarAccessIndexer):
15231587

1524-
""" integer based scalar accessor """
1588+
"""Fast integer location scalar accessor.
1589+
1590+
Similarly to ``iloc``, ``iat`` provides **integer** based lookups.
1591+
You can also set using these indexers.
1592+
1593+
"""
1594+
15251595
_takeable = True
15261596

15271597
def _has_valid_setitem_indexer(self, indexer):

0 commit comments

Comments
 (0)