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

Conversation

jbrockmendel
Copy link
Member

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

@pep8speaks
Copy link

Hello @jbrockmendel! Thanks for submitting the PR.

Copy link
Contributor

@TomAugspurger TomAugspurger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usually these merit a whatsnew entry.

@codecov
Copy link

codecov bot commented Oct 11, 2018

Codecov Report

Merging #23083 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #23083      +/-   ##
==========================================
+ Coverage   92.19%   92.19%   +<.01%     
==========================================
  Files         169      169              
  Lines       50911    50919       +8     
==========================================
+ Hits        46939    46947       +8     
  Misses       3972     3972
Flag Coverage Δ
#multiple 90.62% <100%> (ø) ⬆️
#single 42.3% <37.5%> (-0.01%) ⬇️
Impacted Files Coverage Δ
pandas/core/indexes/period.py 93.44% <100%> (+0.12%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 296c251...3bd918c. Read the comment docs.

@jreback jreback added Performance Memory or execution speed performance Period Period data type labels Oct 11, 2018
@jreback jreback added this to the 0.24.0 milestone Oct 11, 2018
@jreback jreback merged commit a86501f into pandas-dev:master Oct 11, 2018
@jreback
Copy link
Contributor

jreback commented Oct 11, 2018

thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Performance Memory or execution speed performance Period Period data type
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants