From 0a8ba4558ed0737e14aae2b8d6314bf24984a165 Mon Sep 17 00:00:00 2001 From: Ming Li Date: Fri, 23 Mar 2018 21:58:52 +0000 Subject: [PATCH 01/10] remove _shared_docs and add doctring to series.unique --- pandas/core/base.py | 24 ------------------------ pandas/core/series.py | 22 +++++++++++++++++++++- 2 files changed, 21 insertions(+), 25 deletions(-) diff --git a/pandas/core/base.py b/pandas/core/base.py index b3eb9a0ae7530..7c31ea32bfa19 100644 --- a/pandas/core/base.py +++ b/pandas/core/base.py @@ -1020,30 +1020,6 @@ def value_counts(self, normalize=False, sort=True, ascending=False, normalize=normalize, bins=bins, dropna=dropna) return result - _shared_docs['unique'] = ( - """ - Return unique values in the object. Uniques are returned in order - of appearance, this does NOT sort. Hash table-based unique. - - Parameters - ---------- - values : 1d array-like - - Returns - ------- - unique values. - - If the input is an Index, the return is an Index - - If the input is a Categorical dtype, the return is a Categorical - - If the input is a Series/ndarray, the return will be an ndarray - - See Also - -------- - unique - Index.unique - Series.unique - """) - - @Appender(_shared_docs['unique'] % _indexops_doc_kwargs) def unique(self): values = self._values diff --git a/pandas/core/series.py b/pandas/core/series.py index da598259d272d..2de4a126af741 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -1429,8 +1429,28 @@ def mode(self): # TODO: Add option for bins like value_counts() return algorithms.mode(self) - @Appender(base._shared_docs['unique'] % _shared_doc_kwargs) def unique(self): + """ + Return unique values in the object. Uniques are returned in order + of appearance, this does NOT sort. Hash table-based unique. + + Parameters + ---------- + values : 1d array-like + + Returns + ------- + unique values. + - If the input is an Index, the return is an Index + - If the input is a Categorical dtype, the return is a Categorical + - If the input is a Series/ndarray, the return will be an ndarray + + See Also + -------- + unique + Index.unique + Series.unique + """ result = super(Series, self).unique() if is_datetime64tz_dtype(self.dtype): From 308b2794b7ed4a8b16ec479924fb1e04a2dfec63 Mon Sep 17 00:00:00 2001 From: Ming Li Date: Sat, 24 Mar 2018 13:28:31 +0000 Subject: [PATCH 02/10] add examples and wording --- pandas/core/series.py | 39 +++++++++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index 2de4a126af741..11b13ddeb4c98 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -1431,12 +1431,10 @@ def mode(self): def unique(self): """ - Return unique values in the object. Uniques are returned in order - of appearance, this does NOT sort. Hash table-based unique. + Return unique values in the Series. - Parameters - ---------- - values : 1d array-like + Uniques are returned in order of appearance. Hash table-based unique, + therefore does NOT sort. Returns ------- @@ -1449,7 +1447,36 @@ def unique(self): -------- unique Index.unique - Series.unique + + Examples + -------- + >>> pd.Series([2, 1, 3, 3], name='A').unique() + array([2, 1, 3]) + + >>> pd.Series([2] + [1] * 5).unique() + array([2, 1]) + + >>> pd.Series([pd.Timestamp('20160101') for _ in range(3)]).unique() + array(['2016-01-01T00:00:00.000000000'], dtype='datetime64[ns]') + + >>> pd.Series([pd.Timestamp('20160101', tz='US/Eastern') + for _ in range(3)]).unique() + array([Timestamp('2016-01-01 00:00:00-0500', tz='US/Eastern')], + dtype=object) + + An unordered Categorical will return categories in the order of + appearance. + + >>> pd.Series(pd.Categorical(list('baabc'))).unique() + [b, a, c] + Categories (3, object): [b, a, c] + + An ordered Categorical preserves the category ordering. + + >>> pd.Series(pd.Categorical(list('baabc'), categories=list('abc'), + ordered=True)).unique() + [b, a, c] + Categories (3, object): [a < b < c] """ result = super(Series, self).unique() From fb86b7fa9657c6ef1164b399a5bff011e81f54bf Mon Sep 17 00:00:00 2001 From: Ming Li Date: Sat, 24 Mar 2018 13:32:23 +0000 Subject: [PATCH 03/10] line break in example docstrings --- pandas/core/series.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index 11b13ddeb4c98..fb5774293c3e4 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -1459,7 +1459,7 @@ def unique(self): >>> pd.Series([pd.Timestamp('20160101') for _ in range(3)]).unique() array(['2016-01-01T00:00:00.000000000'], dtype='datetime64[ns]') - >>> pd.Series([pd.Timestamp('20160101', tz='US/Eastern') + >>> pd.Series([pd.Timestamp('20160101', tz='US/Eastern') \ for _ in range(3)]).unique() array([Timestamp('2016-01-01 00:00:00-0500', tz='US/Eastern')], dtype=object) @@ -1473,7 +1473,7 @@ def unique(self): An ordered Categorical preserves the category ordering. - >>> pd.Series(pd.Categorical(list('baabc'), categories=list('abc'), + >>> pd.Series(pd.Categorical(list('baabc'), categories=list('abc'), \ ordered=True)).unique() [b, a, c] Categories (3, object): [a < b < c] From 10d940d78c39b9ab04ab7f4798f3d8d5a514a866 Mon Sep 17 00:00:00 2001 From: Ming Li Date: Sat, 24 Mar 2018 13:37:46 +0000 Subject: [PATCH 04/10] descriptions in See Also --- pandas/core/series.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index fb5774293c3e4..1defebd4a1c33 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -1445,8 +1445,8 @@ def unique(self): See Also -------- - unique - Index.unique + unique : return unique values of 1d array-like objects. + Index.unique : return Index with unique values from an Index object. Examples -------- From 93b1ffdaa41ef83693e0739c87ea5765ccef1765 Mon Sep 17 00:00:00 2001 From: Ming Li Date: Sat, 24 Mar 2018 13:39:31 +0000 Subject: [PATCH 05/10] minor changes --- pandas/core/series.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index 1defebd4a1c33..87f0f6b8677cb 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -1431,7 +1431,7 @@ def mode(self): def unique(self): """ - Return unique values in the Series. + Return unique values of Series object. Uniques are returned in order of appearance. Hash table-based unique, therefore does NOT sort. From 2dff8315ff2027a91e88671fd4ce91a81a553462 Mon Sep 17 00:00:00 2001 From: Ming Li Date: Sun, 25 Mar 2018 22:52:16 +0100 Subject: [PATCH 06/10] remove backward slash --- pandas/core/series.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index 87f0f6b8677cb..9c1ddd4e0590c 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -1459,8 +1459,8 @@ def unique(self): >>> pd.Series([pd.Timestamp('20160101') for _ in range(3)]).unique() array(['2016-01-01T00:00:00.000000000'], dtype='datetime64[ns]') - >>> pd.Series([pd.Timestamp('20160101', tz='US/Eastern') \ - for _ in range(3)]).unique() + >>> pd.Series([pd.Timestamp('20160101', tz='US/Eastern') + ... for _ in range(3)]).unique() array([Timestamp('2016-01-01 00:00:00-0500', tz='US/Eastern')], dtype=object) @@ -1473,8 +1473,8 @@ def unique(self): An ordered Categorical preserves the category ordering. - >>> pd.Series(pd.Categorical(list('baabc'), categories=list('abc'), \ - ordered=True)).unique() + >>> pd.Series(pd.Categorical(list('baabc'), categories=list('abc'), + ... ordered=True)).unique() [b, a, c] Categories (3, object): [a < b < c] """ From e02463587a69d1800ef0d81de343d3b40beb5ffa Mon Sep 17 00:00:00 2001 From: Ming Li Date: Sun, 25 Mar 2018 22:59:14 +0100 Subject: [PATCH 07/10] rephrase See Also section --- pandas/core/series.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index 9c1ddd4e0590c..d54b97a1ab3a7 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -1445,7 +1445,7 @@ def unique(self): See Also -------- - unique : return unique values of 1d array-like objects. + pandas.unique : top-level unique method for any 1-d array-like object. Index.unique : return Index with unique values from an Index object. Examples From e325fef06c83b5677f1bfe0b1f53e1a20a747d78 Mon Sep 17 00:00:00 2001 From: Ming Li Date: Tue, 27 Mar 2018 00:15:59 +0100 Subject: [PATCH 08/10] simpler return description. --- pandas/core/series.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index d54b97a1ab3a7..082dc20297f06 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -1438,10 +1438,7 @@ def unique(self): Returns ------- - unique values. - - If the input is an Index, the return is an Index - - If the input is a Categorical dtype, the return is a Categorical - - If the input is a Series/ndarray, the return will be an ndarray + unique values : Series or Categorical See Also -------- From bd1f114ab0b07398b98e1b5319e7365f3a9c4a60 Mon Sep 17 00:00:00 2001 From: minggli Date: Tue, 27 Mar 2018 16:25:23 +0100 Subject: [PATCH 09/10] rephase return description --- pandas/core/series.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index 082dc20297f06..b59d68bcb05de 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -1438,7 +1438,9 @@ def unique(self): Returns ------- - unique values : Series or Categorical + unique values : ndarray or Categorical + The unique values returned as a NumPy array. In case of categorical + data type, returned as a Categorical. See Also -------- From 4931fcf40d207358578ae9f35bbae8eeeeb14c10 Mon Sep 17 00:00:00 2001 From: Joris Van den Bossche Date: Tue, 27 Mar 2018 22:49:24 +0200 Subject: [PATCH 10/10] Update series.py --- pandas/core/series.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index b59d68bcb05de..48e6453e36491 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -1438,7 +1438,7 @@ def unique(self): Returns ------- - unique values : ndarray or Categorical + ndarray or Categorical The unique values returned as a NumPy array. In case of categorical data type, returned as a Categorical. @@ -1452,13 +1452,10 @@ def unique(self): >>> pd.Series([2, 1, 3, 3], name='A').unique() array([2, 1, 3]) - >>> pd.Series([2] + [1] * 5).unique() - array([2, 1]) - - >>> pd.Series([pd.Timestamp('20160101') for _ in range(3)]).unique() + >>> pd.Series([pd.Timestamp('2016-01-01') for _ in range(3)]).unique() array(['2016-01-01T00:00:00.000000000'], dtype='datetime64[ns]') - >>> pd.Series([pd.Timestamp('20160101', tz='US/Eastern') + >>> pd.Series([pd.Timestamp('2016-01-01', tz='US/Eastern') ... for _ in range(3)]).unique() array([Timestamp('2016-01-01 00:00:00-0500', tz='US/Eastern')], dtype=object)