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

Dataframe with incorrect index type returned when combining two tickers (one without data) #1382

Open
btodac opened this issue Jan 30, 2023 · 6 comments

Comments

@btodac
Copy link

btodac commented Jan 30, 2023

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

@asafravid
Copy link
Collaborator

What happens with other dates?

@ValueRaider
Copy link
Collaborator

@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
Copy link
Collaborator

I’ll check

@btodac
Copy link
Author

btodac commented 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:

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())

@asafravid
Copy link
Collaborator

Can you create a PR?

@ValueRaider
Copy link
Collaborator

remove the empty dataframe

Is this best solution? My concern is users might think yfinance is failing to fetch and post Issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants