-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
DOC: Updates Index.reindex docstrings (#40328) #40879
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
6766803
9a657cd
d684b99
2bf0bf5
010f942
9d894b2
4628ec2
7908984
205d544
6daecfb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3763,18 +3763,59 @@ def _validate_can_reindex(self, indexer: np.ndarray) -> None: | |
|
||
def reindex(self, target, method=None, level=None, limit=None, tolerance=None): | ||
""" | ||
Create index with target's values. | ||
Create an index with target's values. | ||
|
||
Parameters | ||
---------- | ||
target : an iterable | ||
method : {None, ‘backfill’/’bfill’, ‘pad’/’ffill’, ‘nearest’} | ||
Method to use for filling holes in reindexed DataFrame. | ||
Please note: this is only applicable to DataFrames/Series | ||
with a monotonically increasing/decreasing index. | ||
- None (default): don’t fill gaps | ||
- pad / ffill: Propagate last valid observation forward to next valid. | ||
- backfill / bfill: Use next valid observation to fill gap. | ||
- nearest: Use nearest valid observations to fill gap. | ||
level : int or name | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These are types, I guess it should be |
||
Broadcast across a level, matching Index values on | ||
the passed MultiIndex level. | ||
limit : int, default None | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
Maximum number of consecutive elements to forward or backward fill. | ||
tolerance : optional | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Type should be something like |
||
Maximum distance between original and new labels for inexact matches. | ||
The values of the index at the matching locations most satisfy the | ||
equation `abs(index[indexer] - target) <= tolerance`. | ||
Tolerance may be a scalar value, which applies the same tolerance | ||
to all values, or list-like, which applies variable tolerance per element. | ||
List-like includes list, tuple, array, Series, and must be the same size | ||
as the index and its dtype must exactly match the index’s type. | ||
|
||
Returns | ||
------- | ||
new_index : pd.Index | ||
Resulting index. | ||
indexer : np.ndarray or None | ||
Indices of output values in original index. | ||
|
||
Examples | ||
-------- | ||
>>> index = ['a', 'b', 'c', 'd'] | ||
>>> df = pd.DataFrame({"A": [1,2,3,4], | ||
... "B": [5,6,7,8], | ||
... "C": [9,10,11,12]}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. PEP-8 requires spaces ater commas, can you add them please, and make sure this is PEP-8 compliant. |
||
... index=index) | ||
>>> df | ||
A B C | ||
a 1 5 9 | ||
b 2 6 10 | ||
c 3 7 11 | ||
d 4 8 12 | ||
>>> target, indexer = df.index.reindex(target=['I', 'II', 'III', 'IV']) | ||
>>> target, indexer | ||
(Index(['I', 'II', 'III', 'IV'], dtype='object'), array([-1, -1, -1, -1])) | ||
>>> target, indexer = df.index.reindex(target=['I', 'd', 'a', 'IV']) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you check the failure on the CI? These tests are failing, something is not right. You can test the code locally using the master version of pandas. After you fix these things, can you check that the CI is green, so we can merge. |
||
>>> target, indexer | ||
(Index(['I', 'd', 'III', 'IV'], dtype='object'), array([-1, 3, 0, -1])) | ||
""" | ||
# GH6552: preserve names when reindexing to non-named target | ||
# (i.e. neither Index nor Series). | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a way to share parts with NDFrame.reindex?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe share parts with other functions in this same file, such as get_indexer? @phofl
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think in this case you can better use
, optional
at the end, instead of havingNone
in the list.I don't think we ever use these forward ticks, can you check other docstrings to see if we use quotes at all or what.