@@ -959,7 +959,7 @@ def calc_dividend_ratios(self, dividends):
959
959
- effective_date, the date in seconds on which to apply the ratio.
960
960
- ratio, the ratio to apply to backwards looking pricing data.
961
961
"""
962
- if dividends is None :
962
+ if dividends is None or dividends . empty :
963
963
return DataFrame (np .array (
964
964
[],
965
965
dtype = [
@@ -978,12 +978,26 @@ def calc_dividend_ratios(self, dividends):
978
978
equity_daily_bar_reader = self ._equity_daily_bar_reader
979
979
980
980
effective_dates = full (len (amounts ), - 1 , dtype = int64 )
981
+
981
982
calendar = self ._calendar
983
+
984
+ # Calculate locs against a tz-naive cal, as the ex_dates are tz-
985
+ # naive.
986
+ #
987
+ # TODO: A better approach here would be to localize ex_date to
988
+ # the tz of the calendar, but currently get_indexer does not
989
+ # preserve tz of the target when method='bfill', which throws
990
+ # off the comparison.
991
+ tz_naive_calendar = calendar .tz_localize (None )
992
+ day_locs = tz_naive_calendar .get_indexer (ex_dates , method = 'bfill' )
993
+
982
994
for i , amount in enumerate (amounts ):
983
995
sid = sids [i ]
984
996
ex_date = ex_dates [i ]
985
- day_loc = calendar .get_loc (ex_date , method = 'bfill' )
997
+ day_loc = day_locs [i ]
998
+
986
999
prev_close_date = calendar [day_loc - 1 ]
1000
+
987
1001
try :
988
1002
prev_close = equity_daily_bar_reader .get_value (
989
1003
sid , prev_close_date , 'close' )
0 commit comments