Skip to content

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

Closed
@jikamens

Description

@jikamens

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

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