@@ -481,7 +481,7 @@ def history(self, period=period_default, interval="1d",
481481 # Must fix bad 'Adj Close' & dividends before 100x/split errors.
482482 # First make currency consistent. On some exchanges, dividends often in different currency
483483 # to prices, e.g. £ vs pence.
484- df , currency , div_scaled , prices_scaled = self ._standardise_currency (df , currency )
484+ df , currency , prices_scaled = self ._standardise_currency (df , currency )
485485 self ._history_metadata ['currency' ] = currency
486486
487487 f_na = df ['Volume' ].isna ()
@@ -516,8 +516,9 @@ def history(self, period=period_default, interval="1d",
516516 m = _CURRENCY_CONVERSIONS [original_currency ]
517517 for c in _PRICE_COLNAMES_ :
518518 df [c ] /= m
519- if div_scaled :
520- df ['Dividends' ] /= m
519+ # After running _fix_bad_div_adjust(), the dividends should always be in
520+ # same unit as prices
521+ df ['Dividends' ] /= m
521522 self ._history_metadata ['currency' ] = original_currency
522523 if 'currencyRepaired' in self ._history_metadata :
523524 del self ._history_metadata ['currencyRepaired' ]
@@ -1107,18 +1108,17 @@ def _reconstruct_intervals_batch(self, df, interval, prepost, tag=-1):
11071108 return df_v2
11081109
11091110 def _standardise_currency (self , df , currency ):
1110- div_scaled = False
11111111 prices_scaled = False
11121112 if currency not in _CURRENCY_CONVERSIONS :
1113- return df , currency , div_scaled , prices_scaled
1113+ return df , currency , prices_scaled
11141114 m = _CURRENCY_CONVERSIONS [currency ]
11151115 currency2 = {'GBp' : 'GBP' , 'ZAc' : 'ZAR' , 'ILA' : 'ILS' }[currency ]
11161116
11171117 # Use latest row with actual volume, because volume=0 rows can be 0.01x the other rows.
11181118 # _fix_unit_switch() will ensure all rows are on same scale.
11191119 f_volume = df ['Volume' ]> 0
11201120 if not f_volume .any ():
1121- return df , currency , div_scaled , prices_scaled
1121+ return df , currency , prices_scaled
11221122 last_row = df .iloc [np .where (f_volume )[0 ][- 1 ]]
11231123 prices_in_subunits = True # usually is true
11241124 if last_row .name > (pd .Timestamp .now ('UTC' ) - _datetime .timedelta (days = 30 )):
@@ -1153,9 +1153,8 @@ def _standardise_currency(self, df, currency):
11531153 div_pcts = (divs ['Dividends' ] / divs ['Close' ]).to_numpy ()
11541154 if len (div_pcts ) > 0 and np .average (div_pcts ) > 1 :
11551155 df ['Dividends' ] *= m
1156- div_scaled = True
11571156
1158- return df , currency2 , div_scaled , prices_scaled
1157+ return df , currency2 , prices_scaled
11591158
11601159 def _dividends_convert_fx (self , dividends , fx , repair = False ):
11611160 bad_div_currencies = [c for c in dividends ['currency' ].unique () if c != fx ]
0 commit comments