-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
DOC: docstring to series.unique #20474
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 9 commits
0a8ba45
fc7049b
308b279
fb86b7f
10d940d
93b1ffd
2dff831
e024635
e325fef
bd1f114
4931fcf
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 |
---|---|---|
|
@@ -1429,8 +1429,52 @@ 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 of Series object. | ||
|
||
Uniques are returned in order of appearance. Hash table-based unique, | ||
therefore does NOT sort. | ||
|
||
Returns | ||
------- | ||
unique values : Series or Categorical | ||
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. It's never a Series, only an numpy array or Categorical. I would also include something about that like
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. done. |
||
|
||
See Also | ||
-------- | ||
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 | ||
-------- | ||
>>> 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] | ||
""" | ||
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 add examples? 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. aded. and removed self reference in See Also and added descriptions. |
||
result = super(Series, self).unique() | ||
|
||
if is_datetime64tz_dtype(self.dtype): | ||
|
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.
it might be worth trying to share this doc-string with
pd.unique
(at least the examples) no?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.
good point but they have some differences:
do we have pattern somewhere in regards to conditionally show docstring lines?
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.
https://github.com/pandas-dev/pandas/pull/20361/files is doing something similar for factorize. It's somewhat complex, since we have
pd.unique
,Series/Index.unique
, andCategorical.unique
. I'd be OK with improving the docstring here, and merging theme later.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.
agree, this PR is mainly about improve docstring. and should be another PR synthesising docs of all unique methods.
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.
that's fine too