65
65
_unsortable_types = frozenset (('mixed' , 'mixed-integer' ))
66
66
67
67
_index_doc_kwargs = dict (klass = 'Index' , inplace = '' ,
68
+ target_klass = 'Index' ,
68
69
unique = 'Index' , duplicated = 'np.ndarray' )
69
70
_index_shared_docs = dict ()
70
71
@@ -1605,7 +1606,7 @@ def _append_same_dtype(self, to_concat, name):
1605
1606
numpy.ndarray.take
1606
1607
"""
1607
1608
1608
- @Appender (_index_shared_docs ['take' ])
1609
+ @Appender (_index_shared_docs ['take' ] % _index_doc_kwargs )
1609
1610
def take (self , indices , axis = 0 , allow_fill = True ,
1610
1611
fill_value = None , ** kwargs ):
1611
1612
nv .validate_take (tuple (), kwargs )
@@ -2350,15 +2351,14 @@ def get_level_values(self, level):
2350
2351
self ._validate_index_level (level )
2351
2352
return self
2352
2353
2353
- def get_indexer (self , target , method = None , limit = None , tolerance = None ):
2354
- """
2354
+ _index_shared_docs ['get_indexer' ] = """
2355
2355
Compute indexer and mask for new index given the current index. The
2356
2356
indexer should be then used as an input to ndarray.take to align the
2357
2357
current data to the new index.
2358
2358
2359
2359
Parameters
2360
2360
----------
2361
- target : Index
2361
+ target : %(target_klass)s
2362
2362
method : {None, 'pad'/'ffill', 'backfill'/'bfill', 'nearest'}, optional
2363
2363
* default: exact matches only.
2364
2364
* pad / ffill: find the PREVIOUS index value if no exact match.
@@ -2387,6 +2387,9 @@ def get_indexer(self, target, method=None, limit=None, tolerance=None):
2387
2387
positions matches the corresponding target values. Missing values
2388
2388
in the target are marked by -1.
2389
2389
"""
2390
+
2391
+ @Appender (_index_shared_docs ['get_indexer' ] % _index_doc_kwargs )
2392
+ def get_indexer (self , target , method = None , limit = None , tolerance = None ):
2390
2393
method = missing .clean_reindex_fill_method (method )
2391
2394
target = _ensure_index (target )
2392
2395
if tolerance is not None :
@@ -2496,11 +2499,28 @@ def _filter_indexer_tolerance(self, target, indexer, tolerance):
2496
2499
indexer = np .where (distance <= tolerance , indexer , - 1 )
2497
2500
return indexer
2498
2501
2502
+ _index_shared_docs ['get_indexer_non_unique' ] = """
2503
+ Compute indexer and mask for new index given the current index. The
2504
+ indexer should be then used as an input to ndarray.take to align the
2505
+ current data to the new index.
2506
+
2507
+ Parameters
2508
+ ----------
2509
+ target : %(target_klass)s
2510
+
2511
+ Returns
2512
+ -------
2513
+ indexer : ndarray of int
2514
+ Integers from 0 to n - 1 indicating that the index at these
2515
+ positions matches the corresponding target values. Missing values
2516
+ in the target are marked by -1.
2517
+ missing : ndarray of int
2518
+ An indexer into the target of the values not found.
2519
+ These correspond to the -1 in the indexer array
2520
+ """
2521
+
2522
+ @Appender (_index_shared_docs ['get_indexer_non_unique' ] % _index_doc_kwargs )
2499
2523
def get_indexer_non_unique (self , target ):
2500
- """ return an indexer suitable for taking from a non unique index
2501
- return the labels in the same order as the target, and
2502
- return a missing indexer into the target (missing are marked as -1
2503
- in the indexer); target must be an iterable """
2504
2524
target = _ensure_index (target )
2505
2525
pself , ptarget = self ._possibly_promote (target )
2506
2526
if pself is not self or ptarget is not target :
@@ -2516,7 +2536,10 @@ def get_indexer_non_unique(self, target):
2516
2536
return Index (indexer ), missing
2517
2537
2518
2538
def get_indexer_for (self , target , ** kwargs ):
2519
- """ guaranteed return of an indexer even when non-unique """
2539
+ """
2540
+ guaranteed return of an indexer even when non-unique
2541
+ This dispatches to get_indexer or get_indexer_nonunique as appropriate
2542
+ """
2520
2543
if self .is_unique :
2521
2544
return self .get_indexer (target , ** kwargs )
2522
2545
indexer , _ = self .get_indexer_non_unique (target , ** kwargs )
0 commit comments