Skip to content

Commit 2a0d882

Browse files
author
tp
committed
clarifies input to get_loc is sequence
1 parent 13a4de9 commit 2a0d882

File tree

1 file changed

+20
-15
lines changed

1 file changed

+20
-15
lines changed

pandas/core/indexes/multi.py

+20-15
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ class MultiIndex(Index):
7272
Examples
7373
---------
7474
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``):
7777
7878
>>> arrays = [[1, 1, 2, 2], ['red', 'blue', 'red', 'blue']]
7979
>>> pd.MultiIndex.from_arrays(arrays, names=('number', 'color'))
@@ -1985,13 +1985,9 @@ def get_loc(self, key, method=None):
19851985
Get location for a label or a tuple of labels as an integer, slice or
19861986
boolean mask.
19871987
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-
19921988
Parameters
19931989
----------
1994-
key : label or tuple of labels
1990+
key : label or tuple of labels (one for each level)
19951991
method : None
19961992
19971993
Returns
@@ -2003,17 +1999,24 @@ def get_loc(self, key, method=None):
20031999
Examples
20042000
---------
20052001
>>> mi = pd.MultiIndex.from_arrays([list('abb'), list('def')])
2002+
20062003
>>> mi.get_loc('b')
20072004
slice(1, 3, None)
2005+
20082006
>>> mi.get_loc(('b', 'e'))
20092007
1
20102008
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+
20112015
See also
20122016
--------
20132017
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.
20172020
"""
20182021
if method is not None:
20192022
raise NotImplementedError('only the default get_loc method is '
@@ -2122,7 +2125,9 @@ def get_loc_level(self, key, level=0, drop_level=True):
21222125
21232126
See Also
21242127
---------
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
21262131
"""
21272132

21282133
def maybe_droplevels(indexer, levels, drop_level):
@@ -2332,14 +2337,14 @@ def convert_indexer(start, stop, step, indexer=indexer, labels=labels):
23322337
j = labels.searchsorted(loc, side='right')
23332338
return slice(i, j)
23342339

2335-
def get_locs(self, tup):
2340+
def get_locs(self, seq):
23362341
"""
23372342
Get location for a given label/slice/list/mask or a sequence of such as
23382343
a integer, slice or boolean mask.
23392344
23402345
Parameters
23412346
----------
2342-
key : label/slice/list/mask or a sequence of such.
2347+
seq : label/slice/list/mask or a sequence of such.
23432348
23442349
Returns
23452350
-------
@@ -2365,7 +2370,7 @@ def get_locs(self, tup):
23652370
"""
23662371

23672372
# 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]
23692374
if true_slices and true_slices[-1] >= self.lexsort_depth:
23702375
raise UnsortedIndexError('MultiIndex slicing requires the index '
23712376
'to be lexsorted: slicing on levels {0}, '
@@ -2398,7 +2403,7 @@ def _update_indexer(idxr, indexer=indexer):
23982403
return indexer
23992404
return indexer & idxr
24002405

2401-
for i, k in enumerate(tup):
2406+
for i, k in enumerate(seq):
24022407

24032408
if is_bool_indexer(k):
24042409
# a boolean indexer, must be the same length!

0 commit comments

Comments
 (0)