Skip to content

Commit

Permalink
Hide divide-by-0 warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
ValueRaider committed Dec 16, 2022
1 parent b48212e commit a13bf0c
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions yfinance/base.py
Expand Up @@ -559,12 +559,21 @@ def _reconstruct_intervals_batch(self, df, interval, tag=-1):
# Calibrate! Check whether 'df_fine' has different split-adjustment.
# If different, then adjust to match 'df'
df_block_calib = df_block[price_cols]
calib_filter = df_block_calib.to_numpy() != tag
calib_filter = (df_block_calib != tag).to_numpy()
if not calib_filter.any():
# Can't calibrate so don't attempt repair
continue
df_new_calib = df_new[df_new.index.isin(df_block_calib.index)][price_cols]
ratios = (df_block_calib[price_cols].to_numpy() / df_new_calib[price_cols].to_numpy())[calib_filter]
# Avoid divide-by-zero warnings printing:
df_new_calib = df_new_calib.to_numpy()
df_block_calib = df_block_calib.to_numpy()
for j in range(len(price_cols)):
c = price_cols[j]
f = ~calib_filter[:,j]
if f.any():
df_block_calib[f,j] = 1
df_new_calib[f,j] = 1
ratios = (df_block_calib / df_new_calib)[calib_filter]
ratio = _np.mean(ratios)
#
ratio_rcp = round(1.0 / ratio, 1)
Expand Down Expand Up @@ -1175,4 +1184,4 @@ def get_history_metadata(self) -> dict:
if self._history_metadata is None:
raise RuntimeError("Metadata was never retrieved so far, "
"call history() to retrieve it")
return self._history_metadata
return self._history_metadata

0 comments on commit a13bf0c

Please sign in to comment.