Skip to content

datetools.BDay() does the wrong thing when given a Friday - Saturday range #5637

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
jikamens opened this issue Dec 3, 2013 · 1 comment
Closed
Labels
Bug Datetime Datetime data dtype Duplicate Report Duplicate issue or pull request Frequency DateOffsets Timezones Timezone data dtype
Milestone

Comments

@jikamens
Copy link

jikamens commented Dec 3, 2013

With a daily frequency, when you specify a range from a Friday morning UTC to Saturday morning UTC, you get back both days as expected:

(Pdb) pd.DatetimeIndex(start=datetime.datetime(2013,11,22,5,0,0,tzinfo=pytz.utc), end=datetime.datetime(2013,11,23,4,59,59,tzinfo=pytz.utc), freq=pd.datetools.Day())
<class 'pandas.tseries.index.DatetimeIndex'>
[2013-11-22 05:00:00, 2013-11-23 05:00:00]
Length: 2, Freq: D, Timezone: UTC

With a BDay frequency, however, you get back neither day, even though you should get back the Friday since it's a business dasy:

(Pdb) pd.DatetimeIndex(start=datetime.datetime(2013,11,22,5,0,0,tzinfo=pytz.utc), end=datetime.datetime(2013,11,23,4,59,59,tzinfo=pytz.utc), freq=pd.datetools.BDay())
<class 'pandas.tseries.index.DatetimeIndex'>
Length: 0, Freq: B, Timezone: UTC

The correct thing happens if you shift both dates back by a day:

(Pdb) pd.DatetimeIndex(start=datetime.datetime(2013,11,21,5,0,0,tzinfo=pytz.utc), end=datetime.datetime(2013,11,22,4,59,59,tzinfo=pytz.utc), freq=pd.datetools.BDay())
<class 'pandas.tseries.index.DatetimeIndex'>
[2013-11-21 05:00:00]
Length: 1, Freq: B, Timezone: UTC

You also get back the Friday if you extend the range to the next business day:

(Pdb) pd.DatetimeIndex(start=datetime.datetime(2013,11,22,5,0,0,tzinfo=pytz.utc), end=datetime.datetime(2013,11,25,4,59,59,tzinfo=pytz.utc), freq=pd.datetools.BDay())
<class 'pandas.tseries.index.DatetimeIndex'>
[2013-11-22 05:00:00]
Length: 1, Freq: B, Timezone: UTC

Ref: quantopian/zipline#243

@jreback
Copy link
Contributor

jreback commented Apr 6, 2014

dupe of #6673

@jreback jreback closed this as completed Apr 6, 2014
@jreback jreback added the Dupe label Apr 6, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Datetime Datetime data dtype Duplicate Report Duplicate issue or pull request Frequency DateOffsets Timezones Timezone data dtype
Projects
None yet
Development

No branches or pull requests

2 participants