8000 PERF: Override PeriodIndex.unique by jbrockmendel · Pull Request #23083 · pandas-dev/pandas · GitHub
[go: up one dir, main page]

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
Changes from 1 commit
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
Next Next commit
PERF: Override PeriodIndex.unique
  • Loading branch information
jbrockmendel committed Oct 11, 2018
commit f8d170bbae5d53f25900ce800d5cac6936d3bf16
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
0