Skip to content

PERF: Override PeriodIndex.unique #23083

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 3 commits into from
Oct 11, 2018
Merged
Show file tree
Hide file tree
Changes from 2 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
3 changes: 3 additions & 0 deletions asv_bench/benchmarks/period.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,6 @@ def time_align(self):

def time_intersection(self):
self.index[:750].intersection(self.index[250:])

def time_unique(self):
self.index.unique()
13 changes: 13 additions & 0 deletions pandas/core/indexes/period.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
DIFFERENT_FREQ_INDEX)
from pandas._libs.tslibs import resolution, period

from pandas.core.algorithms import unique1d
from pandas.core.arrays import datetimelike as dtl
from pandas.core.arrays.period import PeriodArrayMixin, dt64arr_to_periodarr
from pandas.core.base import _shared_docs
Expand Down Expand Up @@ -539,6 +540,18 @@ def _get_unique_index(self, dropna=False):
res = res.dropna()
return res

@Appender(Index.unique.__doc__)
def unique(self, level=None):
# override the Index.unique method for performance
if level is not None:
# this should never occur, but is retained to make the signature
# match Index.unique
self._validate_index_level(level)

values = self._ndarray_values
result = unique1d(values)
return self._shallow_copy(result)

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