Skip to content

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

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
dd137 opened this issue Jan 9, 2014 · 2 comments · Fixed by #5911
Closed

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

dd137 opened this issue Jan 9, 2014 · 2 comments · Fixed by #5911
Labels
Bug Frequency DateOffsets
Milestone

Comments

@dd137
Copy link
Contributor

dd137 commented Jan 9, 2014

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.

@jreback
Copy link
Contributor

jreback commented Jan 9, 2014

a PR would be appreciated

pls include your above examples as tests

@dd137
Copy link
Contributor Author

dd137 commented Jan 10, 2014

Ok sure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Frequency DateOffsets
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants