Open zhangshoug opened 5 years ago
说个解决方案,主要是因为 series = self.func(series, arg) 这一句,以这种方式引用talib.MA函数,将会自动添加一个MovingAverageSeries类参数,导致第一个参数不是是series,因此报错。你可以通过debug查看参数就能明白
class OneArgumentSeries(NumericSeries):
func = talib.MA
def __init__(self, series, arg):
if isinstance(series, NumericSeries):
series = series.series
try:
series[series == np.inf] = np.nan
series = self.func(series, arg)
except Exception as e:
raise FormulaException(e)
super(OneArgumentSeries, self).__init__(series)
self.extra_create_kwargs["arg"] = arg
class BaseSeries(NumericSeries):
def __init__(self, series, arg):
if isinstance(series, NumericSeries):
series = series.series
try:
series[series == np.inf] = np.nan
series = eval(self.funcName)(series, arg)
except Exception as e:
raise FormulaException(e)
super(BaseSeries, self).__init__(series)
self.extra_create_kwargs["arg"] = arg
@property
def funcName(self):
raise NotImplementedError
class MovingAverageSeries(BaseSeries):
"""http://www.tadoc.org/indicator/MA.htm"""
@property
def funcName(self):
return 'talib.MA'
棒!解决了出现的同样问题。
https://github.com/cedricporter/funcat/blob/master/notebooks/funcat-tutorial.ipynb 中的代码运行到计算均线就出错误了。
如果是 bug 反馈,烦请在 issue 中描述以下问题:
1. funcat 的版本
0.3.2
2. Python 的版本
Python 3.6.5 |Anaconda
3. 是 Windows / Linux / MacOS or others?
linux mint 18.3 amd64
4. 您出现问题对应的源码 / 或者能复现问题的简易代码
$ python Python 3.6.5 |Anaconda, Inc.| (default, Apr 29 2018, 16:14:56) [GCC 7.2.0] on linux Type "help", "copyright", "credits" or "license" for more information.
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "/opt/anaconda3/lib/python3.6/site-packages/funcat/func.py", line 31, in init series = self.func(series, arg) File "/opt/anaconda3/lib/python3.6/site-packages/talib/init.py", line 24, in wrapper return func(*args, **kwargs) File "talib/_func.pxi", line 7863, in talib._ta_lib.MA TypeError: only size-1 arrays can be converted to Python scalars
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "", line 1, in
File "/opt/anaconda3/lib/python3.6/site-packages/funcat/func.py", line 33, in init
raise FormulaException(e)
funcat.utils.FormulaException: only size-1 arrays can be converted to Python scalars
5. 您出现的错误堆栈日志信息