ta icon indicating copy to clipboard operation
ta copied to clipboard

RuntimeWarning

Open bukosabino opened this issue 4 years ago • 30 comments

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])

bukosabino avatar Oct 29 '19 13:10 bukosabino

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])

AntMatRod avatar Nov 14 '19 20:11 AntMatRod

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

AntMatRod avatar Nov 14 '19 20:11 AntMatRod

same issue

alm0ra avatar Mar 22 '20 18:03 alm0ra

same issue

daggamault avatar Mar 28 '20 13:03 daggamault

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])

msarm avatar Apr 01 '20 11:04 msarm

Hi all,

This is a warning error.

I will fix it asap.

Best, Dario

bukosabino avatar Apr 01 '20 18:04 bukosabino

Hi, first off thanks for doing this! Second, im just curious if there is and ETA for this fix? Thanks again, Dan

saltyDan716 avatar Apr 18 '20 22:04 saltyDan716

RuntimeWarning: invalid value encountered in double_scalars dip[i] = 100 * (self._dip[i]/self._trs[i])

sagarkhale avatar Jun 08 '20 18:06 sagarkhale

Still present

ElliotVilhelm avatar Jul 19 '20 02:07 ElliotVilhelm

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])

erzwo31 avatar Nov 28 '20 12:11 erzwo31

RuntimeWarning: invalid value encountered in double_scalars dip[i] = 100 * (self._dip[i] / self._trs[i])

this problem is still present

RRRddd10001 avatar Dec 02 '20 11:12 RRRddd10001

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.

karenjh2 avatar Dec 23 '20 16:12 karenjh2

Yeah, this fails (get the warning) with pretty much all data. Even basic yahoo finance data. Great library otherwise, though.

elginbeloy avatar Dec 23 '20 22:12 elginbeloy

Hey what's the timeline for this? It's not something major but it's nice to have the log clean😛

YukaLangbuana avatar Jan 09 '21 04:01 YukaLangbuana

Getting the same error...

sunsakis avatar Feb 05 '21 16:02 sunsakis

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:

  1. 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.

  1. 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 avatar Feb 22 '21 03:02 Neogus

@Neogus :+1: You should make a PR

rundef avatar Mar 18 '21 02:03 rundef

@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

jaymegordo avatar Apr 26 '21 16:04 jaymegordo

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.

informankur avatar Jun 02 '21 12:06 informankur

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?

George-Gar avatar Jun 02 '21 19:06 George-Gar

@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.

informankur avatar Jun 02 '21 19:06 informankur

@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..

George-Gar avatar Jun 02 '21 19:06 George-Gar

sure, leave a comment here, will reply to you :-) This library is very well done, this is the only minor irritant.

informankur avatar Jun 02 '21 19:06 informankur

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

ziyunxiao avatar Jun 15 '21 21:06 ziyunxiao

For me, it started popping up recently. Same issue.

summa-code avatar Aug 16 '21 17:08 summa-code

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.

jonnymaserati avatar Aug 16 '21 20:08 jonnymaserati

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()?

jonnymaserati avatar Feb 02 '22 21:02 jonnymaserati

This Commit fix this Problem: https://github.com/bukosabino/ta/pull/196/commits/d0cccf8e31e4cfc889b0d2cbac36e2b0dcd1dbac But there are other line numbers

DaniDD avatar Feb 26 '22 15:02 DaniDD

@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)

Mysterytrade827 avatar Apr 02 '22 08:04 Mysterytrade827

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)

gafakaya avatar Oct 21 '22 04:10 gafakaya