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