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

Drop empty dataframes before merge with appropriate error handling #1782

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
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
13 changes: 13 additions & 0 deletions yfinance/multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,21 @@ def download(tickers, start=None, end=None, actions=False, threads=True, ignore_
return shared._DFS[ticker]

try:
for key , df in shared._DFS.items():
assert not df.empty
data = _pd.concat(shared._DFS.values(), axis=1, sort=True,
keys=shared._DFS.keys())
except AssertionError:
dfs = {}
empty_dfs = []
for key, df in shared._DFS.items():
if not df.empty:
dfs[key] = df
else:
empty_dfs.append(key)
logger.error(f'{empty_dfs} tickers have no data in given time frame. Dropping {empty_dfs} and continuing...')
data = _pd.concat(shared._DFS.values(), axis=1, sort=True,
keys=dfs.keys())
except Exception:
_realign_dfs()
data = _pd.concat(shared._DFS.values(), axis=1, sort=True,
Expand Down