Skip to content

Commit 44796f0

Browse files
committed
DOC: .get_slice_bound in MultiIndex needs documentation. (pandas-dev#29967)
1 parent 18631d6 commit 44796f0

File tree

1 file changed

+47
-1
lines changed

1 file changed

+47
-1
lines changed

pandas/core/indexes/multi.py

+47-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from collections import OrderedDict
22
import datetime
33
from sys import getsizeof
4+
from typing import Hashable, Sequence, Union
45
import warnings
56

67
import numpy as np
@@ -2436,8 +2437,53 @@ def reindex(self, target, method=None, level=None, limit=None, tolerance=None):
24362437

24372438
return target, indexer
24382439

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

0 commit comments

Comments
 (0)