-
Notifications
You must be signed in to change notification settings - Fork 107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
the macd indicator are giving errors #3
Comments
I get the same king of errors (TypeError: 'slice(11, None, None)' is an invalid key AND ValueError: cannot set using a slice indexer with a different length than the value) using btalib.macd, btalib.ppo and btalib.ppofast. |
Hey, I had the same issue and it was driving me crazy. What fixed it for me was setting correcting the column layout of my initial pandas dataframe. before my df had columns: after: then it magically worked. I suppose it was really just the extra column bta-lib didn't like. I think in their docs it also mentions somewhere that the library only accepts the OHLCV format. Hope that might help you as well :) |
a similar problem happened to me. |
btalib.macd(df.close,pfast=12,pslow=26,psignal=9)
TypeError Traceback (most recent call last)
~/anaconda3/lib/python3.7/site-packages/pandas/core/series.py in setitem(self, key, value)
1013 try:
-> 1014 self._set_with_engine(key, value)
1015 except com.SettingWithCopyError:
~/anaconda3/lib/python3.7/site-packages/pandas/core/series.py in _set_with_engine(self, key, value)
1053 try:
-> 1054 self.index._engine.set_value(values, key, value)
1055 return
pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.set_value()
pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.set_value()
pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()
TypeError: 'slice(11, None, None)' is an invalid key
During handling of the above exception, another exception occurred:
ValueError Traceback (most recent call last)
in
----> 1 btalib.macd(df.close,pfast=12,pslow=26,psignal=9)
~/anaconda3/lib/python3.7/site-packages/btalib/indicator.py in call(cls, *args, **kwargs)
150 # Auto-call base classes
151 for b_init in reversed(list(dict.fromkeys(b.init for b in bases))):
--> 152 b_init(self, *args, **kwargs)
153
154 # delete old aliases only meant for operational purposes
~/anaconda3/lib/python3.7/site-packages/btalib/indicators/macd.py in init(self)
38
39 def init(self):
---> 40 ma1 = self.p._ma(self.i0, period=self.p.pfast, **self._talibkw)
41 ma2 = self.p._ma(self.i0, period=self.p.pslow)
42 self.o.macd = ma1 - ma2
~/anaconda3/lib/python3.7/site-packages/btalib/indicator.py in call(cls, *args, **kwargs)
150 # Auto-call base classes
151 for b_init in reversed(list(dict.fromkeys(b.init for b in bases))):
--> 152 b_init(self, *args, **kwargs)
153
154 # delete old aliases only meant for operational purposes
~/anaconda3/lib/python3.7/site-packages/btalib/indicators/ema.py in init(self, poffset)
37 def init(self, poffset=0): # see above for poffset
38 span, seed, poff = self.p.period, self.p._seed, poffset
---> 39 self.o.ema = self.i0._ewm(span=span, _seed=seed, _poffset=poff).mean()
~/anaconda3/lib/python3.7/site-packages/btalib/meta/lines.py in call_op(*args, **kwargs)
377 sargs.append(arg)
378
--> 379 result[self._minidx:] = r = op(*sargs, **kwargs) # run/store
380 result = result.astype(r.dtype, copy=False)
381 return self._line._clone(result, period=self._minperiod)
~/anaconda3/lib/python3.7/site-packages/pandas/core/series.py in setitem(self, key, value)
1040 pass
1041
-> 1042 self._set_with(key, value)
1043
1044 if cacher_needs_updating:
~/anaconda3/lib/python3.7/site-packages/pandas/core/series.py in _set_with(self, key, value)
1062 if isinstance(key, slice):
1063 indexer = self.index._convert_slice_indexer(key, kind="getitem")
-> 1064 return self._set_values(indexer, value)
1065
1066 elif is_scalar(key) and not is_integer(key) and key not in self.index:
~/anaconda3/lib/python3.7/site-packages/pandas/core/series.py in _set_values(self, key, value)
1109 if isinstance(key, Series):
1110 key = key._values
-> 1111 self._data = self._data.setitem(indexer=key, value=value)
1112 self._maybe_update_cacher()
1113
~/anaconda3/lib/python3.7/site-packages/pandas/core/internals/managers.py in setitem(self, **kwargs)
559
560 def setitem(self, **kwargs):
--> 561 return self.apply("setitem", **kwargs)
562
563 def putmask(self, **kwargs):
~/anaconda3/lib/python3.7/site-packages/pandas/core/internals/managers.py in apply(self, f, filter, **kwargs)
440 applied = b.apply(f, **kwargs)
441 else:
--> 442 applied = getattr(b, f)(**kwargs)
443 result_blocks = _extend_blocks(applied, result_blocks)
444
~/anaconda3/lib/python3.7/site-packages/pandas/core/internals/blocks.py in setitem(self, indexer, value)
875
876 # length checking
--> 877 check_setitem_lengths(indexer, value, values)
878 exact_match = (
879 len(arr_value.shape)
~/anaconda3/lib/python3.7/site-packages/pandas/core/indexers.py in check_setitem_lengths(indexer, value, values)
122 if len(value) != length_of_indexer(indexer, values):
123 raise ValueError(
--> 124 "cannot set using a slice indexer with a "
125 "different length than the value"
126 )
ValueError: cannot set using a slice indexer with a different length than the value
The text was updated successfully, but these errors were encountered: