dpguthrie / dpguthrie/yahooquery

Inconsistent output from yahooquery get_financial_data for single symbol and multiple symbols

Open
#112 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
920
Forks
164
PR merge metrics
No merged PRs in 30d

Description

**Describe the bug**
When the input has multiple symbols, if some financial data is not available for one symbol, a NaN is in the output dataframe cell. When the input is the single symbol with missing financial data, the output dataframe is very different from the multiple symbols one making it difficult for generic data handling.

**To Reproduce**
### dataframe cell will have NaN for missing data in column
securities=['0700.HK','80737.HK']
ticker = Ticker(securities)
df=ticker.get_financial_data(['CurrentAssets','Inventory'],trailing=False)
df
symbol | asOfDate | periodType | currencyCode | CurrentAssets | Inventory
-- | -- | -- | -- | -- | --
0700.HK | 2018-12-31 | 12M | CNY | 2.170800e+11 | 3.240000e+08
0700.HK | 2019-12-31 | 12M | CNY | 2.539680e+11 | 7.180000e+08
0700.HK | 2020-12-31 | 12M | CNY | 3.176470e+11 | 8.140000e+08
0700.HK | 2021-12-31 | 12M | CNY | 4.848120e+11 | 1.063000e+09
80737.HK | 2019-12-31 | 12M | CNY | 5.067300e+07 | NaN
80737.HK | 2020-12-31 | 12M | CNY | 1.589339e+09 | NaN
80737.HK | 2021-12-31 | 12M | CNY | 2.173692e+09 | NaN

### Dataframe does NOT have the ROWS for symbol with missing data
securities=['0700.HK','80737.HK']
ticker = Ticker(securities)
df=ticker.get_financial_data(['Inventory'],trailing=False)
df
symbol | asOfDate | periodType | currencyCode | Inventory
-- | -- | -- | -- | --
0700.HK | 2018-12-31 | 12M | CNY | 3.240000e+08
0700.HK | 2019-12-31 | 12M | CNY | 7.180000e+08
0700.HK | 2020-12-31 | 12M | CNY | 8.140000e+08
0700.HK | 2021-12-31 | 12M | CNY | 1.063000e+09

### Dataframe does NOT have the COLUMNS of the missing data
securities=['80737.HK']
ticker = Ticker(securities)
df=ticker.get_financial_data(['CurrentAssets','Inventory'],trailing=False)
df
symbol | asOfDate | periodType | currencyCode | CurrentAssets
-- | -- | -- | -- | --
80737.HK | 2019-12-31 | 12M | CNY | 5.067300e+07
80737.HK | 2020-12-31 | 12M | CNY | 1.589339e+09
80737.HK | 2021-12-31 | 12M | CNY | 2.173692e+09

### a STRING is returned instead of a dataframe
securities=['80737.HK']
ticker = Ticker(securities)
df=ticker.get_financial_data(['Inventory'],trailing=False)
print(df)
df['Inventory']

Cash Flow data unavailable for 80737.HK
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Input In [129], in ()
3 df=ticker.get_financial_data(['Inventory'],trailing=False)
4 print(df)
----> 5 df['Inventory']

TypeError: string indices must be integers

### Jupyter notebook with above examples
[Untitled1.ipynb.gz](https://github.com/dpguthrie/yahooquery/files/9387168/Untitled1.ipynb.gz)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.