Skip to content

Commit

Permalink
Fix history() keepna=False with repair=True
Browse files Browse the repository at this point in the history
  • Loading branch information
ValueRaider committed Jan 13, 2024
1 parent 006e0a1 commit 6686258
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions yfinance/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
from .scrapers.holders import Holders
from .scrapers.quote import Quote, FastInfo

from .const import _BASE_URL_, _ROOT_URL_
from .const import _BASE_URL_, _ROOT_URL_, price_colnames


class TickerBase:
Expand Down Expand Up @@ -426,7 +426,9 @@ def history(self, period="1mo", interval="1d",
if not actions:
df = df.drop(columns=["Dividends", "Stock Splits", "Capital Gains"], errors='ignore')
if not keepna:
mask_nan_or_zero = (df.isna() | (df == 0)).all(axis=1)
data_colnames = price_colnames + ['Volume'] + ['Dividends', 'Stock Splits', 'Capital Gains']
data_colnames = [c for c in data_colnames if c in df.columns]
mask_nan_or_zero = (df[data_colnames].isna() | (df[data_colnames] == 0)).all(axis=1)
df = df.drop(mask_nan_or_zero.index[mask_nan_or_zero])

logger.debug(f'{self.ticker}: yfinance returning OHLC: {df.index[0]} -> {df.index[-1]}')
Expand Down Expand Up @@ -455,7 +457,7 @@ def _reconstruct_intervals_batch(self, df, interval, prepost, tag=-1):
else:
intraday = True

price_cols = [c for c in ["Open", "High", "Low", "Close", "Adj Close"] if c in df]
price_cols = [c for c in price_colnames if c in df]
data_cols = price_cols + ["Volume"]

# If interval is weekly then can construct with daily. But if smaller intervals then
Expand Down Expand Up @@ -1011,7 +1013,7 @@ def _fix_zeroes(self, df, interval, tz_exchange, prepost):
elif df2.index.tz != tz_exchange:
df2.index = df2.index.tz_convert(tz_exchange)

price_cols = [c for c in ["Open", "High", "Low", "Close", "Adj Close"] if c in df2.columns]
price_cols = [c for c in price_colnames if c in df2.columns]
f_prices_bad = (df2[price_cols] == 0.0) | df2[price_cols].isna()
df2_reserve = None
if intraday:
Expand Down

0 comments on commit 6686258

Please sign in to comment.