-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
DOC: add docstring for Index.get_duplicates #20223
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 2 commits
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 |
---|---|---|
|
@@ -1710,6 +1710,42 @@ def _invalid_indexer(self, form, key): | |
kind=type(key))) | ||
|
||
def get_duplicates(self): | ||
""" | ||
Extract duplicated index elements. | ||
|
||
This function returns a sorted list of index elements which appear more | ||
than once in the index. | ||
|
||
Returns | ||
------- | ||
array-like | ||
List of duplicated indices. | ||
|
||
See Also | ||
-------- | ||
:meth:`Index.duplicated` : Return boolean array denoting duplicates. | ||
:meth:`Index.drop_duplicates` : Return Index with duplicates removed. | ||
|
||
Examples | ||
-------- | ||
>>> pd.Index([1, 2, 3, 4]).get_duplicates() | ||
[] | ||
>>> pd.Index([1, 2, 2, 3, 3, 3, 4]).get_duplicates() | ||
[2, 3] | ||
>>> pd.Index([1, 2, 3, 2, 3, 4, 3]).get_duplicates() | ||
[2, 3] | ||
>>> pd.Index(['a', 'b', 'b', 'c', 'c', 'c', 'd']).get_duplicates() | ||
['b', 'c'] | ||
>>> dates = pd.to_datetime(['2018-01-01', '2018-01-02', | ||
... '2018-01-03', '2018-01-03'], | ||
... format='%Y-%m-%d') | ||
>>> pd.Index(pd.to_datetime(dates, format='%Y-%m-%d')).get_duplicates() | ||
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. you don't need to repeat the Can you also add a sentence here before the example explaining that for DatetimeIndex, it does not return a list but a DatetetimeIndex ? |
||
DatetimeIndex(['2018-01-03'], dtype='datetime64[ns]', freq=None) | ||
|
||
Notes | ||
----- | ||
Returns empty list in case all index elements are unique. | ||
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. I would put this explanation above the actual example where you show this |
||
""" | ||
from collections import defaultdict | ||
counter = defaultdict(lambda: 0) | ||
for k in self.values: | ||
|
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.
In the See Also section, it is not needed to make an explicit link with the
:meth:`..`
syntax, you can just use Index.duplicated