From 391fa86ad1e00bdb44527beebca56ed813198ce7 Mon Sep 17 00:00:00 2001 From: Doran Deluz Date: Sun, 12 Jan 2014 11:13:35 +0900 Subject: [PATCH 1/2] BUG/TST: dt+BDay(n) wrong if n>5, n%5==0 and dt not on offset (GH5890) --- pandas/tseries/offsets.py | 4 +++- pandas/tseries/tests/test_offsets.py | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/pandas/tseries/offsets.py b/pandas/tseries/offsets.py index b763fc6b11252..ab9f49ddd321e 100644 --- a/pandas/tseries/offsets.py +++ b/pandas/tseries/offsets.py @@ -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) diff --git a/pandas/tseries/tests/test_offsets.py b/pandas/tseries/tests/test_offsets.py index 047bd244fef93..a3c63966948ee 100644 --- a/pandas/tseries/tests/test_offsets.py +++ b/pandas/tseries/tests/test_offsets.py @@ -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()) From 4b791d44d0b31587a3cd718d55197d824fbee9c6 Mon Sep 17 00:00:00 2001 From: Doran Deluz Date: Sun, 12 Jan 2014 11:57:26 +0900 Subject: [PATCH 2/2] DOC: updated release.rst (GH5890) --- doc/source/release.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/source/release.rst b/doc/source/release.rst index 83caba53375f0..d025baa66aa88 100644 --- a/doc/source/release.rst +++ b/doc/source/release.rst @@ -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 -------------