@@ -1982,18 +1982,23 @@ def _partial_tup_index(self, tup, side='left'):
1982
1982
1983
1983
def get_loc (self , key , method = None ):
1984
1984
"""
1985
- Get integer location, slice or boolean mask for requested label or
1986
- tuple. If the key is past the lexsort depth, the return may be a
1987
- boolean mask array, otherwise it is always a slice or int.
1985
+ Get location for a label or a tuple of labels as an integer, slice or
1986
+ boolean mask.
1987
+
1988
+ Note that the key cannot be a slice, list of same-level labels,
1989
+ a boolean mask, or a sequence of such. If you want that, use
1990
+ :meth:`get_locs` instead.
1988
1991
1989
1992
Parameters
1990
1993
----------
1991
- key : label or tuple
1994
+ key : label or tuple of labels
1992
1995
method : None
1993
1996
1994
1997
Returns
1995
1998
-------
1996
1999
loc : int, slice object or boolean mask
2000
+ If the key is past the lexsort depth, the return may be a
2001
+ boolean mask array, otherwise it is always a slice or int.
1997
2002
1998
2003
Examples
1999
2004
---------
@@ -2117,8 +2122,7 @@ def get_loc_level(self, key, level=0, drop_level=True):
2117
2122
2118
2123
See Also
2119
2124
---------
2120
- MultiIndex.get_loc : Get integer location, slice or boolean mask for
2121
- requested label or tuple.
2125
+ MultiIndex.get_loc : Get location for a label or a tuple of labels.
2122
2126
"""
2123
2127
2124
2128
def maybe_droplevels (indexer , levels , drop_level ):
@@ -2330,17 +2334,34 @@ def convert_indexer(start, stop, step, indexer=indexer, labels=labels):
2330
2334
2331
2335
def get_locs (self , tup ):
2332
2336
"""
2333
- Given a tuple of slices/lists/labels/boolean indexer to a level-wise
2334
- spec produce an indexer to extract those locations
2337
+ Get location for a given label/slice/list/mask or a sequence of such as
2338
+ a integer, slice or boolean mask.
2335
2339
2336
2340
Parameters
2337
2341
----------
2338
- key : tuple of (slices/ list/labels)
2342
+ key : label/slice/ list/mask or a sequence of such.
2339
2343
2340
2344
Returns
2341
2345
-------
2342
- locs : integer list of locations or boolean indexer suitable
2346
+ locs : integer, slice or boolean mask suitable
2343
2347
for passing to iloc
2348
+
2349
+ Examples
2350
+ ---------
2351
+ >>> mi = pd.MultiIndex.from_arrays([list('abb'), list('def')])
2352
+
2353
+ >>> mi.get_locs('b')
2354
+ slice(1, 3, None)
2355
+
2356
+ >>> mi.get_locs([slice(None), ['e', 'f']])
2357
+ array([1, 2], dtype=int64)
2358
+
2359
+ >>> mi.get_locs([[True, False, True], slice('e', 'f')])
2360
+ array([2], dtype=int64)
2361
+
2362
+ See also
2363
+ --------
2364
+ get_loc : Get location for a label or a tuple of labels.
2344
2365
"""
2345
2366
2346
2367
# must be lexsorted to at least as many levels
0 commit comments