Skip to content

Commit cdfce2b

Browse files
mingglijorisvandenbossche
authored andcommitted
DOC: docstring to series.unique (#20474)
1 parent 7fd3b85 commit cdfce2b

File tree

2 files changed

+44
-25
lines changed

2 files changed

+44
-25
lines changed

pandas/core/base.py

-24
Original file line numberDiff line numberDiff line change
@@ -1021,30 +1021,6 @@ def value_counts(self, normalize=False, sort=True, ascending=False,
10211021
normalize=normalize, bins=bins, dropna=dropna)
10221022
return result
10231023

1024-
_shared_docs['unique'] = (
1025-
"""
1026-
Return unique values in the object. Uniques are returned in order
1027-
of appearance, this does NOT sort. Hash table-based unique.
1028-
1029-
Parameters
1030-
----------
1031-
values : 1d array-like
1032-
1033-
Returns
1034-
-------
1035-
unique values.
1036-
- If the input is an Index, the return is an Index
1037-
- If the input is a Categorical dtype, the return is a Categorical
1038-
- If the input is a Series/ndarray, the return will be an ndarray
1039-
1040-
See Also
1041-
--------
1042-
unique
1043-
Index.unique
1044-
Series.unique
1045-
""")
1046-
1047-
@Appender(_shared_docs['unique'] % _indexops_doc_kwargs)
10481024
def unique(self):
10491025
values = self._values
10501026

pandas/core/series.py

+44-1
Original file line numberDiff line numberDiff line change
@@ -1429,8 +1429,51 @@ def mode(self):
14291429
# TODO: Add option for bins like value_counts()
14301430
return algorithms.mode(self)
14311431

1432-
@Appender(base._shared_docs['unique'] % _shared_doc_kwargs)
14331432
def unique(self):
1433+
"""
1434+
Return unique values of Series object.
1435+
1436+
Uniques are returned in order of appearance. Hash table-based unique,
1437+
therefore does NOT sort.
1438+
1439+
Returns
1440+
-------
1441+
ndarray or Categorical
1442+
The unique values returned as a NumPy array. In case of categorical
1443+
data type, returned as a Categorical.
1444+
1445+
See Also
1446+
--------
1447+
pandas.unique : top-level unique method for any 1-d array-like object.
1448+
Index.unique : return Index with unique values from an Index object.
1449+
1450+
Examples
1451+
--------
1452+
>>> pd.Series([2, 1, 3, 3], name='A').unique()
1453+
array([2, 1, 3])
1454+
1455+
>>> pd.Series([pd.Timestamp('2016-01-01') for _ in range(3)]).unique()
1456+
array(['2016-01-01T00:00:00.000000000'], dtype='datetime64[ns]')
1457+
1458+
>>> pd.Series([pd.Timestamp('2016-01-01', tz='US/Eastern')
1459+
... for _ in range(3)]).unique()
1460+
array([Timestamp('2016-01-01 00:00:00-0500', tz='US/Eastern')],
1461+
dtype=object)
1462+
1463+
An unordered Categorical will return categories in the order of
1464+
appearance.
1465+
1466+
>>> pd.Series(pd.Categorical(list('baabc'))).unique()
1467+
[b, a, c]
1468+
Categories (3, object): [b, a, c]
1469+
1470+
An ordered Categorical preserves the category ordering.
1471+
1472+
>>> pd.Series(pd.Categorical(list('baabc'), categories=list('abc'),
1473+
... ordered=True)).unique()
1474+
[b, a, c]
1475+
Categories (3, object): [a < b < c]
1476+
"""
14341477
result = super(Series, self).unique()
14351478

14361479
if is_datetime64tz_dtype(self.dtype):

0 commit comments

Comments
 (0)