Skip to content

Commit 9652745

Browse files
committed
DOC: .get_slice_bound in MultiIndex needs documentation. (#29967)
1 parent 2043969 commit 9652745

File tree

1 file changed

+46
-1
lines changed

1 file changed

+46
-1
lines changed

pandas/core/indexes/multi.py

+46-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from collections import OrderedDict
2+
from typing import Tuple, Union
23
import datetime
34
from sys import getsizeof
45
import warnings
@@ -2441,7 +2442,51 @@ def reindex(self, target, method=None, level=None, limit=None, tolerance=None):
24412442

24422443
return target, indexer
24432444

2444-
def get_slice_bound(self, label, side, kind):
2445+
def get_slice_bound(self, label: Union[object, Tuple], side: str, kind: str) -> int:
2446+
"""
2447+
For an ordered MultiIndex, compute slice bound
2448+
that corresponds to given label.
2449+
2450+
Returns leftmost (one-past-the-rightmost if `side=='right') position
2451+
of given label.
2452+
2453+
Parameters
2454+
----------
2455+
label : object or tuple of objects
2456+
side : {'left', 'right'}
2457+
kind : {'ix', 'loc', 'getitem'}
2458+
2459+
Returns
2460+
-------
2461+
int
2462+
Index of label.
2463+
2464+
Notes
2465+
-----
2466+
This method only works if level 0 index of the MultiIndex is lexsorted.
2467+
2468+
Examples
2469+
--------
2470+
>>> mi = pd.MultiIndex.from_arrays([list('abbc'), list('gefd')])
2471+
2472+
Get the locations from the leftmost 'b' in the first level
2473+
until the end of the multiindex:
2474+
2475+
>>> mi.get_slice_bound('b', side="left", kind="ix")
2476+
1
2477+
2478+
Like above, but if you get the locations from the rightmost
2479+
'b' in the first level and 'f' in the second level:
2480+
2481+
>>> mi.get_slice_bound(('b','f'), side="right", kind="ix")
2482+
3
2483+
2484+
See Also
2485+
--------
2486+
MultiIndex.get_loc : Get location for a label or a tuple of labels.
2487+
MultiIndex.get_locs : Get location for a label/slice/list/mask or a
2488+
sequence of such.
2489+
"""
24452490

24462491
if not isinstance(label, tuple):
24472492
label = (label,)

0 commit comments

Comments
 (0)