yfinance
yfinance copied to clipboard
Dataframe with incorrect index type returned when combining two tickers (one without data)
import yfinance as yf
df = yf.download( tickers = ["^NDX", "^TWII"],
start="2023-01-22", end="2023-01-29",
interval = "1m",
group_by = 'column',
auto_adjust = False,
prepost = True,
threads = True,
proxy = None
)
[*********************100%***********************] 2 of 2 completed
1 Failed download:
- ^TWII: No data found for this date range, symbol may be delisted
It's not delisted, it's just there as there is no data due to the lunar new year. The problem is the returned dataframe index is not a datetime index, but has type object)
yfinace version 0.2.9, python 3.10.8 on Linux ubuntu
What happens with other dates?
@asafravid Not helpful.
This appears to be a simple problem for someone to debug & fix, clue is one ticker doesn't return data so maybe messing up merge.
I’ll check
I had a look at this myself. Pandas concat now combines the empty dataframe and then fails to convert the timezone. I altered a try catch block in multi.py at line 155 to remove the empty dataframe and then everything seemed to work fine:
try:
dfs = dict([(key, df) for key, df in shared._DFS.items() if not df.empty])
data = _pd.concat(dfs.values(), axis=1, sort=True,
keys=dfs.keys())
except Exception:
_realign_dfs()
data = _pd.concat(shared._DFS.values(), axis=1, sort=True,
keys=shared._DFS.keys())
Can you create a PR?
remove the empty dataframe
Is this best solution? My concern is users might think yfinance
is failing to fetch and post Issues.