Skip to content

Commit

Permalink
Fix when Yahoo returns price=NaNs on dividend day
Browse files Browse the repository at this point in the history
  • Loading branch information
ValueRaider committed Oct 18, 2022
1 parent 01ef1bb commit 1d7f813
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions yfinance/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,9 +293,6 @@ def history(self, period="1mo", interval="1d",
"chart"]["result"][0]["meta"]["priceHint"])
quotes['Volume'] = quotes['Volume'].fillna(0).astype(_np.int64)

if not keepna:
quotes.dropna(inplace=True)

# actions
dividends, splits = utils.parse_actions(data["chart"]["result"][0])

Expand All @@ -320,13 +317,13 @@ def history(self, period="1mo", interval="1d",
df.index.name = "Date"

# duplicates and missing rows cleanup
df.dropna(how='all', inplace=True)
df = df[~df.index.duplicated(keep='first')]

self._history = df.copy()

if not actions:
df.drop(columns=["Dividends", "Stock Splits"], inplace=True)
df = df.drop(columns=["Dividends", "Stock Splits"])
if not keepna:
mask_nan_or_zero = (df.isna()|(df==0)).all(axis=1)
df = df.drop(mask_nan_or_zero.index[mask_nan_or_zero])

return df

Expand Down

0 comments on commit 1d7f813

Please sign in to comment.