Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix history() keepna=False when repair=True #1824

Merged
merged 1 commit into from
Jan 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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