-
Notifications
You must be signed in to change notification settings - Fork 53
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
Fixed Bug: KeyError: <ticker> for batch query #258
Conversation
For passing tickers as list for e.g. ['AAPL, 'GOOGL'], the concat operation results in KeyError: 'AAPL', because the df does not contain this index
Hey @Kuhno92 , thanks for taking a look at this. Unfortunately, this fix breaks the current set of tests. Do you have a minimal code snippet that will reproduce the issue? The tests suggests that the current code should work when "tickers" is provided as a list of strings. https://travis-ci.org/hydrosquall/tiingo-python/jobs/520429886 |
Okay i have to admit that my suggested solution wasn't well thought out :) I can reproduce the error with the following simple example: from tiingo import TiingoClient
config = {}
config['session'] = True
config['api_key'] = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
client = TiingoClient(config)
ticker_history = client.get_dataframe(['AAPL', 'GOOGL'], frequency='1min')
print(ticker_history) This results in:
I debugged this code, and it seems that the 'df.rename' function has no effect, because the variable 'metric_name' is none. Due to this, indexing the df with the stock name fails. As i understand this piece of code, the variable 'metric_name' is not set if the user does not specify a metric in the client.get_dataframe call. |
Hi @Kuhno92 , I took a closer look at this, and realized that we could do a better job of raising a more informative error message. The issue is that when passing in a list of tickers, you must provide a specific https://github.com/hydrosquall/tiingo-python/blob/master/tiingo/api.py#L225-L226 Only single-ticker lookup supports single-metric lookup. If you'd like to get all the metrics back, for multiple tickers, here is something that might work for your purposes. histories = []
tickers = ['GOOGL', 'APPL']
for ticker in tickers:
history = client.get_dataframe(ticker, frequency='weekly')
histories.append(history) Let me know if that clears things up! |
@Kuhno92 , I've opened up a fix in #263 that will address this issue. Let me know if you have a chance to take a look / if you have any suggestions about what would make the error message more helpful. Thanks again for taking the time to take a look at this project and contribute the time for investigating! |
For passing tickers as list for e.g. ['AAPL, 'GOOGL'], the concat operation results in KeyError: 'AAPL', because the df does not contain this index