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

Fixed Bug: KeyError: <ticker> for batch query #258

Closed
wants to merge 1 commit into from

Conversation

Kuhno92
Copy link

@Kuhno92 Kuhno92 commented Apr 15, 2019

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

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
@hydrosquall
Copy link
Owner

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

@Kuhno92
Copy link
Author

Kuhno92 commented Apr 29, 2019

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:

KeyError: 'AAPL'

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.

@hydrosquall
Copy link
Owner

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 metric_name. This is intentional, but we could do a better job of providing an informative error message instead of a cryptic KeyError. I'll open a fix for this soon. In the meantime, this constraint is indicated in the docstring for the get_dataframe function.

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!

@hydrosquall hydrosquall changed the title Fixed Bug: KeyError: <ticker> for batch querry Fixed Bug: KeyError: <ticker> for batch query Apr 30, 2019
@hydrosquall
Copy link
Owner

@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!

@hydrosquall
Copy link
Owner

Replaced by #263, which changes the error message instead of changing behavior. The new feature request will instead be tracked under #265.

@hydrosquall hydrosquall closed this May 5, 2019
@Kuhno92 Kuhno92 deleted the patch-1 branch May 8, 2019 16:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants