|
56 | 56 | pprint_thing,
|
57 | 57 | )
|
58 | 58 |
|
| 59 | +from pandas._typing import OneOrMoreObjects |
| 60 | + |
59 | 61 | _index_doc_kwargs = dict(ibase._index_doc_kwargs)
|
60 | 62 | _index_doc_kwargs.update(
|
61 | 63 | dict(klass="MultiIndex", target_klass="MultiIndex or list of tuples")
|
@@ -2441,7 +2443,51 @@ def reindex(self, target, method=None, level=None, limit=None, tolerance=None):
|
2441 | 2443 |
|
2442 | 2444 | return target, indexer
|
2443 | 2445 |
|
2444 |
| - def get_slice_bound(self, label, side, kind): |
| 2446 | + def get_slice_bound(self, label: OneOrMoreObjects, side: str, kind: str) -> int: |
| 2447 | + """ |
| 2448 | + For an ordered MultiIndex, compute slice bound |
| 2449 | + that corresponds to given label. |
| 2450 | +
|
| 2451 | + Returns leftmost (one-past-the-rightmost if `side=='right') position |
| 2452 | + of given label. |
| 2453 | +
|
| 2454 | + Parameters |
| 2455 | + ---------- |
| 2456 | + label : object or tuple of objects |
| 2457 | + side : {'left', 'right'} |
| 2458 | + kind : {'ix', 'loc', 'getitem'} |
| 2459 | +
|
| 2460 | + Returns |
| 2461 | + ------- |
| 2462 | + int |
| 2463 | + Index of label. |
| 2464 | +
|
| 2465 | + Notes |
| 2466 | + ----- |
| 2467 | + This method only works if level 0 index of the MultiIndex is lexsorted. |
| 2468 | +
|
| 2469 | + Examples |
| 2470 | + -------- |
| 2471 | + >>> mi = pd.MultiIndex.from_arrays([list('abbc'), list('gefd')]) |
| 2472 | +
|
| 2473 | + Get the locations from the leftmost 'b' in the first level |
| 2474 | + until the end of the multiindex: |
| 2475 | +
|
| 2476 | + >>> mi.get_slice_bound('b', side="left", kind="ix") |
| 2477 | + 1 |
| 2478 | +
|
| 2479 | + Like above, but if you get the locations from the rightmost |
| 2480 | + 'b' in the first level and 'f' in the second level: |
| 2481 | +
|
| 2482 | + >>> mi.get_slice_bound(('b','f'), side="right", kind="ix") |
| 2483 | + 3 |
| 2484 | +
|
| 2485 | + See Also |
| 2486 | + -------- |
| 2487 | + MultiIndex.get_loc : Get location for a label or a tuple of labels. |
| 2488 | + MultiIndex.get_locs : Get location for a label/slice/list/mask or a |
| 2489 | + sequence of such. |
| 2490 | + """ |
2445 | 2491 |
|
2446 | 2492 | if not isinstance(label, tuple):
|
2447 | 2493 | label = (label,)
|
|
0 commit comments