yahooquery icon indicating copy to clipboard operation
yahooquery copied to clipboard

tickers.history fails when one ticker in list fails to download

Open jakemdrew opened this issue 4 years ago • 2 comments

I have 1 of 564 tickers that causes tickers.history(period='30d', interval='1d') to fail. This is a valid ticker, but also fails download using yfinance:

[100%**] 1 of 1 completed

1 Failed download:

  • KBSR: None

To Reproduce

tickers = Ticker(['KBSR'], asynchronous=True, progress=True) hist = tickers.history(period='30d', interval='1d')

Expected behavior

If a "failed to download" ticker is contained in the ticker_list, yahooquery will fail for the following internal error:


TypeError Traceback (most recent call last) in 4 5 # Get 30 days of price history for tickers ----> 6 hist = tickers.history(period='30d', interval='1d')

~.conda\envs\ML7331\lib\site-packages\yahooquery\ticker.py in history(self, period, interval, start, end, adj_timezone, adj_ohlc) 1240 else: 1241 data = self._get_data("chart", params) -> 1242 df = self._historical_data_to_dataframe(data, params, adj_timezone) 1243 if adj_ohlc and "adjclose" in df: 1244 df = self._adjust_ohlc(df)

~.conda\envs\ML7331\lib\site-packages\yahooquery\ticker.py in _historical_data_to_dataframe(self, data, params, adj_timezone) 1267 d = {} 1268 for symbol in self._symbols: -> 1269 if "timestamp" in data[symbol]: 1270 d[symbol] = _history_dataframe(data, symbol, params, adj_timezone) 1271 else:

TypeError: argument of type 'NoneType' is not iterable

Concern All valid data for 563 other tickers in my case are lost because of one failed download.

jakemdrew avatar Nov 05 '21 16:11 jakemdrew

The same happens to me. The invalid tickers are not previously identified and removed with the "validate = True" argument. The data dictionary is returned from self._get_data with a NaN for each invalid symbol, which causes the reported error.

danilogalisteu avatar Nov 23 '21 20:11 danilogalisteu

To sidestep the problem I modified the function _historical_data_to_dataframe as such:

    def _historical_data_to_dataframe(self, data, params, adj_timezone):
        d = {}
        invalid = []
        for symbol in self._symbols:
            if data[symbol] is not None:
                if "timestamp" in data[symbol]:
                    d[symbol] = _history_dataframe(data, symbol, params, adj_timezone)
                else:
                    d[symbol] = data[symbol]
            else:
                invalid.append(symbol)
        self._symbols = [s for s in self._symbols if not s in invalid]
        if self.invalid_symbols is not None:
            self.invalid_symbols += invalid
        else:
            self.invalid_symbols = invalid
        if all(isinstance(d[key], pd.DataFrame) for key in d):
            df = pd.concat(d, names=["symbol", "date"], sort=False)
            if "dividends" in df.columns:
                df["dividends"].fillna(0, inplace=True)
            if "splits" in df.columns:
                df["splits"].fillna(0, inplace=True)
            return df
        return d

danilogalisteu avatar Nov 24 '21 03:11 danilogalisteu

Is this still happening to folks? Not able to replicate using the example above.

https://www.loom.com/share/76783dfd46ae4e7dbc07797a6b323db2

dpguthrie avatar Oct 15 '22 18:10 dpguthrie

Resolved for me long ago

On Sat, Oct 15, 2022 at 1:32 PM Doug Guthrie @.***> wrote:

Is this still happening to folks? Not able to replicate using the example above.

https://www.loom.com/share/76783dfd46ae4e7dbc07797a6b323db2

— Reply to this email directly, view it on GitHub https://github.com/dpguthrie/yahooquery/issues/97#issuecomment-1279803040, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAQCS47RNHEH4WUB2C5HH4DWDL2B7ANCNFSM5HOFLRFA . You are receiving this because you authored the thread.Message ID: @.***>

jakemdrew avatar Oct 15 '22 18:10 jakemdrew