Skip to content

Commit 9d894b2

Browse files
committed
DOC: generalized parameters for reindex/get_indexer (pandas-dev#40328)
1 parent 010f942 commit 9d894b2

File tree

1 file changed

+37
-36
lines changed

1 file changed

+37
-36
lines changed

pandas/core/indexes/base.py

+37-36
Original file line numberDiff line numberDiff line change
@@ -3348,34 +3348,45 @@ def get_loc(self, key, method=None, tolerance=None):
33483348
return loc
33493349

33503350
_index_shared_docs[
3351-
"get_indexer"
3351+
"method"
33523352
] = """
3353-
Compute indexer and mask for new index given the current index. The
3354-
indexer should be then used as an input to ndarray.take to align the
3355-
current data to the new index.
3356-
3357-
Parameters
3358-
----------
3359-
target : %(target_klass)s
3360-
method : {None, 'pad'/'ffill', 'backfill'/'bfill', 'nearest'}, optional
3353+
{None, 'pad'/'ffill', 'backfill'/'bfill', 'nearest'}, optional
33613354
* default: exact matches only.
33623355
* pad / ffill: find the PREVIOUS index value if no exact match.
33633356
* backfill / bfill: use NEXT index value if no exact match
33643357
* nearest: use the NEAREST index value if no exact match. Tied
33653358
distances are broken by preferring the larger index value.
3366-
limit : int, optional
3359+
"""
3360+
_index_shared_docs[
3361+
"limit"
3362+
] = """
3363+
int, optional
33673364
Maximum number of consecutive labels in ``target`` to match for
33683365
inexact matches.
3369-
tolerance : optional
3366+
"""
3367+
3368+
_index_shared_docs[
3369+
"tolerance"
3370+
] = """
3371+
optional
33703372
Maximum distance between original and new labels for inexact
33713373
matches. The values of the index at the matching locations must
33723374
satisfy the equation ``abs(index[indexer] - target) <= tolerance``.
3375+
"""
33733376

3374-
Tolerance may be a scalar value, which applies the same tolerance
3375-
to all values, or list-like, which applies variable tolerance per
3376-
element. List-like includes list, tuple, array, Series, and must be
3377-
the same size as the index and its dtype must exactly match the
3378-
index's type.
3377+
_index_shared_docs[
3378+
"get_indexer"
3379+
] = """
3380+
Compute indexer and mask for new index given the current index. The
3381+
indexer should be then used as an input to ndarray.take to align the
3382+
current data to the new index.
3383+
3384+
Parameters
3385+
----------
3386+
target : %(target_klass)s
3387+
method : %(method)s
3388+
limit : %(limit)s
3389+
tolerance : %(tolerance)s
33793390
33803391
Returns
33813392
-------
@@ -3761,34 +3772,20 @@ def _validate_can_reindex(self, indexer: np.ndarray) -> None:
37613772
if not self._index_as_unique and len(indexer):
37623773
raise ValueError("cannot reindex from a duplicate axis")
37633774

3764-
def reindex(self, target, method=None, level=None, limit=None, tolerance=None):
3765-
"""
3775+
_index_shared_docs[
3776+
"reindex"
3777+
] = """
37663778
Create an index with target's values.
37673779
37683780
Parameters
37693781
----------
37703782
target : an iterable
3771-
method : {None, ‘backfill’/’bfill’, ‘pad’/’ffill’, ‘nearest’}
3772-
Method to use for filling holes in reindexed DataFrame.
3773-
Please note: this is only applicable to DataFrames/Series
3774-
with a monotonically increasing/decreasing index.
3775-
- None (default): don’t fill gaps
3776-
- pad / ffill: Propagate last valid observation forward to next valid.
3777-
- backfill / bfill: Use next valid observation to fill gap.
3778-
- nearest: Use nearest valid observations to fill gap.
3783+
method : %(method)s
37793784
level : int or name
37803785
Broadcast across a level, matching Index values on
37813786
the passed MultiIndex level.
3782-
limit : int, default None
3783-
Maximum number of consecutive elements to forward or backward fill.
3784-
tolerance : optional
3785-
Maximum distance between original and new labels for inexact matches.
3786-
The values of the index at the matching locations most satisfy the
3787-
equation `abs(index[indexer] - target) <= tolerance`.
3788-
Tolerance may be a scalar value, which applies the same tolerance
3789-
to all values, or list-like, which applies variable tolerance per element.
3790-
List-like includes list, tuple, array, Series, and must be the same size
3791-
as the index and its dtype must exactly match the index’s type.
3787+
limit : %(limit)s
3788+
tolerance : %(tolerance)
37923789
37933790
Returns
37943791
-------
@@ -3817,6 +3814,10 @@ def reindex(self, target, method=None, level=None, limit=None, tolerance=None):
38173814
>>> target, indexer
38183815
(Index(['I', 'd', 'III', 'IV'], dtype='object'), array([-1, 3, 0, -1]))
38193816
"""
3817+
3818+
@Appender(_index_shared_docs["reindex"] % _index_doc_kwargs)
3819+
@final
3820+
def reindex(self, target, method=None, level=None, limit=None, tolerance=None):
38203821
# GH6552: preserve names when reindexing to non-named target
38213822
# (i.e. neither Index nor Series).
38223823
preserve_names = not hasattr(target, "name")

0 commit comments

Comments
 (0)