PERF: Override PeriodIndex.unique by jbrockmendel · Pull Request #23083 · pandas-dev/pandas (original) (raw)

In trying to simplify the mess that is the PeriodIndex constructors, I found that PeriodIndex.unique is doing an unfortunate conversion to object-dtype. This PR avoids that and gets a nice speedup.

In [2]: pi = pd.period_range('1000Q1', periods=10000, freq='Q')
In [3]: %timeit pi.unique()
The slowest run took 6.25 times longer than the fastest. This could mean that an intermediate result is being cached.
1000 loops, best of 3: 226 µs per loop    <-- PR
10 loops, best of 3: 24.7 ms per loop     <-- master