@@ -975,8 +975,7 @@ def _infer_daily_rule(self):
975
975
else :
976
976
return _maybe_add_count ('D' , days )
977
977
978
- # Business daily. Maybe
979
- if self .day_deltas == [1 , 3 ]:
978
+ if self ._is_business_daily ():
980
979
return 'B'
981
980
982
981
wom_rule = self ._get_wom_rule ()
@@ -1012,6 +1011,19 @@ def _get_monthly_rule(self):
1012
1011
return {'cs' : 'MS' , 'bs' : 'BMS' ,
1013
1012
'ce' : 'M' , 'be' : 'BM' }.get (pos_check )
1014
1013
1014
+ def _is_business_daily (self ):
1015
+ # quick check: cannot be business daily
1016
+ if self .day_deltas != [1 , 3 ]:
1017
+ return False
1018
+
1019
+ # probably business daily, but need to confirm
1020
+ first_weekday = self .index [0 ].weekday ()
1021
+ shifts = np .diff (self .index .asi8 )
1022
+ shifts = np .floor_divide (shifts , _ONE_DAY )
1023
+ weekdays = np .mod (first_weekday + np .cumsum (shifts ), 7 )
1024
+ return np .all (((weekdays == 0 ) & (shifts == 3 )) |
1025
+ ((weekdays > 0 ) & (weekdays <= 4 ) & (shifts == 1 )))
1026
+
1015
1027
def _get_wom_rule (self ):
1016
1028
# wdiffs = unique(np.diff(self.index.week))
1017
1029
# We also need -47, -49, -48 to catch index spanning year boundary
0 commit comments