pandas-datareader
pandas-datareader copied to clipboard
Feature request: easier-to-understand error when looking up nonexistent ticker (and symbol lookup?)
When I request data for a nonexistent symbol, here's the error I get:
>>> import pandas_datareader.data as web
>>> web.DataReader("FAKETICKER", 'yahoo')
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
File ~\.conda\envs\my_app\lib\site-packages\pandas_datareader\yahoo\daily.py:153, in YahooDailyReader._read_one_data(self, url, params)
152 j = json.loads(re.search(ptrn, resp.text, re.DOTALL).group(1))
--> 153 data = j["context"]["dispatcher"]["stores"]["HistoricalPriceStore"]
154 except KeyError:
KeyError: 'HistoricalPriceStore'
During handling of the above exception, another exception occurred:
RemoteDataError Traceback (most recent call last)
Input In [27], in <cell line: 1>()
----> 1 web.DataReader("FAKETICKER", 'yahoo')
File ~\.conda\envs\my_env\lib\site-packages\pandas\util\_decorators.py:207, in deprecate_kwarg.<locals>._deprecate_kwarg.<locals>.wrapper(*args, **kwargs)
205 else:
206 kwargs[new_arg_name] = new_arg_value
--> 207 return func(*args, **kwargs)
File ~\.conda\envs\my_env\lib\site-packages\pandas_datareader\data.py:379, in DataReader(name, data_source, start, end, retry_count, pause, session, api_key)
367 raise NotImplementedError(msg)
369 if data_source == "yahoo":
370 return YahooDailyReader(
371 symbols=name,
372 start=start,
373 end=end,
374 adjust_price=False,
375 chunksize=25,
376 retry_count=retry_count,
377 pause=pause,
378 session=session,
--> 379 ).read()
381 elif data_source == "iex":
382 return IEXDailyReader(
383 symbols=name,
384 start=start,
(...)
390 session=session,
391 ).read()
File ~\.conda\envs\my_env\lib\site-packages\pandas_datareader\base.py:253, in _DailyBaseReader.read(self)
251 # If a single symbol, (e.g., 'GOOG')
252 if isinstance(self.symbols, (string_types, int)):
--> 253 df = self._read_one_data(self.url, params=self._get_params(self.symbols))
254 # Or multiple symbols, (e.g., ['GOOG', 'AAPL', 'MSFT'])
255 elif isinstance(self.symbols, DataFrame):
File ~\.conda\envs\my_env\lib\site-packages\pandas_datareader\yahoo\daily.py:156, in YahooDailyReader._read_one_data(self, url, params)
154 except KeyError:
155 msg = "No data fetched for symbol {} using {}"
--> 156 raise RemoteDataError(msg.format(symbol, self.__class__.__name__))
158 # price data
159 prices = DataFrame(data["prices"])
RemoteDataError: No data fetched for symbol FAKETICKER using YahooDailyReader
Is there a way to clarify this error in the event that the data source doesn't have the ticker at all? A simple traceback for a single error that looks something like this:
# DESIRED BEHAVIOR
>>> web.DataReader("FAKETICKER", 'yahoo')
---------------------------------------------------------------------------
SymbolLookupError Traceback (most recent call last)
File ~\.conda\envs\my_app\lib\site-packages\pandas_datareader\yahoo\daily.py:000, in YahooDailyReader._read_one_data(self, url, params)
000 if not reader.has_symbol(ticker):
--> 000 raise SymbolLookupError(f"{reader} could not find symbol {ticker}")
000
SymbolLookupError: YahooDailyReader could not find symbol FAKETICKER
Relatedly, the Yahoo Finance website has a symbol lookup. Is this feature exposed via the API? If so, it would be nice to access it via Pandas Datareader, and it could be useful for the above error-raising feature.