Skip to content

Commit 54c26ec

Browse files
authored
BUG: DateOffset(normalize=True).rollback (pandas-dev#62910)
1 parent 09278ed commit 54c26ec

File tree

3 files changed

+4
-16
lines changed

3 files changed

+4
-16
lines changed

doc/source/whatsnew/v3.0.0.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -980,6 +980,7 @@ Datetimelike
980980
- Bug in :meth:`DataFrame.fillna` raising an ``AssertionError`` instead of ``OutOfBoundsDatetime`` when filling a ``datetime64[ns]`` column with an out-of-bounds timestamp. Now correctly raises ``OutOfBoundsDatetime``. (:issue:`61208`)
981981
- Bug in :meth:`DataFrame.min` and :meth:`DataFrame.max` casting ``datetime64`` and ``timedelta64`` columns to ``float64`` and losing precision (:issue:`60850`)
982982
- Bug in :meth:`Dataframe.agg` with df with missing values resulting in IndexError (:issue:`58810`)
983+
- Bug in :meth:`DateOffset.rollback` (and subclass methods) with ``normalize=True`` rolling back one offset too long (:issue:`32616`)
983984
- Bug in :meth:`DatetimeIndex.is_year_start` and :meth:`DatetimeIndex.is_quarter_start` does not raise on Custom business days frequencies bigger then "1C" (:issue:`58664`)
984985
- Bug in :meth:`DatetimeIndex.is_year_start` and :meth:`DatetimeIndex.is_quarter_start` returning ``False`` on double-digit frequencies (:issue:`58523`)
985986
- Bug in :meth:`DatetimeIndex.union` and :meth:`DatetimeIndex.intersection` when ``unit`` was non-nanosecond (:issue:`59036`)

pandas/_libs/tslibs/offsets.pyx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,9 @@ cdef class BaseOffset:
692692
Rolled timestamp if not on offset, otherwise unchanged timestamp.
693693
"""
694694
dt = Timestamp(dt)
695+
if self.normalize and (dt - dt.normalize())._value != 0:
696+
# GH#32616
697+
dt = dt.normalize()
695698
if not self.is_on_offset(dt):
696699
dt = dt - type(self)(1, normalize=self.normalize, **self.kwds)
697700
return dt

pandas/tests/tseries/offsets/test_offsets.py

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -431,22 +431,6 @@ def test_rollback(self, offset_types):
431431
for k in norm_expected:
432432
norm_expected[k] = Timestamp(norm_expected[k].date())
433433

434-
normalized = {
435-
"Day": Timestamp("2010-12-31 00:00:00"),
436-
"DateOffset": Timestamp("2010-12-31 00:00:00"),
437-
"MonthBegin": Timestamp("2010-12-01 00:00:00"),
438-
"SemiMonthBegin": Timestamp("2010-12-15 00:00:00"),
439-
"YearBegin": Timestamp("2010-01-01 00:00:00"),
440-
"HalfYearBegin": Timestamp("2010-07-01 00:00:00"),
441-
"Week": Timestamp("2010-12-25 00:00:00"),
442-
"Hour": Timestamp("2011-01-01 00:00:00"),
443-
"Minute": Timestamp("2011-01-01 00:00:00"),
444-
"Second": Timestamp("2011-01-01 00:00:00"),
445-
"Milli": Timestamp("2011-01-01 00:00:00"),
446-
"Micro": Timestamp("2011-01-01 00:00:00"),
447-
}
448-
norm_expected.update(normalized)
449-
450434
sdt = datetime(2011, 1, 1, 9, 0)
451435
ndt = np.datetime64("2011-01-01 09:00")
452436

0 commit comments

Comments
 (0)