Skip to content

Commit 0325f49

Browse files
committed
BUG: BDay for n>5 bug if starting not on offset #2680
1 parent cd3dffd commit 0325f49

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

pandas/tseries/offsets.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,8 @@ def apply(self, other):
329329
if abs(n) > 5:
330330
k = n // 5
331331
result = result + timedelta(7 * k)
332+
if n < 0 and result.weekday() > 4:
333+
n += 1
332334
n -= 5 * k
333335

334336
while n != 0:

pandas/tseries/tests/test_offsets.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,16 @@ def test_apply_large_n(self):
274274
result = dt + BDay(100) - BDay(100)
275275
self.assertEqual(result, dt)
276276

277+
off = BDay() * 6
278+
rs = datetime(2012, 1, 1) - off
279+
xp = datetime(2011, 12, 23)
280+
self.assertEqual(rs, xp)
281+
282+
st = datetime(2011, 12, 18)
283+
rs = st + off
284+
xp = datetime(2011, 12, 26)
285+
self.assertEqual(rs, xp)
286+
277287
def test_apply_corner(self):
278288
self.assertRaises(Exception, BDay().apply, BMonthEnd())
279289

0 commit comments

Comments
 (0)