From e749fe3b4ef17756ebcf45147a3a1add8fdedb60 Mon Sep 17 00:00:00 2001 From: Ryan Chen <54162655+ChNgineer@users.noreply.github.com> Date: Tue, 12 Dec 2023 20:04:11 -0500 Subject: [PATCH] Implemented suggested dropping of empty dataframes with appropriate error handling --- yfinance/multi.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/yfinance/multi.py b/yfinance/multi.py index f9e0332f3..a508779b0 100644 --- a/yfinance/multi.py +++ b/yfinance/multi.py @@ -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,