@@ -358,7 +358,6 @@ cdef class BaseOffset:
358
358
Base class for DateOffset methods that are not overridden by subclasses
359
359
and will (after pickle errors are resolved) go into a cdef class.
360
360
"""
361
- _typ = " dateoffset"
362
361
_day_opt = None
363
362
_attributes = tuple ([" n" , " normalize" ])
364
363
_use_relativedelta = False
@@ -394,7 +393,7 @@ cdef class BaseOffset:
394
393
def __ne__ (self , other ):
395
394
return not self == other
396
395
397
- def __hash__ (self ):
396
+ def __hash__ (self ) -> int :
398
397
return hash(self._params )
399
398
400
399
@cache_readonly
@@ -422,10 +421,10 @@ cdef class BaseOffset:
422
421
return params
423
422
424
423
@property
425
- def kwds (self ):
424
+ def kwds (self ) -> dict :
426
425
# for backwards-compatibility
427
426
kwds = {name: getattr (self , name, None ) for name in self ._attributes
428
- if name not in [' n ' , ' normalize' ]}
427
+ if name not in [" n " , " normalize" ]}
429
428
return {name: kwds[name] for name in kwds if kwds[name] is not None}
430
429
431
430
@property
@@ -582,7 +581,7 @@ cdef class BaseOffset:
582
581
" does not have a vectorized implementation"
583
582
)
584
583
585
- def rollback (self , dt ):
584
+ def rollback (self , dt ) -> datetime :
586
585
"""
587
586
Roll provided date backward to next offset only if not on offset.
588
587
@@ -596,7 +595,7 @@ cdef class BaseOffset:
596
595
dt = dt - type (self )(1 , normalize = self .normalize, ** self .kwds)
597
596
return dt
598
597
599
- def rollforward (self , dt ):
598
+ def rollforward (self , dt ) -> datetime :
600
599
"""
601
600
Roll provided date forward to next offset only if not on offset.
602
601
@@ -618,7 +617,7 @@ cdef class BaseOffset:
618
617
pydate_to_dtstruct(other , &dts )
619
618
return get_day_of_month(&dts , self._day_opt )
620
619
621
- def is_on_offset(self , dt ) -> bool:
620
+ def is_on_offset(self , dt: datetime ) -> bool:
622
621
if self.normalize and not _is_normalized(dt ):
623
622
return False
624
623
@@ -780,6 +779,8 @@ cdef class Tick(SingleConstructorOffset):
780
779
def nanos (self ) -> int64_t:
781
780
return self.n * self._nanos_inc
782
781
782
+ # FIXME: This should be typed as datetime , but we DatetimeLikeIndex.insert
783
+ # checks self.freq.is_on_offset with a Timedelta sometimes.
783
784
def is_on_offset(self , dt ) -> bool:
784
785
return True
785
786
@@ -861,16 +862,8 @@ cdef class Tick(SingleConstructorOffset):
861
862
def apply (self , other ):
862
863
# Timestamp can handle tz and nano sec, thus no need to use apply_wraps
863
864
if isinstance (other, _Timestamp):
864
-
865
865
# GH#15126
866
- # in order to avoid a recursive
867
- # call of __add__ and __radd__ if there is
868
- # an exception, when we call using the + operator,
869
- # we directly call the known method
870
- result = other.__add__ (self )
871
- if result is NotImplemented :
872
- raise OverflowError
873
- return result
866
+ return other + self .delta
874
867
elif other is NaT:
875
868
return NaT
876
869
elif is_datetime64_object(other) or PyDate_Check(other):
@@ -1097,7 +1090,7 @@ cdef class RelativeDeltaOffset(BaseOffset):
1097
1090
" applied vectorized"
1098
1091
)
1099
1092
1100
- def is_on_offset (self , dt ) -> bool:
1093
+ def is_on_offset (self , dt: datetime ) -> bool:
1101
1094
if self.normalize and not _is_normalized(dt ):
1102
1095
return False
1103
1096
# TODO: see GH#1395
@@ -1384,7 +1377,7 @@ cdef class BusinessDay(BusinessMixin):
1384
1377
i8other = dtindex.view(" i8" )
1385
1378
return shift_bdays(i8other, self .n)
1386
1379
1387
- def is_on_offset (self , dt ) -> bool:
1380
+ def is_on_offset (self , dt: datetime ) -> bool:
1388
1381
if self.normalize and not _is_normalized(dt ):
1389
1382
return False
1390
1383
return dt.weekday() < 5
@@ -1788,7 +1781,7 @@ cdef class WeekOfMonthMixin(SingleConstructorOffset):
1788
1781
to_day = self ._get_offset_day(shifted)
1789
1782
return shift_day(shifted , to_day - shifted.day )
1790
1783
1791
- def is_on_offset(self , dt ) -> bool:
1784
+ def is_on_offset(self , dt: datetime ) -> bool:
1792
1785
if self.normalize and not _is_normalized(dt ):
1793
1786
return False
1794
1787
return dt.day == self ._get_offset_day(dt)
@@ -1843,12 +1836,12 @@ cdef class YearOffset(SingleConstructorOffset):
1843
1836
month = MONTH_ALIASES[self .month]
1844
1837
return f"{self._prefix}-{month}"
1845
1838
1846
- def is_on_offset(self , dt ) -> bool:
1839
+ def is_on_offset(self , dt: datetime ) -> bool:
1847
1840
if self.normalize and not _is_normalized(dt ):
1848
1841
return False
1849
1842
return dt.month == self .month and dt.day == self ._get_offset_day(dt)
1850
1843
1851
- def _get_offset_day (self , other ) -> int:
1844
+ def _get_offset_day (self , other: datetime ) -> int:
1852
1845
# override BaseOffset method to use self.month instead of other.month
1853
1846
cdef:
1854
1847
npy_datetimestruct dts
@@ -1995,7 +1988,7 @@ cdef class QuarterOffset(SingleConstructorOffset):
1995
1988
def is_anchored(self ) -> bool:
1996
1989
return self.n == 1 and self.startingMonth is not None
1997
1990
1998
- def is_on_offset(self , dt ) -> bool:
1991
+ def is_on_offset(self , dt: datetime ) -> bool:
1999
1992
if self.normalize and not _is_normalized(dt ):
2000
1993
return False
2001
1994
mod_month = (dt.month - self .startingMonth) % 3
@@ -2119,7 +2112,7 @@ cdef class QuarterBegin(QuarterOffset):
2119
2112
# Month-Based Offset Classes
2120
2113
2121
2114
cdef class MonthOffset(SingleConstructorOffset):
2122
- def is_on_offset (self , dt ) -> bool:
2115
+ def is_on_offset (self , dt: datetime ) -> bool:
2123
2116
if self.normalize and not _is_normalized(dt ):
2124
2117
return False
2125
2118
return dt.day == self ._get_offset_day(dt)
@@ -2339,7 +2332,7 @@ cdef class SemiMonthEnd(SemiMonthOffset):
2339
2332
_prefix = " SM"
2340
2333
_min_day_of_month = 1
2341
2334
2342
- def is_on_offset (self , dt ) -> bool:
2335
+ def is_on_offset (self , dt: datetime ) -> bool:
2343
2336
if self.normalize and not _is_normalized(dt ):
2344
2337
return False
2345
2338
days_in_month = get_days_in_month(dt.year, dt.month)
@@ -2360,7 +2353,7 @@ cdef class SemiMonthBegin(SemiMonthOffset):
2360
2353
2361
2354
_prefix = " SMS"
2362
2355
2363
- def is_on_offset (self , dt ) -> bool:
2356
+ def is_on_offset (self , dt: datetime ) -> bool:
2364
2357
if self.normalize and not _is_normalized(dt ):
2365
2358
return False
2366
2359
return dt.day in (1 , self .day_of_month)
@@ -2375,8 +2368,8 @@ cdef class Week(SingleConstructorOffset):
2375
2368
Weekly offset.
2376
2369
2377
2370
Parameters
2378
- ----------f
2379
- weekday : int, default None
2371
+ ----------
2372
+ weekday : int or None , default None
2380
2373
Always generate specific day of week. 0 for Monday.
2381
2374
"""
2382
2375
0 commit comments