Skip to content

PERF: Implement PeriodArray._unique #23586

Closed
@TomAugspurger

Description

@TomAugspurger

Avoid an astype(object).

diff --git a/pandas/core/arrays/period.py b/pandas/core/arrays/period.py
index 5a75f2706..12191ad89 100644
--- a/pandas/core/arrays/period.py
+++ b/pandas/core/arrays/period.py
@@ -216,6 +216,10 @@ class PeriodArray(dtl.DatetimeLikeArrayMixin, ExtensionArray):
         ordinals = libperiod.extract_ordinals(periods, freq)
         return cls(ordinals, freq=freq)
 
+    def unique(self):
+        from pandas.core.algorithms import unique
+        return type(self)(unique(self.asi8), self.freq)
+
     def _values_for_factorize(self):
         return self.asi8, iNaT

should work.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions