ta
ta copied to clipboard
RuntimeWarning
trend.py:170: RuntimeWarning: invalid value encountered in double_scalars
dip[i] = 100 * (dip_mio[i]/trs[i])
trend.py:174: RuntimeWarning: invalid value encountered in double_scalars
din[i] = 100 * (din_mio[i]/trs[i])
site-packages\ta\trend.py:468: RuntimeWarning: invalid value encountered in double_scalars dip[i] = 100 * (self._dip[i]/self._trs[i])
site-packages\ta\trend.py:472: RuntimeWarning: invalid value encountered in double_scalars din[i] = 100 * (self._din[i]/self._trs[i])
site-packages\ta\trend.py:468: RuntimeWarning: invalid value encountered in double_scalars dip[i] = 100 * (self._dip[i]/self._trs[i])
site-packages\ta\trend.py:472: RuntimeWarning: invalid value encountered in double_scalars din[i] = 100 * (self._din[i]/self._trs[i])
same issues
same issue
same issue
Same issue
\.venv\lib\site-packages\ta\trend.py:543: RuntimeWarning: invalid value encountered in double_scalars
dip[i] = 100 * (self._dip[i]/self._trs[i])
\.venv\lib\site-packages\ta\trend.py:547: RuntimeWarning: invalid value encountered in double_scalars
din[i] = 100 * (self._din[i]/self._trs[i])
Hi all,
This is a warning error.
I will fix it asap.
Best, Dario
Hi, first off thanks for doing this! Second, im just curious if there is and ETA for this fix? Thanks again, Dan
RuntimeWarning: invalid value encountered in double_scalars dip[i] = 100 * (self._dip[i]/self._trs[i])
Still present
Any update on this? I am still encountering the issue.
../python3.8/site-packages/ta/trend.py:643: RuntimeWarning: invalid value encountered in double_scalars dip[i] = 100 * (self._dip[i]/self._trs[i]) ../python3.8/site-packages/ta/trend.py:647: RuntimeWarning: invalid value encountered in double_scalars din[i] = 100 * (self._din[i]/self._trs[i])
RuntimeWarning: invalid value encountered in double_scalars dip[i] = 100 * (self._dip[i] / self._trs[i])
this problem is still present
I get error RuntimeWarning: invalid value encountered in double_scalars dip[i] = 100 * (self._dip[i] / self._trs[i])
Looks like divide by zero error. I see it has been previously reported. Several times. I appreciate your library but this makes it unusable for me. If I fix it, I run into another divide by zero error. If I fix that, I run into a different error. Cascading issues.
Yeah, this fails (get the warning) with pretty much all data. Even basic yahoo finance data. Great library otherwise, though.
Hey what's the timeline for this? It's not something major but it's nice to have the log clean😛
Getting the same error...
This is so annoying I had answer this issue with a beatiful explanation and Github decided to erase what i was writing and send me to another page gr.. There might be 2 issues:
- The first one in line 715 in Trend.py:
pdm = _get_min_max(self._high, close_shift, "max") pdn = _get_min_max(self._high, close_shift, "max") diff_directional_movement = pdm - pdn
And then goes to line 726:
for i in range(1, len(self._trs) - 1): self._trs[i] = ( self._trs[i - 1] - (self._trs[i - 1] / float(self._window)) + diff_directional_movement[self._window + i] )
If the Dataset has missing values (NaN) then since self._trs[i] is being filled with self._trs[i-1] as part of the formula the first Nan it encounters will continue to fill all values with NaN. So you end up with a self._trs that has a lot of missing values so when you divide something with self._trs you get that warning, but of course is not only a warning you are actually messing up with the results of the indicators involved. I solved my particular issue by adding a fillna method just after line 717 like this:
pdm = _get_min_max(self._high, close_shift, "max") pdn = _get_min_max(self._high, close_shift, "max") diff_directional_movement = pdm - pdn ---> diff_directional_movement.fillna(method='ffill',inplace=True) <--- New line
However you can also add some vectorized numpy solution to the _get_min_max function in utils.py so it makes sure to clean all Nan values of the series that are feed to it, or maybe just fillna the whole dataset somehow.
-
The second one is the actual warning that occurs because the last value of self._trs is 0 and then once you fill it with other value you have another warning because the last values of din and dip are also 0. This is how I patched it by replacing the last value of each series with the previous one.
dip = np.zeros(len(self._trs)) self._trs[-1] = self._trs[-2] ---> new line for i in range(len(self._trs)): dip[i] = 100 * (self._dip[i] / self._trs[i]) din = np.zeros(len(self._trs)) for i in range(len(self._trs)): din[i] = 100 * (self._din[i] / self._trs[i]) din[-1] = din[-2] ---> new line dip[-1] = dip[-2] ---> new line directional_index = 100 * np.abs((dip - din) / (dip + din))
@Neogus :+1: You should make a PR
@Neogus thx that fixed it for me!
Also there is an open PR https://github.com/bukosabino/ta/pull/196 that seems to have a similar fix
or we could simply add this line at the beginning of the code
np.seterr(divide='ignore', invalid='ignore')
We know there will be nan or 0 values at the beginning of data range while calculating an indicator, and that will throw this warning. So by adding this one line, solves that issue.
or we could simply add this line at the beginning of the code
np.seterr(divide='ignore', invalid='ignore')
We know there will be nan or 0 values at the beginning of data range while calculating an indicator, and that will throw this warning. So by adding this one line, solves that issue.
kinda new to this, can you explain how this solves the issue?
@formula-x The runtime warning happens when the program is trying to divide a value by zero or nan value. We know in order to calculate our Indicators, some of the initial values will be either zero or nan, which inevitably are going to throw the runtime warning. So, what this line does is to ignore such warnings, pertaining only to divide function. Rest of warnings will still work.
I've tried to fix another part of the library , and similar issue cropped up, but that time I took the long method of solving it. This time I felt ignoring divide warning is a more efficient way of handling it.
@formula-x
The runtime warning happens when the program is trying to divide a value by zero or nan value. We know in order to calculate our Indicators, some of the initial values will be either zero or nan, which inevitably are going to throw the runtime warning.
So, what this line does is to ignore such warnings, pertaining only to divide function. Rest of warnings will still work.
I've tried to fix another part of the library , and similar issue cropped up, but that time I took the long method of solving it. This time I felt ignoring divide warning is a more efficient way of handling it.
Ok I get it, thanks for the explanation bro I appreciate it.. do you have a discord or anything I can reach you on incase I have more questions pertaining to this library? Judging by your reply, there are other areas of this library where I might run into similar issues..
sure, leave a comment here, will reply to you :-) This library is very well done, this is the only minor irritant.
Still have this error on different line: /usr/local/lib/python3.7/dist-packages/ta/trend.py:768: RuntimeWarning: invalid value encountered in double_scalars dip[i] = 100 * (self._dip[i] / self._trs[i]) /usr/local/lib/python3.7/dist-packages/ta/trend.py:772: RuntimeWarning: invalid value encountered in double_scalars din[i] = 100 * (self._din[i] / self._trs[i])
version: ta==0.7.0
For me, it started popping up recently. Same issue.
You’d be better slicing out the bits where you expect the error, otherwise you might not catch genuine errors.
On 16 Aug 2021, at 19:52, summa-code @.***> wrote:
For me, it started popping up recently. Same issue.
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe.
Getting some similar errors:
/trend.py:769: RuntimeWarning: invalid value encountered in double_scalars
/trend.py:774: RuntimeWarning: invalid value encountered in double_scalars
/trend.py:938: FutureWarning: The default dtype for empty Series will be 'object' instead of 'float64' in a future version. Specify a dtype explicitly to silence this warning.
self._psar_up = pd.Series(index=self._psar.index)
trend.py:939: FutureWarning: The default dtype for empty Series will be 'object' instead of 'float64' in a future version. Specify a dtype explicitly to silence this warning.
self._psar_down = pd.Series(index=self._psar.index)
Maybe do the calcs with numpy
and wrap with np.errstate()
?
This Commit fix this Problem: https://github.com/bukosabino/ta/pull/196/commits/d0cccf8e31e4cfc889b0d2cbac36e2b0dcd1dbac But there are other line numbers
@Neogus getting similar error will you please let me know what do do for it
C:\Users\addev\anaconda3\lib\site-packages\ta\trend.py:769: RuntimeWarning: invalid value encountered in double_scalars dip[idx] = 100 * (self._dip[idx] / value) C:\Users\addev\anaconda3\lib\site-packages\ta\trend.py:774: RuntimeWarning: invalid value encountered in double_scalars din[idx] = 100 * (self._din[idx] / value)
C:\Users\eldem\AppData\Local\Programs\Python\Python310\lib\site-packages\ta\trend.py:780: RuntimeWarning: invalid value encountered in double_scalars dip[idx] = 100 * (self._dip[idx] / value) C:\Users\eldem\AppData\Local\Programs\Python\Python310\lib\site-packages\ta\trend.py:785: RuntimeWarning: invalid value encountered in double_scalars din[idx] = 100 * (self._din[idx] / value)