|
1 | 1 | from collections import OrderedDict
|
2 | 2 | import datetime
|
3 | 3 | from sys import getsizeof
|
| 4 | +from typing import Tuple, Union |
4 | 5 | import warnings
|
5 | 6 |
|
6 | 7 | import numpy as np
|
@@ -2441,7 +2442,53 @@ 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( |
| 2446 | + self, label: Union[object, Tuple[object, ...]], side: str, kind: str |
| 2447 | + ) -> int: |
| 2448 | + """ |
| 2449 | + For an ordered MultiIndex, compute slice bound |
| 2450 | + that corresponds to given label. |
| 2451 | +
|
| 2452 | + Returns leftmost (one-past-the-rightmost if `side=='right') position |
| 2453 | + of given label. |
| 2454 | +
|
| 2455 | + Parameters |
| 2456 | + ---------- |
| 2457 | + label : object or tuple of objects |
| 2458 | + side : {'left', 'right'} |
| 2459 | + kind : {'ix', 'loc', 'getitem'} |
| 2460 | +
|
| 2461 | + Returns |
| 2462 | + ------- |
| 2463 | + int |
| 2464 | + Index of label. |
| 2465 | +
|
| 2466 | + Notes |
| 2467 | + ----- |
| 2468 | + This method only works if level 0 index of the MultiIndex is lexsorted. |
| 2469 | +
|
| 2470 | + Examples |
| 2471 | + -------- |
| 2472 | + >>> mi = pd.MultiIndex.from_arrays([list('abbc'), list('gefd')]) |
| 2473 | +
|
| 2474 | + Get the locations from the leftmost 'b' in the first level |
| 2475 | + until the end of the multiindex: |
| 2476 | +
|
| 2477 | + >>> mi.get_slice_bound('b', side="left", kind="ix") |
| 2478 | + 1 |
| 2479 | +
|
| 2480 | + Like above, but if you get the locations from the rightmost |
| 2481 | + 'b' in the first level and 'f' in the second level: |
| 2482 | +
|
| 2483 | + >>> mi.get_slice_bound(('b','f'), side="right", kind="ix") |
| 2484 | + 3 |
| 2485 | +
|
| 2486 | + See Also |
| 2487 | + -------- |
| 2488 | + MultiIndex.get_loc : Get location for a label or a tuple of labels. |
| 2489 | + MultiIndex.get_locs : Get location for a label/slice/list/mask or a |
| 2490 | + sequence of such. |
| 2491 | + """ |
2445 | 2492 |
|
2446 | 2493 | if not isinstance(label, tuple):
|
2447 | 2494 | label = (label,)
|
|
0 commit comments