From dcf8fe63e8ce24f9ea1919e36f57d6b79922a178 Mon Sep 17 00:00:00 2001 From: Brock Date: Tue, 27 Oct 2020 18:04:50 -0700 Subject: [PATCH 1/2] BUG: BusinessDay.apply_index with offset --- pandas/_libs/tslibs/offsets.pyx | 8 ++++++-- pandas/tests/tseries/offsets/test_offsets.py | 14 ++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/pandas/_libs/tslibs/offsets.pyx b/pandas/_libs/tslibs/offsets.pyx index 98b2ddbd21ee1..dbd094905cf24 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -1388,7 +1388,11 @@ cdef class BusinessDay(BusinessMixin): @apply_array_wraps def _apply_array(self, dtarr): i8other = dtarr.view("i8") - return shift_bdays(i8other, self.n) + res = _shift_bdays(i8other, self.n) + if self.offset: + res = res.view("M8[ns]") + Timedelta(self.offset) + res = res.view("i8") + return res def is_on_offset(self, dt: datetime) -> bool: if self.normalize and not _is_normalized(dt): @@ -3778,7 +3782,7 @@ cdef inline void _shift_quarters(const int64_t[:] dtindex, out[i] = dtstruct_to_dt64(&dts) -cdef ndarray[int64_t] shift_bdays(const int64_t[:] i8other, int periods): +cdef ndarray[int64_t] _shift_bdays(const int64_t[:] i8other, int periods): """ Implementation of BusinessDay.apply_offset. diff --git a/pandas/tests/tseries/offsets/test_offsets.py b/pandas/tests/tseries/offsets/test_offsets.py index 922aff1792227..fba123e47feb2 100644 --- a/pandas/tests/tseries/offsets/test_offsets.py +++ b/pandas/tests/tseries/offsets/test_offsets.py @@ -750,6 +750,13 @@ def test_with_offset(self): assert (self.d + offset) == datetime(2008, 1, 2, 2) + def test_with_offset_index(self): + dti = DatetimeIndex([self.d]) + result = dti + (self.offset + timedelta(hours=2)) + + expected = DatetimeIndex([datetime(2008, 1, 2, 2)]) + tm.assert_index_equal(result, expected) + def test_eq(self): assert self.offset2 == self.offset2 @@ -2642,6 +2649,13 @@ def test_with_offset(self): assert (self.d + offset) == datetime(2008, 1, 2, 2) + def test_with_offset_index(self): + dti = DatetimeIndex([self.d]) + result = dti + (self.offset + timedelta(hours=2)) + + expected = DatetimeIndex([datetime(2008, 1, 2, 2)]) + tm.assert_index_equal(result, expected) + def test_eq(self): assert self.offset2 == self.offset2 From 19af8c4297a9443db3e5e7336b686cc5428677c3 Mon Sep 17 00:00:00 2001 From: Brock Date: Sat, 31 Oct 2020 11:14:52 -0700 Subject: [PATCH 2/2] whatsnew --- doc/source/whatsnew/v1.2.0.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/source/whatsnew/v1.2.0.rst b/doc/source/whatsnew/v1.2.0.rst index 7a5b457d8bad1..d7faa4bc6ac20 100644 --- a/doc/source/whatsnew/v1.2.0.rst +++ b/doc/source/whatsnew/v1.2.0.rst @@ -388,6 +388,7 @@ Datetimelike - :class:`Timestamp` and :class:`DatetimeIndex` comparisons between timezone-aware and timezone-naive objects now follow the standard library ``datetime`` behavior, returning ``True``/``False`` for ``!=``/``==`` and raising for inequality comparisons (:issue:`28507`) - Bug in :meth:`DatetimeIndex.equals` and :meth:`TimedeltaIndex.equals` incorrectly considering ``int64`` indexes as equal (:issue:`36744`) - Bug in :meth:`TimedeltaIndex.sum` and :meth:`Series.sum` with ``timedelta64`` dtype on an empty index or series returning ``NaT`` instead of ``Timedelta(0)`` (:issue:`31751`) +- Bug in adding a :class:`BusinessDay` with nonzero ``offset`` to a non-scalar other (:issue:`37457`) Timedelta ^^^^^^^^^