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