File tree 3 files changed +17
-0
lines changed
3 files changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -119,3 +119,6 @@ def time_align(self):
119
119
120
120
def time_intersection (self ):
121
121
self .index [:750 ].intersection (self .index [250 :])
122
+
123
+ def time_unique (self ):
124
+ self .index .unique ()
Original file line number Diff line number Diff line change @@ -686,6 +686,7 @@ Performance Improvements
686
686
(:issue:`21372`)
687
687
- Improved the performance of :func:`pandas.get_dummies` with ``sparse=True`` (:issue:`21997`)
688
688
- Improved performance of :func:`IndexEngine.get_indexer_non_unique` for sorted, non-unique indexes (:issue:`9466`)
689
+ - Improved performance of :func:`PeriodIndex.unique` (:issue:`23083`)
689
690
690
691
691
692
.. _whatsnew_0240.docs:
Original file line number Diff line number Diff line change 29
29
DIFFERENT_FREQ_INDEX )
30
30
from pandas ._libs .tslibs import resolution , period
31
31
32
+ from pandas .core .algorithms import unique1d
32
33
from pandas .core .arrays import datetimelike as dtl
33
34
from pandas .core .arrays .period import PeriodArrayMixin , dt64arr_to_periodarr
34
35
from pandas .core .base import _shared_docs
@@ -539,6 +540,18 @@ def _get_unique_index(self, dropna=False):
539
540
res = res .dropna ()
540
541
return res
541
542
543
+ @Appender (Index .unique .__doc__ )
544
+ def unique (self , level = None ):
545
+ # override the Index.unique method for performance GH#23083
546
+ if level is not None :
547
+ # this should never occur, but is retained to make the signature
548
+ # match Index.unique
549
+ self ._validate_index_level (level )
550
+
551
+ values = self ._ndarray_values
552
+ result = unique1d (values )
553
+ return self ._shallow_copy (result )
554
+
542
555
def get_loc (self , key , method = None , tolerance = None ):
543
556
"""
544
557
Get integer location for requested label
You can’t perform that action at this time.
0 commit comments