@@ -72,8 +72,8 @@ class MultiIndex(Index):
72
72
Examples
73
73
---------
74
74
A new ``MultiIndex`` is typically constructed using one of the helper
75
- methods :meth:`MultiIndex.from_arrays`` , :meth:`MultiIndex.from_product` `
76
- and :meth:`MultiIndex.from_tuples`` . For example (using ``.from_arrays``):
75
+ methods :meth:`MultiIndex.from_arrays`, :meth:`MultiIndex.from_product`
76
+ and :meth:`MultiIndex.from_tuples`. For example (using ``.from_arrays``):
77
77
78
78
>>> arrays = [[1, 1, 2, 2], ['red', 'blue', 'red', 'blue']]
79
79
>>> pd.MultiIndex.from_arrays(arrays, names=('number', 'color'))
@@ -1985,13 +1985,9 @@ def get_loc(self, key, method=None):
1985
1985
Get location for a label or a tuple of labels as an integer, slice or
1986
1986
boolean mask.
1987
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.
1991
-
1992
1988
Parameters
1993
1989
----------
1994
- key : label or tuple of labels
1990
+ key : label or tuple of labels (one for each level)
1995
1991
method : None
1996
1992
1997
1993
Returns
@@ -2003,17 +1999,24 @@ def get_loc(self, key, method=None):
2003
1999
Examples
2004
2000
---------
2005
2001
>>> mi = pd.MultiIndex.from_arrays([list('abb'), list('def')])
2002
+
2006
2003
>>> mi.get_loc('b')
2007
2004
slice(1, 3, None)
2005
+
2008
2006
>>> mi.get_loc(('b', 'e'))
2009
2007
1
2010
2008
2009
+ Notes
2010
+ ------
2011
+ The key cannot be a slice, list of same-level labels, a boolean mask,
2012
+ or a sequence of such. If you want to use those, use :meth:`get_locs`
2013
+ instead.
2014
+
2011
2015
See also
2012
2016
--------
2013
2017
Index.get_loc : get_loc method for (single-level) index.
2014
- get_locs : Given a tuple of slices/lists/labels/boolean indexer to a
2015
- level-wise spec, produce an indexer to extract those
2016
- locations.
2018
+ get_locs : Get location for a label/slice/list/mask or a sequence of
2019
+ such.
2017
2020
"""
2018
2021
if method is not None :
2019
2022
raise NotImplementedError ('only the default get_loc method is '
@@ -2122,7 +2125,9 @@ def get_loc_level(self, key, level=0, drop_level=True):
2122
2125
2123
2126
See Also
2124
2127
---------
2125
- MultiIndex.get_loc : Get location for a label or a tuple of labels.
2128
+ MultiIndex.get_loc : Get location for a label or a tuple of labels.
2129
+ MultiIndex.get_locs : Get location for a label/slice/list/mask or a
2130
+ sequence of such
2126
2131
"""
2127
2132
2128
2133
def maybe_droplevels (indexer , levels , drop_level ):
@@ -2332,14 +2337,14 @@ def convert_indexer(start, stop, step, indexer=indexer, labels=labels):
2332
2337
j = labels .searchsorted (loc , side = 'right' )
2333
2338
return slice (i , j )
2334
2339
2335
- def get_locs (self , tup ):
2340
+ def get_locs (self , seq ):
2336
2341
"""
2337
2342
Get location for a given label/slice/list/mask or a sequence of such as
2338
2343
a integer, slice or boolean mask.
2339
2344
2340
2345
Parameters
2341
2346
----------
2342
- key : label/slice/list/mask or a sequence of such.
2347
+ seq : label/slice/list/mask or a sequence of such.
2343
2348
2344
2349
Returns
2345
2350
-------
@@ -2365,7 +2370,7 @@ def get_locs(self, tup):
2365
2370
"""
2366
2371
2367
2372
# must be lexsorted to at least as many levels
2368
- true_slices = [i for (i , s ) in enumerate (is_true_slices (tup )) if s ]
2373
+ true_slices = [i for (i , s ) in enumerate (is_true_slices (seq )) if s ]
2369
2374
if true_slices and true_slices [- 1 ] >= self .lexsort_depth :
2370
2375
raise UnsortedIndexError ('MultiIndex slicing requires the index '
2371
2376
'to be lexsorted: slicing on levels {0}, '
@@ -2398,7 +2403,7 @@ def _update_indexer(idxr, indexer=indexer):
2398
2403
return indexer
2399
2404
return indexer & idxr
2400
2405
2401
- for i , k in enumerate (tup ):
2406
+ for i , k in enumerate (seq ):
2402
2407
2403
2408
if is_bool_indexer (k ):
2404
2409
# a boolean indexer, must be the same length!
0 commit comments