@@ -365,7 +365,7 @@ def apply_index(self, i):
365
365
"applied vectorized"
366
366
)
367
367
368
- def is_anchored (self ):
368
+ def is_anchored (self ) -> bool :
369
369
# TODO: Does this make sense for the general case? It would help
370
370
# if there were a canonical docstring for what is_anchored means.
371
371
return self .n == 1
@@ -378,7 +378,7 @@ def onOffset(self, dt):
378
378
)
379
379
return self .is_on_offset (dt )
380
380
381
- def isAnchored (self ):
381
+ def isAnchored (self ) -> bool :
382
382
warnings .warn (
383
383
"isAnchored is a deprecated, use is_anchored instead" ,
384
384
FutureWarning ,
@@ -389,7 +389,7 @@ def isAnchored(self):
389
389
# TODO: Combine this with BusinessMixin version by defining a whitelisted
390
390
# set of attributes on each object rather than the existing behavior of
391
391
# iterating over internal ``__dict__``
392
- def _repr_attrs (self ):
392
+ def _repr_attrs (self ) -> str :
393
393
exclude = {"n" , "inc" , "normalize" }
394
394
attrs = []
395
395
for attr in sorted (self .__dict__ ):
@@ -405,7 +405,7 @@ def _repr_attrs(self):
405
405
return out
406
406
407
407
@property
408
- def name (self ):
408
+ def name (self ) -> str :
409
409
return self .rule_code
410
410
411
411
def rollback (self , dt ):
@@ -452,15 +452,15 @@ def is_on_offset(self, dt):
452
452
453
453
# way to get around weirdness with rule_code
454
454
@property
455
- def _prefix (self ):
455
+ def _prefix (self ) -> str :
456
456
raise NotImplementedError ("Prefix not defined" )
457
457
458
458
@property
459
- def rule_code (self ):
459
+ def rule_code (self ) -> str :
460
460
return self ._prefix
461
461
462
462
@cache_readonly
463
- def freqstr (self ):
463
+ def freqstr (self ) -> str :
464
464
try :
465
465
code = self .rule_code
466
466
except NotImplementedError :
@@ -480,7 +480,7 @@ def freqstr(self):
480
480
481
481
return fstr
482
482
483
- def _offset_str (self ):
483
+ def _offset_str (self ) -> str :
484
484
return ""
485
485
486
486
@property
@@ -529,11 +529,11 @@ def offset(self):
529
529
# Alias for backward compat
530
530
return self ._offset
531
531
532
- def _repr_attrs (self ):
532
+ def _repr_attrs (self ) -> str :
533
533
if self .offset :
534
534
attrs = [f"offset={ repr (self .offset )} " ]
535
535
else :
536
- attrs = None
536
+ attrs = []
537
537
out = ""
538
538
if attrs :
539
539
out += ": " + ", " .join (attrs )
@@ -553,7 +553,7 @@ def __init__(self, n=1, normalize=False, offset=timedelta(0)):
553
553
BaseOffset .__init__ (self , n , normalize )
554
554
object .__setattr__ (self , "_offset" , offset )
555
555
556
- def _offset_str (self ):
556
+ def _offset_str (self ) -> str :
557
557
def get_str (td ):
558
558
off_str = ""
559
559
if td .days > 0 :
@@ -649,7 +649,7 @@ def apply_index(self, i):
649
649
result = shifted .to_timestamp () + time
650
650
return result
651
651
652
- def is_on_offset (self , dt ) :
652
+ def is_on_offset (self , dt : datetime ) -> bool :
653
653
if self .normalize and not _is_normalized (dt ):
654
654
return False
655
655
return dt .weekday () < 5
@@ -1087,7 +1087,7 @@ def apply(self, other):
1087
1087
def apply_index (self , i ):
1088
1088
raise NotImplementedError
1089
1089
1090
- def is_on_offset (self , dt ) :
1090
+ def is_on_offset (self , dt : datetime ) -> bool :
1091
1091
if self .normalize and not _is_normalized (dt ):
1092
1092
return False
1093
1093
day64 = _to_dt64 (dt , "datetime64[D]" )
@@ -1134,14 +1134,14 @@ class MonthOffset(SingleConstructorOffset):
1134
1134
__init__ = BaseOffset .__init__
1135
1135
1136
1136
@property
1137
- def name (self ):
1137
+ def name (self ) -> str :
1138
1138
if self .is_anchored :
1139
1139
return self .rule_code
1140
1140
else :
1141
1141
month = ccalendar .MONTH_ALIASES [self .n ]
1142
1142
return f"{ self .code_rule } -{ month } "
1143
1143
1144
- def is_on_offset (self , dt ) :
1144
+ def is_on_offset (self , dt : datetime ) -> bool :
1145
1145
if self .normalize and not _is_normalized (dt ):
1146
1146
return False
1147
1147
return dt .day == self ._get_offset_day (dt )
@@ -1333,7 +1333,7 @@ def _from_name(cls, suffix=None):
1333
1333
return cls (day_of_month = suffix )
1334
1334
1335
1335
@property
1336
- def rule_code (self ):
1336
+ def rule_code (self ) -> str :
1337
1337
suffix = f"-{ self .day_of_month } "
1338
1338
return self ._prefix + suffix
1339
1339
@@ -1429,7 +1429,7 @@ class SemiMonthEnd(SemiMonthOffset):
1429
1429
_prefix = "SM"
1430
1430
_min_day_of_month = 1
1431
1431
1432
- def is_on_offset (self , dt ) :
1432
+ def is_on_offset (self , dt : datetime ) -> bool :
1433
1433
if self .normalize and not _is_normalized (dt ):
1434
1434
return False
1435
1435
days_in_month = ccalendar .get_days_in_month (dt .year , dt .month )
@@ -1487,7 +1487,7 @@ class SemiMonthBegin(SemiMonthOffset):
1487
1487
1488
1488
_prefix = "SMS"
1489
1489
1490
- def is_on_offset (self , dt ) :
1490
+ def is_on_offset (self , dt : datetime ) -> bool :
1491
1491
if self .normalize and not _is_normalized (dt ):
1492
1492
return False
1493
1493
return dt .day in (1 , self .day_of_month )
@@ -1556,7 +1556,7 @@ def __init__(self, n=1, normalize=False, weekday=None):
1556
1556
if self .weekday < 0 or self .weekday > 6 :
1557
1557
raise ValueError (f"Day must be 0<=day<=6, got { self .weekday } " )
1558
1558
1559
- def is_anchored (self ):
1559
+ def is_anchored (self ) -> bool :
1560
1560
return self .n == 1 and self .weekday is not None
1561
1561
1562
1562
@apply_wraps
@@ -1632,15 +1632,15 @@ def _end_apply_index(self, dtindex):
1632
1632
1633
1633
return base + off + Timedelta (1 , "ns" ) - Timedelta (1 , "D" )
1634
1634
1635
- def is_on_offset (self , dt ) :
1635
+ def is_on_offset (self , dt : datetime ) -> bool :
1636
1636
if self .normalize and not _is_normalized (dt ):
1637
1637
return False
1638
1638
elif self .weekday is None :
1639
1639
return True
1640
1640
return dt .weekday () == self .weekday
1641
1641
1642
1642
@property
1643
- def rule_code (self ):
1643
+ def rule_code (self ) -> str :
1644
1644
suffix = ""
1645
1645
if self .weekday is not None :
1646
1646
weekday = ccalendar .int_to_weekday [self .weekday ]
@@ -1717,7 +1717,7 @@ def __init__(self, n=1, normalize=False, week=0, weekday=0):
1717
1717
if self .week < 0 or self .week > 3 :
1718
1718
raise ValueError (f"Week must be 0<=week<=3, got { self .week } " )
1719
1719
1720
- def _get_offset_day (self , other ) :
1720
+ def _get_offset_day (self , other : datetime ) -> int :
1721
1721
"""
1722
1722
Find the day in the same month as other that has the same
1723
1723
weekday as self.weekday and is the self.week'th such day in the month.
@@ -1736,7 +1736,7 @@ def _get_offset_day(self, other):
1736
1736
return 1 + shift_days + self .week * 7
1737
1737
1738
1738
@property
1739
- def rule_code (self ):
1739
+ def rule_code (self ) -> str :
1740
1740
weekday = ccalendar .int_to_weekday .get (self .weekday , "" )
1741
1741
return f"{ self ._prefix } -{ self .week + 1 } { weekday } "
1742
1742
@@ -1785,7 +1785,7 @@ def __init__(self, n=1, normalize=False, weekday=0):
1785
1785
if self .weekday < 0 or self .weekday > 6 :
1786
1786
raise ValueError (f"Day must be 0<=day<=6, got { self .weekday } " )
1787
1787
1788
- def _get_offset_day (self , other ) :
1788
+ def _get_offset_day (self , other : datetime ) -> int :
1789
1789
"""
1790
1790
Find the day in the same month as other that has the same
1791
1791
weekday as self.weekday and is the last such day in the month.
@@ -1805,7 +1805,7 @@ def _get_offset_day(self, other):
1805
1805
return dim - shift_days
1806
1806
1807
1807
@property
1808
- def rule_code (self ):
1808
+ def rule_code (self ) -> str :
1809
1809
weekday = ccalendar .int_to_weekday .get (self .weekday , "" )
1810
1810
return f"{ self ._prefix } -{ weekday } "
1811
1811
@@ -1842,7 +1842,7 @@ def __init__(self, n=1, normalize=False, startingMonth=None):
1842
1842
startingMonth = self ._default_startingMonth
1843
1843
object .__setattr__ (self , "startingMonth" , startingMonth )
1844
1844
1845
- def is_anchored (self ):
1845
+ def is_anchored (self ) -> bool :
1846
1846
return self .n == 1 and self .startingMonth is not None
1847
1847
1848
1848
@classmethod
@@ -1856,7 +1856,7 @@ def _from_name(cls, suffix=None):
1856
1856
return cls (** kwargs )
1857
1857
1858
1858
@property
1859
- def rule_code (self ):
1859
+ def rule_code (self ) -> str :
1860
1860
month = ccalendar .MONTH_ALIASES [self .startingMonth ]
1861
1861
return f"{ self ._prefix } -{ month } "
1862
1862
@@ -1874,7 +1874,7 @@ def apply(self, other):
1874
1874
months = qtrs * 3 - months_since
1875
1875
return shift_month (other , months , self ._day_opt )
1876
1876
1877
- def is_on_offset (self , dt ) :
1877
+ def is_on_offset (self , dt : datetime ) -> bool :
1878
1878
if self .normalize and not _is_normalized (dt ):
1879
1879
return False
1880
1880
mod_month = (dt .month - self .startingMonth ) % 3
@@ -1953,7 +1953,7 @@ class YearOffset(DateOffset):
1953
1953
_adjust_dst = True
1954
1954
_attributes = frozenset (["n" , "normalize" , "month" ])
1955
1955
1956
- def _get_offset_day (self , other ) :
1956
+ def _get_offset_day (self , other : datetime ) -> int :
1957
1957
# override BaseOffset method to use self.month instead of other.month
1958
1958
# TODO: there may be a more performant way to do this
1959
1959
return liboffsets .get_day_of_month (
@@ -1977,7 +1977,7 @@ def apply_index(self, dtindex):
1977
1977
shifted , freq = dtindex .freq , dtype = dtindex .dtype
1978
1978
)
1979
1979
1980
- def is_on_offset (self , dt ) :
1980
+ def is_on_offset (self , dt : datetime ) -> bool :
1981
1981
if self .normalize and not _is_normalized (dt ):
1982
1982
return False
1983
1983
return dt .month == self .month and dt .day == self ._get_offset_day (dt )
@@ -1999,7 +1999,7 @@ def _from_name(cls, suffix=None):
1999
1999
return cls (** kwargs )
2000
2000
2001
2001
@property
2002
- def rule_code (self ):
2002
+ def rule_code (self ) -> str :
2003
2003
month = ccalendar .MONTH_ALIASES [self .month ]
2004
2004
return f"{ self ._prefix } -{ month } "
2005
2005
@@ -2117,12 +2117,12 @@ def __init__(
2117
2117
if self .variation not in ["nearest" , "last" ]:
2118
2118
raise ValueError (f"{ self .variation } is not a valid variation" )
2119
2119
2120
- def is_anchored (self ):
2120
+ def is_anchored (self ) -> bool :
2121
2121
return (
2122
2122
self .n == 1 and self .startingMonth is not None and self .weekday is not None
2123
2123
)
2124
2124
2125
- def is_on_offset (self , dt ) :
2125
+ def is_on_offset (self , dt : datetime ) -> bool :
2126
2126
if self .normalize and not _is_normalized (dt ):
2127
2127
return False
2128
2128
dt = datetime (dt .year , dt .month , dt .day )
@@ -2217,18 +2217,18 @@ def get_year_end(self, dt):
2217
2217
return target_date + timedelta (days_forward - 7 )
2218
2218
2219
2219
@property
2220
- def rule_code (self ):
2220
+ def rule_code (self ) -> str :
2221
2221
prefix = self ._prefix
2222
2222
suffix = self .get_rule_code_suffix ()
2223
2223
return f"{ prefix } -{ suffix } "
2224
2224
2225
- def _get_suffix_prefix (self ):
2225
+ def _get_suffix_prefix (self ) -> str :
2226
2226
if self .variation == "nearest" :
2227
2227
return "N"
2228
2228
else :
2229
2229
return "L"
2230
2230
2231
- def get_rule_code_suffix (self ):
2231
+ def get_rule_code_suffix (self ) -> str :
2232
2232
prefix = self ._get_suffix_prefix ()
2233
2233
month = ccalendar .MONTH_ALIASES [self .startingMonth ]
2234
2234
weekday = ccalendar .int_to_weekday [self .weekday ]
@@ -2346,7 +2346,7 @@ def _offset(self):
2346
2346
variation = self .variation ,
2347
2347
)
2348
2348
2349
- def is_anchored (self ):
2349
+ def is_anchored (self ) -> bool :
2350
2350
return self .n == 1 and self ._offset .is_anchored ()
2351
2351
2352
2352
def _rollback_to_year (self , other ):
@@ -2434,7 +2434,7 @@ def get_weeks(self, dt):
2434
2434
2435
2435
return ret
2436
2436
2437
- def year_has_extra_week (self , dt ) :
2437
+ def year_has_extra_week (self , dt : datetime ) -> bool :
2438
2438
# Avoid round-down errors --> normalize to get
2439
2439
# e.g. '370D' instead of '360D23H'
2440
2440
norm = Timestamp (dt ).normalize ().tz_localize (None )
@@ -2445,7 +2445,7 @@ def year_has_extra_week(self, dt):
2445
2445
assert weeks_in_year in [52 , 53 ], weeks_in_year
2446
2446
return weeks_in_year == 53
2447
2447
2448
- def is_on_offset (self , dt ) :
2448
+ def is_on_offset (self , dt : datetime ) -> bool :
2449
2449
if self .normalize and not _is_normalized (dt ):
2450
2450
return False
2451
2451
if self ._offset .is_on_offset (dt ):
@@ -2463,7 +2463,7 @@ def is_on_offset(self, dt):
2463
2463
return False
2464
2464
2465
2465
@property
2466
- def rule_code (self ):
2466
+ def rule_code (self ) -> str :
2467
2467
suffix = self ._offset .get_rule_code_suffix ()
2468
2468
qtr = self .qtr_with_extra_week
2469
2469
return f"{ self ._prefix } -{ suffix } -{ qtr } "
@@ -2516,7 +2516,7 @@ def apply(self, other):
2516
2516
)
2517
2517
return new
2518
2518
2519
- def is_on_offset (self , dt ) :
2519
+ def is_on_offset (self , dt : datetime ) -> bool :
2520
2520
if self .normalize and not _is_normalized (dt ):
2521
2521
return False
2522
2522
return date (dt .year , dt .month , dt .day ) == easter (dt .year )
@@ -2596,7 +2596,7 @@ def __eq__(self, other: Any) -> bool:
2596
2596
2597
2597
# This is identical to DateOffset.__hash__, but has to be redefined here
2598
2598
# for Python 3, because we've redefined __eq__.
2599
- def __hash__ (self ):
2599
+ def __hash__ (self ) -> int :
2600
2600
return hash (self ._params )
2601
2601
2602
2602
def __ne__ (self , other ):
@@ -2617,7 +2617,7 @@ def __ne__(self, other):
2617
2617
return True
2618
2618
2619
2619
@property
2620
- def delta (self ):
2620
+ def delta (self ) -> Timedelta :
2621
2621
return self .n * self ._inc
2622
2622
2623
2623
@property
@@ -2648,11 +2648,11 @@ def apply(self, other):
2648
2648
2649
2649
raise ApplyTypeError (f"Unhandled type: { type (other ).__name__ } " )
2650
2650
2651
- def is_anchored (self ):
2651
+ def is_anchored (self ) -> bool :
2652
2652
return False
2653
2653
2654
2654
2655
- def _delta_to_tick (delta ) :
2655
+ def _delta_to_tick (delta : timedelta ) -> Tick :
2656
2656
if delta .microseconds == 0 and getattr (delta , "nanoseconds" , 0 ) == 0 :
2657
2657
# nanoseconds only for pd.Timedelta
2658
2658
if delta .seconds == 0 :
0 commit comments