yahooquery icon indicating copy to clipboard operation
yahooquery copied to clipboard

Historical Prices sometimes returns Dict instead of Pandas

Open nrygh opened this issue 4 years ago • 1 comments

tickers = Ticker(symbols, asynchronous=True, max_workers=8, progress=True, formatted=False, validate=True) df = tickers.history(period='max',interval='1d') print (df) print (type(df))

====================================================================== [1885 rows x 7 columns], 'AXTA': high close open low volume adjclose 2014-11-12 20.940001 20.750000 20.940001 20.110001 24860700 20.750000 2014-11-13 21.990000 21.500000 20.750000 20.745001 2276000 21.500000 2014-11-14 22.370001 21.980000 21.500000 21.459999 2089200 21.980000 2014-11-17 22.840000 22.330000 22.059999 21.500000 1628400 22.330000 2014-11-18 22.400000 21.879999 22.129999 21.750000 437900 21.879999 ... ... ... ... ... ... ... 2021-05-10 34.200001 33.680000 34.000000 33.680000 2285200 33.680000 2021-05-11 33.790001 33.509998 33.470001 33.250000 2843000 33.509998 2021-05-12 33.450001 31.690001 33.240002 31.490000 6731100 31.690001 2021-05-13 32.919998 32.740002 31.889999 31.799999 4648300 32.740002 2021-05-14 32.849998 32.639999 32.849998 32.450001 2480900 32.639999

[1637 rows x 6 columns], 'AXS': open high volume close low adjclose dividends splits 2003-07-01 25.500000 26.400000 11648400 25.549999 25.000000 16.365232 NaN NaN 2003-07-02 25.799999 25.799999 1789400 25.400000 25.200001 16.269152 NaN NaN 2003-07-03 25.299999 25.600000 415700 25.600000 25.100000 16.397257 NaN NaN 2003-07-07 25.480000 26.100000 821100 25.799999 25.350000 16.525358 NaN NaN 2003-07-08 25.750000 25.969999 612400 25.889999 25.530001 16.583006 NaN NaN ... ... ... ... ... ... ... ... ... 2021-05-10 58.360001 58.610001 510200 56.790001 56.779999 56.790001 NaN NaN 2021-05-11 56.549999 56.549999 527400 55.500000 55.279999 55.500000 NaN NaN 2021-05-12 55.939999 56.310001 308200 55.060001 54.959999 55.060001 NaN NaN 2021-05-13 54.849998 56.430000 432900 56.259998 54.849998 56.259998 NaN NaN 2021-05-14 56.369999 56.889999 220700 56.730000 56.049999 56.730000 NaN NaN

[4500 rows x 8 columns], 'ASIX': open high volume close low adjclose 2016-09-15 12.000000 17.809999 4000 16.639999 12.000000 16.639999 2016-09-16 17.260000 19.200001 3400 19.200001 17.260000 19.200001 2016-09-19 19.200001 20.250000 2500 20.150000 19.200001 20.150000 2016-09-20 20.250000 20.500000 6200 19.510000 19.400000 19.510000 2016-09-21 19.400000 19.400000 100 19.400000 19.400000 19.400000 ... ... ... ... ... ... ... 2021-05-10 32.009998 32.424000 270000 30.980000 30.860001 30.980000 2021-05-11 30.480000 31.010000 189000 30.700001 30.100000 30.700001 2021-05-12 30.540001 31.100000 317900 29.940001 29.879999 29.940001 2021-05-13 30.080000 30.760000 182000 30.129999 29.209999 30.129999 2021-05-14 30.459999 31.200001 175200 31.139999 30.190001 31.139999

[1174 rows x 6 columns]} <class 'dict'> Traceback (most recent call last): File "./yftocsv.py", line 39, in df = df.drop(columns=['dividends','splits']) AttributeError: 'dict' object has no attribute 'drop'

=================================================================

pip3 list ... yahooquery 2.2.15 ...

=================================================================

It seems, that the problem occcures after several tries and if then the data-rate is limited by yahoo

nrygh avatar May 15 '21 12:05 nrygh

Hello,

Might not be the same issue, but in my case, I could pinpoint the problem to a specific ticker I was requesting which was delisted:

l1 = ['AAPL', 'GOOG']
l2 = ['AAPL', 'GOOG', 'GLOG'] # 'GLOG is delisted'

t1 = Ticker(l1, asynchronous=True)
t2 = Ticker(l2, asynchronous=True)

df1 = t1.history(period = '1m', interval = '1d') # This is a dataframe
df2 = t2.history(period = '1m', interval = '1d') # This is a dict

df2['GLOG'] returns 'No data found, symbol may be delisted'

My guess is, because the delisted ticker has no 'timestamp' key, this function ends up returning the raw dict instead.

Would be nice if this behaviour could be customized, as example with a "drop_invalid=True" kwarg to pass to Ticker.history()

dnabb avatar Aug 18 '21 14:08 dnabb