Skip to content

BUG: dt+BDay(n) wrong if n>5, n%5==0 and dt not on offset (GH5890) #5911

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

Merged
merged 2 commits into from
Jan 13, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/release.rst
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ Bug Fixes
- Bug when assigning to .ix[tuple(...)] (:issue:`5896`)
- Bug in fully reindexing a Panel (:issue:`5905`)
- Bug in idxmin/max with object dtypes (:issue:`5914`)
- Bug in ``BusinessDay`` when adding n days to a date not on offset when n>5 and n%5==0 (:issue:`5890`)

pandas 0.13.0
-------------
Expand Down
4 changes: 3 additions & 1 deletion pandas/tseries/offsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,9 @@ def apply(self, other):
if n < 0 and result.weekday() > 4:
n += 1
n -= 5 * k

if n == 0 and result.weekday() > 4:
n -= 1

while n != 0:
k = n // abs(n)
result = result + timedelta(k)
Expand Down
5 changes: 5 additions & 0 deletions pandas/tseries/tests/test_offsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,11 @@ def test_apply_large_n(self):
rs = st + off
xp = datetime(2011, 12, 26)
self.assertEqual(rs, xp)

off = BDay() * 10
rs = datetime(2014, 1, 5) + off # see #5890
xp = datetime(2014, 1, 17)
self.assertEqual(rs, xp)

def test_apply_corner(self):
self.assertRaises(TypeError, BDay().apply, BMonthEnd())
Expand Down