Skip to content

Commit 5f569a0

Browse files
proosthweecat
authored andcommitted
DOC: .get_slice_bound in MultiIndex needs documentation. (pandas-dev#29967) (pandas-dev#30257)
1 parent d7ff4e6 commit 5f569a0

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
@@ -2447,7 +2447,53 @@ def reindex(self, target, method=None, level=None, limit=None, tolerance=None):
24472447

24482448
return target, indexer
24492449

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

24522498
if not isinstance(label, tuple):
24532499
label = (label,)

0 commit comments

Comments
 (0)