Skip to content

dt+BDay(n) gives the wrong date if n>5, n%5==0 and dt not on offset #5890

Closed
@dd137

Description

@dd137

This issue is closely related to bug #2680 and I believe it is also a bug.

The problem appears when adding a number of BDay n with n > 5, n % 5 == 0 to
a starting date which is not on offset.

For instance

dt = Timestamp('20140105') # Sunday
print (dt + BDay(10)).strftime('%A')
Sunday

We except Friday and not Sunday. Likewise, Friday is 'gone' from the week in the following loop:

for i in range(8,12):
    print i, (Timestamp('20140104') + BDay(i)).strftime('%A')
8 Wednesday
9 Thursday
10 Saturday
11 Monday

It does yield the correct results for substraction however:

for i in range(9,13):
    print i, (Timestamp('20140105') - BDay(i)).strftime('%A')
9 Tuesday
10 Monday
11 Friday
12 Thursday

I have patched tseries/offsets.py with a couple of lines and it corrects the problem without apparently breaking any of the existing tests (version 0.13.0-94-g0bab303). I am not super familiar with git but can try to write a PR about this if appropriate.

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