@@ -975,8 +975,7 @@ def _infer_daily_rule(self):
975975 else :
976976 return _maybe_add_count ('D' , days )
977977
978- # Business daily. Maybe
979- if self .day_deltas == [1 , 3 ]:
978+ if self ._is_business_daily ():
980979 return 'B'
981980
982981 wom_rule = self ._get_wom_rule ()
@@ -1012,6 +1011,19 @@ def _get_monthly_rule(self):
10121011 return {'cs' : 'MS' , 'bs' : 'BMS' ,
10131012 'ce' : 'M' , 'be' : 'BM' }.get (pos_check )
10141013
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+
10151027 def _get_wom_rule (self ):
10161028 # wdiffs = unique(np.diff(self.index.week))
10171029 # We also need -47, -49, -48 to catch index spanning year boundary
0 commit comments