Skip to content

Commit ef4f911

Browse files
committed
DOC: use shared_docs for Index.get_indexer, get_indexer_non_unique
1 parent e351ed0 commit ef4f911

File tree

4 files changed

+33
-64
lines changed

4 files changed

+33
-64
lines changed

pandas/indexes/base.py

+29-7
Original file line numberDiff line numberDiff line change
@@ -2350,8 +2350,7 @@ def get_level_values(self, level):
23502350
self._validate_index_level(level)
23512351
return self
23522352

2353-
def get_indexer(self, target, method=None, limit=None, tolerance=None):
2354-
"""
2353+
_index_shared_docs['get_indexer'] = """
23552354
Compute indexer and mask for new index given the current index. The
23562355
indexer should be then used as an input to ndarray.take to align the
23572356
current data to the new index.
@@ -2387,6 +2386,9 @@ def get_indexer(self, target, method=None, limit=None, tolerance=None):
23872386
positions matches the corresponding target values. Missing values
23882387
in the target are marked by -1.
23892388
"""
2389+
2390+
@Appender(_index_shared_docs['get_indexer'])
2391+
def get_indexer(self, target, method=None, limit=None, tolerance=None):
23902392
method = missing.clean_reindex_fill_method(method)
23912393
target = _ensure_index(target)
23922394
if tolerance is not None:
@@ -2496,11 +2498,28 @@ def _filter_indexer_tolerance(self, target, indexer, tolerance):
24962498
indexer = np.where(distance <= tolerance, indexer, -1)
24972499
return indexer
24982500

2501+
_index_shared_docs['get_indexer_non_unique'] = """
2502+
Compute indexer and mask for new index given the current index. The
2503+
indexer should be then used as an input to ndarray.take to align the
2504+
current data to the new index.
2505+
2506+
Parameters
2507+
----------
2508+
target : Index
2509+
2510+
Returns
2511+
-------
2512+
indexer : ndarray of int
2513+
Integers from 0 to n - 1 indicating that the index at these
2514+
positions matches the corresponding target values. Missing values
2515+
in the target are marked by -1.
2516+
missing : ndarray of int
2517+
An indexer into the target of the values not found.
2518+
These correspond to the -1 in the indexer array
2519+
"""
2520+
2521+
@Appender(_index_shared_docs['get_indexer_non_unique'])
24992522
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 """
25042523
target = _ensure_index(target)
25052524
pself, ptarget = self._possibly_promote(target)
25062525
if pself is not self or ptarget is not target:
@@ -2516,7 +2535,10 @@ def get_indexer_non_unique(self, target):
25162535
return Index(indexer), missing
25172536

25182537
def get_indexer_for(self, target, **kwargs):
2519-
""" guaranteed return of an indexer even when non-unique """
2538+
"""
2539+
guaranteed return of an indexer even when non-unique
2540+
This dispatches to get_indexer or get_indexer_nonunique as appropriate
2541+
"""
25202542
if self.is_unique:
25212543
return self.get_indexer(target, **kwargs)
25222544
indexer, _ = self.get_indexer_non_unique(target, **kwargs)

pandas/indexes/category.py

+2-30
Original file line numberDiff line numberDiff line change
@@ -425,34 +425,8 @@ def _reindex_non_unique(self, target):
425425

426426
return new_target, indexer, new_indexer
427427

428+
@Appender(_index_shared_docs['get_indexer'])
428429
def get_indexer(self, target, method=None, limit=None, tolerance=None):
429-
"""
430-
Compute indexer and mask for new index given the current index. The
431-
indexer should be then used as an input to ndarray.take to align the
432-
current data to the new index. The mask determines whether labels are
433-
found or not in the current index
434-
435-
Parameters
436-
----------
437-
target : MultiIndex or Index (of tuples)
438-
method : {'pad', 'ffill', 'backfill', 'bfill'}
439-
pad / ffill: propagate LAST valid observation forward to next valid
440-
backfill / bfill: use NEXT valid observation to fill gap
441-
442-
Notes
443-
-----
444-
This is a low-level method and probably should be used at your own risk
445-
446-
Examples
447-
--------
448-
>>> indexer, mask = index.get_indexer(new_index)
449-
>>> new_values = cur_values.take(indexer)
450-
>>> new_values[-mask] = np.nan
451-
452-
Returns
453-
-------
454-
(indexer, mask) : (ndarray, ndarray)
455-
"""
456430
method = missing.clean_reindex_fill_method(method)
457431
target = ibase._ensure_index(target)
458432

@@ -472,10 +446,8 @@ def get_indexer(self, target, method=None, limit=None, tolerance=None):
472446

473447
return _ensure_platform_int(indexer)
474448

449+
@Appender(_index_shared_docs['get_indexer_non_unique'])
475450
def get_indexer_non_unique(self, target):
476-
""" this is the same for a CategoricalIndex for get_indexer; the API
477-
returns the missing values as well
478-
"""
479451
target = ibase._ensure_index(target)
480452

481453
if isinstance(target, CategoricalIndex):

pandas/indexes/multi.py

+1-27
Original file line numberDiff line numberDiff line change
@@ -1564,34 +1564,8 @@ def sortlevel(self, level=0, ascending=True, sort_remaining=True):
15641564

15651565
return new_index, indexer
15661566

1567+
@Appender(_index_shared_docs['get_indexer'])
15671568
def get_indexer(self, target, method=None, limit=None, tolerance=None):
1568-
"""
1569-
Compute indexer and mask for new index given the current index. The
1570-
indexer should be then used as an input to ndarray.take to align the
1571-
current data to the new index. The mask determines whether labels are
1572-
found or not in the current index
1573-
1574-
Parameters
1575-
----------
1576-
target : MultiIndex or Index (of tuples)
1577-
method : {'pad', 'ffill', 'backfill', 'bfill'}
1578-
pad / ffill: propagate LAST valid observation forward to next valid
1579-
backfill / bfill: use NEXT valid observation to fill gap
1580-
1581-
Notes
1582-
-----
1583-
This is a low-level method and probably should be used at your own risk
1584-
1585-
Examples
1586-
--------
1587-
>>> indexer, mask = index.get_indexer(new_index)
1588-
>>> new_values = cur_values.take(indexer)
1589-
>>> new_values[-mask] = np.nan
1590-
1591-
Returns
1592-
-------
1593-
(indexer, mask) : (ndarray, ndarray)
1594-
"""
15951569
method = missing.clean_reindex_fill_method(method)
15961570
target = _ensure_index(target)
15971571

pandas/tseries/period.py

+1
Original file line numberDiff line numberDiff line change
@@ -759,6 +759,7 @@ def get_value(self, series, key):
759759
return com._maybe_box(self, self._engine.get_value(s, key),
760760
series, key)
761761

762+
@Appender(_index_shared_docs['get_indexer'])
762763
def get_indexer(self, target, method=None, limit=None, tolerance=None):
763764
target = _ensure_index(target)
764765

0 commit comments

Comments
 (0)