Skip to content

CustomBusinessDay slow for increments <0 and >1 #8236

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

Closed
bjonen opened this issue Sep 10, 2014 · 1 comment · Fixed by #8293
Closed

CustomBusinessDay slow for increments <0 and >1 #8236

bjonen opened this issue Sep 10, 2014 · 1 comment · Fixed by #8293
Labels
Frequency DateOffsets Performance Memory or execution speed performance
Milestone

Comments

@bjonen
Copy link
Contributor

bjonen commented Sep 10, 2014

For rolling back or for moving forward more than one step, DateOffsets create a new instance setting n accordingly. The CustomBusinessDay constructor can be very slow, however, when a large list of holidays is passed. The holidays are processed to datetime64.

As a result speed deteriorates by two magnitudes.

import pandas as pd
import datetime as dt

pd.__version__
Out[6]:
'0.14.1'
In [7]:
cbday = pd.offsets.CustomBusinessDay()
date + cbday
%timeit date + cbday
100000 loops, best of 3: 14.6 µs per loop
In [8]:
hdays = [dt.datetime(2013,1,1) for ele in range(1000)]
cbdayh = pd.offsets.CustomBusinessDay(holidays=hdays)
date + cbdayh
%timeit date + cbdayh
%timeit date + 2*cbdayh
%timeit date - 1*cbdayh
%timeit date - 10*cbday

100000 loops, best of 3: 14.6 µs per loop
100 loops, best of 3: 3.4 ms per loop
100 loops, best of 3: 6.76 ms per loop
10000 loops, best of 3: 27.8 µs per loop

I think it makes sense to have the user call to_dt64 before initializing CustomBusinessDay and to rely on the holidays to be passed in the correct format. Any other ideas how to handle this problem? Shall I create a PR for this?

@jreback
Copy link
Contributor

jreback commented Sep 10, 2014

hmm, take that back...go ahead and do a PR (and add vbenches)

@jreback jreback added Performance Memory or execution speed performance Frequency DateOffsets labels Sep 10, 2014
@jreback jreback added this to the 0.15.1 milestone Sep 18, 2014
@jreback jreback modified the milestones: 0.15.0, 0.15.1 Oct 4, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Frequency DateOffsets Performance Memory or execution speed performance
Projects
None yet
2 participants