Skip to content

Commit 56b6561

Browse files
proostjreback
authored andcommitted
DOC: .get_slice_bound in MultiIndex needs documentation. (#29967) (#30257)
1 parent 0aa48f7 commit 56b6561

File tree

1 file changed

+48
-2
lines changed

1 file changed

+48
-2
lines changed

pandas/core/indexes/multi.py

+48-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from collections import OrderedDict
22
import datetime
33
from sys import getsizeof
4-
from typing import List, Optional
4+
from typing import Hashable, List, Optional, Sequence, Union
55
import warnings
66

77
import numpy as np
@@ -2432,7 +2432,53 @@ def reindex(self, target, method=None, level=None, limit=None, tolerance=None):
24322432

24332433
return target, indexer
24342434

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

24372483
if not isinstance(label, tuple):
24382484
label = (label,)

0 commit comments

Comments
 (0)