You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Dataframe with incorrect index type returned when combining two tickers (one without data) #1382
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
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())
@
Looks resolved on dev. reindex_dfs now builds the union index only from non-empty frames, then reindexes the empty ticker onto it. Combining a populated 1m frame with a data-less ticker (utils.empty_df()) yields a DatetimeIndex (datetime64[us]), not an object index, so the concatenated result keeps a proper datetime index. Appears safe to close.
@
Activity
asafravid commentedon Feb 1, 2023
What happens with other dates?
ValueRaider commentedon Feb 1, 2023
@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.
asafravid commentedon Feb 1, 2023
I’ll check
btodac commentedon Feb 2, 2023
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:
asafravid commentedon Feb 2, 2023
Can you create a PR?
ValueRaider commentedon Feb 2, 2023
Is this best solution? My concern is users might think
yfinanceis failing to fetch and post Issues.DogInfantry commentedon Jul 8, 2026
@
Looks resolved on
dev.reindex_dfsnow builds the union index only from non-empty frames, then reindexes the empty ticker onto it. Combining a populated1mframe with a data-less ticker (utils.empty_df()) yields aDatetimeIndex(datetime64[us]), not an object index, so the concatenated result keeps a proper datetime index. Appears safe to close.@