Skip to content

Commit c818a22

Browse files
author
Csaba Farkas
committed
DOC: update Index.get_duplicates docstring
1 parent 405c690 commit c818a22

File tree

1 file changed

+31
-14
lines changed

1 file changed

+31
-14
lines changed

pandas/core/indexes/base.py

+31-14
Original file line numberDiff line numberDiff line change
@@ -1713,38 +1713,55 @@ def get_duplicates(self):
17131713
"""
17141714
Extract duplicated index elements.
17151715
1716-
This function returns a sorted list of index elements which appear more
1717-
than once in the index.
1716+
Returns a sorted list of index elements which appear more than once in
1717+
the index.
17181718
17191719
Returns
17201720
-------
17211721
array-like
1722-
List of duplicated indices.
1722+
List of duplicated indexes.
17231723
17241724
See Also
17251725
--------
1726-
:meth:`Index.duplicated` : Return boolean array denoting duplicates.
1727-
:meth:`Index.drop_duplicates` : Return Index with duplicates removed.
1726+
Index.duplicated : Return boolean array denoting duplicates.
1727+
Index.drop_duplicates : Return Index with duplicates removed.
17281728
17291729
Examples
17301730
--------
1731-
>>> pd.Index([1, 2, 3, 4]).get_duplicates()
1732-
[]
1731+
1732+
Works on different Index of types.
1733+
17331734
>>> pd.Index([1, 2, 2, 3, 3, 3, 4]).get_duplicates()
17341735
[2, 3]
1735-
>>> pd.Index([1, 2, 3, 2, 3, 4, 3]).get_duplicates()
1736-
[2, 3]
1736+
>>> pd.Index([1., 2., 2., 3., 3., 3., 4.]).get_duplicates()
1737+
[2.0, 3.0]
17371738
>>> pd.Index(['a', 'b', 'b', 'c', 'c', 'c', 'd']).get_duplicates()
17381739
['b', 'c']
1739-
>>> dates = pd.to_datetime(['2018-01-01', '2018-01-02',
1740-
... '2018-01-03', '2018-01-03'],
1740+
>>> dates = pd.to_datetime(['2018-01-01', '2018-01-02', '2018-01-03',
1741+
... '2018-01-03', '2018-01-04', '2018-01-04'],
1742+
... format='%Y-%m-%d')
1743+
>>> pd.Index(dates).get_duplicates()
1744+
DatetimeIndex(['2018-01-03', '2018-01-04'],
1745+
dtype='datetime64[ns]', freq=None)
1746+
1747+
Sorts duplicated elements even when indexes are unordered.
1748+
1749+
>>> pd.Index([1, 2, 3, 2, 3, 4, 3]).get_duplicates()
1750+
[2, 3]
1751+
1752+
Return empty array-like structure when all elements are unique.
1753+
1754+
>>> pd.Index([1, 2, 3, 4]).get_duplicates()
1755+
[]
1756+
>>> dates = pd.to_datetime(['2018-01-01', '2018-01-02', '2018-01-03'],
17411757
... format='%Y-%m-%d')
1742-
>>> pd.Index(pd.to_datetime(dates, format='%Y-%m-%d')).get_duplicates()
1743-
DatetimeIndex(['2018-01-03'], dtype='datetime64[ns]', freq=None)
1758+
>>> pd.Index(dates).get_duplicates()
1759+
DatetimeIndex([], dtype='datetime64[ns]', freq=None)
17441760
17451761
Notes
17461762
-----
1747-
Returns empty list in case all index elements are unique.
1763+
In case of datetime-like indexes, the function is overridden where the
1764+
result is converted to DatetimeIndex.
17481765
"""
17491766
from collections import defaultdict
17501767
counter = defaultdict(lambda: 0)

0 commit comments

Comments
 (0)