@@ -176,6 +176,7 @@ def __add__(date):
176
176
_params = cache_readonly (BaseOffset ._params .fget )
177
177
freqstr = cache_readonly (BaseOffset .freqstr .fget )
178
178
_attributes = frozenset (["n" , "normalize" ] + list (liboffsets .relativedelta_kwds ))
179
+ _adjust_dst = False
179
180
180
181
def __init__ (self , n = 1 , normalize = False , ** kwds ):
181
182
BaseOffset .__init__ (self , n , normalize )
@@ -228,11 +229,6 @@ def apply_index(self, i):
228
229
-------
229
230
y : DatetimeIndex
230
231
"""
231
- if type (self ) is not DateOffset :
232
- raise NotImplementedError (
233
- f"DateOffset subclass { type (self ).__name__ } "
234
- "does not have a vectorized implementation"
235
- )
236
232
kwds = self .kwds
237
233
relativedelta_fast = {
238
234
"years" ,
@@ -308,18 +304,17 @@ def is_on_offset(self, dt):
308
304
if self .normalize and not is_normalized (dt ):
309
305
return False
310
306
# TODO, see #1395
311
- if type (self ) is DateOffset :
312
- return True
313
-
314
- # Default (slow) method for determining if some date is a member of the
315
- # date range generated by this offset. Subclasses may have this
316
- # re-implemented in a nicer way.
317
- a = dt
318
- b = (dt + self ) - self
319
- return a == b
307
+ return True
320
308
321
309
322
310
class SingleConstructorOffset (DateOffset ):
311
+ # All DateOffset subclasses (other than Tick) subclass SingleConstructorOffset
312
+ __init__ = BaseOffset .__init__
313
+ _attributes = BaseOffset ._attributes
314
+ apply_index = BaseOffset .apply_index
315
+ is_on_offset = BaseOffset .is_on_offset
316
+ _adjust_dst = True
317
+
323
318
@classmethod
324
319
def _from_name (cls , suffix = None ):
325
320
# default _from_name calls cls with no args
@@ -334,7 +329,6 @@ class BusinessDay(BusinessMixin, SingleConstructorOffset):
334
329
"""
335
330
336
331
_prefix = "B"
337
- _adjust_dst = True
338
332
_attributes = frozenset (["n" , "normalize" , "offset" ])
339
333
340
334
def __init__ (self , n = 1 , normalize = False , offset = timedelta (0 )):
@@ -441,6 +435,8 @@ def is_on_offset(self, dt: datetime) -> bool:
441
435
442
436
443
437
class BusinessHourMixin (BusinessMixin ):
438
+ _adjust_dst = False
439
+
444
440
def __init__ (self , start = "09:00" , end = "17:00" , offset = timedelta (0 )):
445
441
# must be validated here to equality check
446
442
if not is_list_like (start ):
@@ -912,11 +908,6 @@ def __init__(
912
908
913
909
914
910
class MonthOffset (SingleConstructorOffset ):
915
- _adjust_dst = True
916
- _attributes = frozenset (["n" , "normalize" ])
917
-
918
- __init__ = BaseOffset .__init__
919
-
920
911
def is_on_offset (self , dt : datetime ) -> bool :
921
912
if self .normalize and not is_normalized (dt ):
922
913
return False
@@ -997,8 +988,8 @@ class _CustomBusinessMonth(CustomMixin, BusinessMixin, MonthOffset):
997
988
["n" , "normalize" , "weekmask" , "holidays" , "calendar" , "offset" ]
998
989
)
999
990
1000
- is_on_offset = DateOffset .is_on_offset # override MonthOffset method
1001
- apply_index = DateOffset .apply_index # override MonthOffset method
991
+ is_on_offset = BaseOffset .is_on_offset # override MonthOffset method
992
+ apply_index = BaseOffset .apply_index # override MonthOffset method
1002
993
1003
994
def __init__ (
1004
995
self ,
@@ -1082,8 +1073,7 @@ class CustomBusinessMonthBegin(_CustomBusinessMonth):
1082
1073
# Semi-Month Based Offset Classes
1083
1074
1084
1075
1085
- class SemiMonthOffset (DateOffset ):
1086
- _adjust_dst = True
1076
+ class SemiMonthOffset (SingleConstructorOffset ):
1087
1077
_default_day_of_month = 15
1088
1078
_min_day_of_month = 2
1089
1079
_attributes = frozenset (["n" , "normalize" , "day_of_month" ])
@@ -1304,7 +1294,7 @@ def _apply_index_days(self, i, roll):
1304
1294
# Week-Based Offset Classes
1305
1295
1306
1296
1307
- class Week (DateOffset ):
1297
+ class Week (SingleConstructorOffset ):
1308
1298
"""
1309
1299
Weekly offset.
1310
1300
@@ -1314,7 +1304,6 @@ class Week(DateOffset):
1314
1304
Always generate specific day of week. 0 for Monday.
1315
1305
"""
1316
1306
1317
- _adjust_dst = True
1318
1307
_inc = timedelta (weeks = 1 )
1319
1308
_prefix = "W"
1320
1309
_attributes = frozenset (["n" , "normalize" , "weekday" ])
@@ -1446,7 +1435,7 @@ def is_on_offset(self, dt):
1446
1435
return dt .day == self ._get_offset_day (dt )
1447
1436
1448
1437
1449
- class WeekOfMonth (_WeekOfMonthMixin , DateOffset ):
1438
+ class WeekOfMonth (_WeekOfMonthMixin , SingleConstructorOffset ):
1450
1439
"""
1451
1440
Describes monthly dates like "the Tuesday of the 2nd week of each month".
1452
1441
@@ -1469,7 +1458,6 @@ class WeekOfMonth(_WeekOfMonthMixin, DateOffset):
1469
1458
"""
1470
1459
1471
1460
_prefix = "WOM"
1472
- _adjust_dst = True
1473
1461
_attributes = frozenset (["n" , "normalize" , "week" , "weekday" ])
1474
1462
1475
1463
def __init__ (self , n = 1 , normalize = False , week = 0 , weekday = 0 ):
@@ -1516,7 +1504,7 @@ def _from_name(cls, suffix=None):
1516
1504
return cls (week = week , weekday = weekday )
1517
1505
1518
1506
1519
- class LastWeekOfMonth (_WeekOfMonthMixin , DateOffset ):
1507
+ class LastWeekOfMonth (_WeekOfMonthMixin , SingleConstructorOffset ):
1520
1508
"""
1521
1509
Describes monthly dates in last week of month like "the last Tuesday of
1522
1510
each month".
@@ -1537,7 +1525,6 @@ class LastWeekOfMonth(_WeekOfMonthMixin, DateOffset):
1537
1525
"""
1538
1526
1539
1527
_prefix = "LWOM"
1540
- _adjust_dst = True
1541
1528
_attributes = frozenset (["n" , "normalize" , "weekday" ])
1542
1529
1543
1530
def __init__ (self , n = 1 , normalize = False , weekday = 0 ):
@@ -1587,14 +1574,13 @@ def _from_name(cls, suffix=None):
1587
1574
# Quarter-Based Offset Classes
1588
1575
1589
1576
1590
- class QuarterOffset (DateOffset ):
1577
+ class QuarterOffset (SingleConstructorOffset ):
1591
1578
"""
1592
1579
Quarter representation - doesn't call super.
1593
1580
"""
1594
1581
1595
1582
_default_startingMonth : Optional [int ] = None
1596
1583
_from_name_startingMonth : Optional [int ] = None
1597
- _adjust_dst = True
1598
1584
_attributes = frozenset (["n" , "normalize" , "startingMonth" ])
1599
1585
# TODO: Consider combining QuarterOffset and YearOffset __init__ at some
1600
1586
# point. Also apply_index, is_on_offset, rule_code if
@@ -1706,12 +1692,11 @@ class QuarterBegin(QuarterOffset):
1706
1692
# Year-Based Offset Classes
1707
1693
1708
1694
1709
- class YearOffset (DateOffset ):
1695
+ class YearOffset (SingleConstructorOffset ):
1710
1696
"""
1711
1697
DateOffset that just needs a month.
1712
1698
"""
1713
1699
1714
- _adjust_dst = True
1715
1700
_attributes = frozenset (["n" , "normalize" , "month" ])
1716
1701
1717
1702
def _get_offset_day (self , other : datetime ) -> int :
@@ -1807,7 +1792,7 @@ class YearBegin(YearOffset):
1807
1792
# Special Offset Classes
1808
1793
1809
1794
1810
- class FY5253 (DateOffset ):
1795
+ class FY5253 (SingleConstructorOffset ):
1811
1796
"""
1812
1797
Describes 52-53 week fiscal year. This is also known as a 4-4-5 calendar.
1813
1798
@@ -1856,7 +1841,6 @@ class FY5253(DateOffset):
1856
1841
"""
1857
1842
1858
1843
_prefix = "RE"
1859
- _adjust_dst = True
1860
1844
_attributes = frozenset (["weekday" , "startingMonth" , "variation" ])
1861
1845
1862
1846
def __init__ (
@@ -2014,7 +1998,7 @@ def _from_name(cls, *args):
2014
1998
return cls (** cls ._parse_suffix (* args ))
2015
1999
2016
2000
2017
- class FY5253Quarter (DateOffset ):
2001
+ class FY5253Quarter (SingleConstructorOffset ):
2018
2002
"""
2019
2003
DateOffset increments between business quarter dates
2020
2004
for 52-53 week fiscal year (also known as a 4-4-5 calendar).
@@ -2071,7 +2055,6 @@ class FY5253Quarter(DateOffset):
2071
2055
"""
2072
2056
2073
2057
_prefix = "REQ"
2074
- _adjust_dst = True
2075
2058
_attributes = frozenset (
2076
2059
["weekday" , "startingMonth" , "qtr_with_extra_week" , "variation" ]
2077
2060
)
@@ -2232,18 +2215,13 @@ def _from_name(cls, *args):
2232
2215
)
2233
2216
2234
2217
2235
- class Easter (DateOffset ):
2218
+ class Easter (SingleConstructorOffset ):
2236
2219
"""
2237
2220
DateOffset for the Easter holiday using logic defined in dateutil.
2238
2221
2239
2222
Right now uses the revised method which is valid in years 1583-4099.
2240
2223
"""
2241
2224
2242
- _adjust_dst = True
2243
- _attributes = frozenset (["n" , "normalize" ])
2244
-
2245
- __init__ = BaseOffset .__init__
2246
-
2247
2225
@apply_wraps
2248
2226
def apply (self , other ):
2249
2227
current_easter = easter (other .year )
0 commit comments