Skip to content

REV: move unique, _get_unique_index to ExtensionIndex #30786

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

Merged
merged 1 commit into from
Jan 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions pandas/core/indexes/datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,17 +110,6 @@ class DatetimeIndexOpsMixin(ExtensionIndex, ExtensionOpsMixin):
def is_all_dates(self) -> bool:
return True

def unique(self, level=None):
if level is not None:
self._validate_index_level(level)

result = self._data.unique()

# Note: if `self` is already unique, then self.unique() should share
# a `freq` with self. If not already unique, then self.freq must be
# None, so again sharing freq is correct.
return self._shallow_copy(result._data)

@classmethod
def _create_comparison_method(cls, op):
"""
Expand Down
16 changes: 16 additions & 0 deletions pandas/core/indexes/extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,3 +176,19 @@ def take(self, indices, axis=0, allow_fill=True, fill_value=None, **kwargs):
na_value=self._na_value,
)
return type(self)(taken, name=self.name)

def unique(self, level=None):
if level is not None:
self._validate_index_level(level)

result = self._data.unique()
return self._shallow_copy(result)

def _get_unique_index(self, dropna=False):
if self.is_unique and not dropna:
return self

result = self._data.unique()
if dropna and self.hasnans:
result = result[~result.isna()]
return self._shallow_copy(result)
9 changes: 0 additions & 9 deletions pandas/core/indexes/period.py
Original file line number Diff line number Diff line change
Expand Up @@ -583,15 +583,6 @@ def get_indexer_non_unique(self, target):
indexer, missing = self._int64index.get_indexer_non_unique(target)
return ensure_platform_int(indexer), missing

def _get_unique_index(self, dropna=False):
if self.is_unique and not dropna:
return self

result = self._data.unique()
if dropna and self.hasnans:
result = result[~result.isna()]
return self._shallow_copy(result)

def get_loc(self, key, method=None, tolerance=None):
"""
Get integer location for requested label
Expand Down