Skip to content

Commit 073b187

Browse files
BUG: Changed if statement pandas-dev#43784
1 parent 7672f40 commit 073b187

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

pandas/_libs/tslibs/offsets.pyx

+11
Original file line numberDiff line numberDiff line change
@@ -1148,6 +1148,7 @@ cdef class Day(Tick):
11481148
_td64_unit = "D"
11491149
_period_dtype_code = PeriodDtypeCode.D
11501150
_reso = NPY_DATETIMEUNIT.NPY_FR_D
1151+
_use_relativedelta = True
11511152

11521153

11531154
cdef class Hour(Tick):
@@ -1495,6 +1496,7 @@ cdef class BusinessMixin(SingleConstructorOffset):
14951496
"""
14961497
Mixin to business types to provide related functions.
14971498
"""
1499+
_use_relativedelta = True
14981500

14991501
cdef readonly:
15001502
timedelta _offset
@@ -2068,6 +2070,7 @@ cdef class WeekOfMonthMixin(SingleConstructorOffset):
20682070
"""
20692071
Mixin for methods common to WeekOfMonth and LastWeekOfMonth.
20702072
"""
2073+
_use_relativedelta = True
20712074

20722075
cdef readonly:
20732076
int weekday, week
@@ -2112,6 +2115,7 @@ cdef class YearOffset(SingleConstructorOffset):
21122115
DateOffset that just needs a month.
21132116
"""
21142117
_attributes = tuple(["n", "normalize", "month"])
2118+
_use_relativedelta = True
21152119

21162120
# FIXME(cython#4446): python annotation here gives compile-time errors
21172121
# _default_month: int
@@ -2277,6 +2281,7 @@ cdef class QuarterOffset(SingleConstructorOffset):
22772281
# FIXME(cython#4446): python annotation here gives compile-time errors
22782282
# _default_starting_month: int
22792283
# _from_name_starting_month: int
2284+
_use_relativedelta = True
22802285

22812286
cdef readonly:
22822287
int startingMonth
@@ -2448,6 +2453,8 @@ cdef class QuarterBegin(QuarterOffset):
24482453
# Month-Based Offset Classes
24492454

24502455
cdef class MonthOffset(SingleConstructorOffset):
2456+
_use_relativedelta = True
2457+
24512458
def is_on_offset(self, dt: datetime) -> bool:
24522459
if self.normalize and not _is_normalized(dt):
24532460
return False
@@ -2548,6 +2555,7 @@ cdef class SemiMonthOffset(SingleConstructorOffset):
25482555
_default_day_of_month = 15
25492556
_min_day_of_month = 2
25502557
_attributes = tuple(["n", "normalize", "day_of_month"])
2558+
_use_relativedelta = True
25512559

25522560
cdef readonly:
25532561
int day_of_month
@@ -2750,6 +2758,7 @@ cdef class Week(SingleConstructorOffset):
27502758
_inc = timedelta(weeks=1)
27512759
_prefix = "W"
27522760
_attributes = tuple(["n", "normalize", "weekday"])
2761+
_use_relativedelta = True
27532762

27542763
cdef readonly:
27552764
object weekday # int or None
@@ -3027,6 +3036,7 @@ cdef class LastWeekOfMonth(WeekOfMonthMixin):
30273036
# Special Offset Classes
30283037

30293038
cdef class FY5253Mixin(SingleConstructorOffset):
3039+
_use_relativedelta = True
30303040
cdef readonly:
30313041
int startingMonth
30323042
int weekday
@@ -3496,6 +3506,7 @@ cdef class Easter(SingleConstructorOffset):
34963506
>>> ts + pd.offsets.Easter()
34973507
Timestamp('2022-04-17 00:00:00')
34983508
"""
3509+
_use_relativedelta = True
34993510

35003511
cpdef __setstate__(self, state):
35013512
self.n = state.pop("n")

pandas/core/arrays/datetimes.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
tz_convert_from_utc,
4242
tzconversion,
4343
)
44-
from pandas._libs.tslibs.offsets import DateOffset
4544
from pandas._typing import npt
4645
from pandas.errors import (
4746
OutOfBoundsDatetime,
@@ -695,7 +694,7 @@ def _add_offset(self, offset) -> DatetimeArray:
695694
assert not isinstance(offset, Tick)
696695

697696
if self.tz is not None:
698-
if not offset._use_relativedelta and type(offset) == DateOffset:
697+
if not offset._use_relativedelta:
699698
values = self.tz_convert("utc").tz_localize(None)
700699
else:
701700
values = self.tz_localize(None)
@@ -720,7 +719,7 @@ def _add_offset(self, offset) -> DatetimeArray:
720719
result = DatetimeArray._simple_new(result, dtype=result.dtype)
721720
if self.tz is not None:
722721
# FIXME: tz_localize with non-nano
723-
if not offset._use_relativedelta and type(offset) == DateOffset:
722+
if not offset._use_relativedelta:
724723
result = result.tz_localize("utc").tz_convert(self.tz)
725724
else:
726725
result = result.tz_localize(self.tz)

0 commit comments

Comments
 (0)