TypeError: Argument has incorrect type (expected numpy.ndarray, got DataFrame) Solution
After upgrading packages in a conda env, talib cannot accept dataframe as input, the error message looks like TypeError: Argument 'xxx' has incorrect type (expected numpy.ndarray, got DataFrame):
| |
Most of the web search results are misleading, like changing the df into np array. Since the code works before updating packages, the problem should be package incompatibility issue.
The problem can be easily reproduced by the following code:
Using $ conda list to check the version diff:
Not work version:
Work version:
BTW, it’s not that obvious to find that the root cause is yfinance instead of talib and pandas.
Finally found that talib is work for yfinance 0.2.44 but not work for 0.2.46+.
The solution is to downgrade the yfinance to 0.2.44:
| |
Then talib and pandas works perfectly.
Posted an github issue to yfinance: https://github.com/ranaroussi/yfinance/issues/2107