Skip to content

Commit 6833958

Browse files
committed
DOC: .get_slice_bound in MultiIndex needs documentation. (pandas-dev#29967)
1 parent 2043969 commit 6833958

File tree

1 file changed

+45
-1
lines changed

1 file changed

+45
-1
lines changed

pandas/core/indexes/multi.py

+45-1
Original file line numberDiff line numberDiff line change
@@ -2441,7 +2441,51 @@ def reindex(self, target, method=None, level=None, limit=None, tolerance=None):
24412441

24422442
return target, indexer
24432443

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

24462490
if not isinstance(label, tuple):
24472491
label = (label,)

0 commit comments

Comments
 (0)