-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
API: change unique to return Index #13979
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 all 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 |
---|---|---|
|
@@ -18,6 +18,7 @@ | |
is_float_dtype, | ||
is_extension_type, is_datetimetz, | ||
is_datetimelike, | ||
is_datetime64tz_dtype, | ||
is_timedelta64_dtype, | ||
is_list_like, | ||
is_hashable, | ||
|
@@ -77,7 +78,7 @@ | |
axes='index', klass='Series', axes_single_arg="{0, 'index'}", | ||
inplace="""inplace : boolean, default False | ||
If True, performs operation inplace and returns None.""", | ||
duplicated='Series', | ||
unique='np.ndarray', duplicated='Series', | ||
optional_by='') | ||
|
||
|
||
|
@@ -1231,6 +1232,15 @@ def mode(self): | |
# TODO: Add option for bins like value_counts() | ||
return algos.mode(self) | ||
|
||
@Appender(base._shared_docs['unique'] % _shared_doc_kwargs) | ||
def unique(self): | ||
result = super(Series, self).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. any way to do this in the super? IOW 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. Because 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. ok then add a big TODO here with the issue reference saying this should really return a dtype compat array-like in future versions |
||
if is_datetime64tz_dtype(self.dtype): | ||
# to return array of Timestamp with tz | ||
# ToDo: it must return DatetimeArray with tz in pandas 2.0 | ||
return result.asobject.values | ||
return result | ||
|
||
@deprecate_kwarg('take_last', 'keep', mapping={True: 'last', | ||
False: 'first'}) | ||
@Appender(base._shared_docs['drop_duplicates'] % _shared_doc_kwargs) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,7 +60,8 @@ | |
|
||
_unsortable_types = frozenset(('mixed', 'mixed-integer')) | ||
|
||
_index_doc_kwargs = dict(klass='Index', inplace='', duplicated='np.array') | ||
_index_doc_kwargs = dict(klass='Index', inplace='', | ||
unique='Index', duplicated='np.ndarray') | ||
_index_shared_docs = dict() | ||
|
||
|
||
|
@@ -3217,6 +3218,11 @@ def drop(self, labels, errors='raise'): | |
indexer = indexer[~mask] | ||
return self.delete(indexer) | ||
|
||
@Appender(base._shared_docs['unique'] % _index_doc_kwargs) | ||
def unique(self): | ||
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. shouldn't this be in 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. Yes, moved. |
||
result = super(Index, self).unique() | ||
return self._shallow_copy(result) | ||
|
||
@deprecate_kwarg('take_last', 'keep', mapping={True: 'last', | ||
False: 'first'}) | ||
@Appender(base._shared_docs['drop_duplicates'] % _index_doc_kwargs) | ||
|
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.
while updating. let's add that uniques are preserved in the order as seen (I know we had discussed this), but let's document the behavior at least. @jorisvandenbossche @shoyer
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.
yes, +1
The issue for this is #9346