1

Looking at ewma method in https://github.com/pydata/pandas/blob/master/pandas/algos.pyx, there is a strange code:

for i from 1 <= i < N:
    cur = input[i]
    prev = output[i - 1]

    if **cur == cur:**
        if **prev == prev**:
            output[i] = oldw * prev + neww * cur
        else:
            output[i] = neww * cur
    else:
        output[i] = prev

Why is it comparing cur==cur and prev==prev?

I'm trying to implement this method in Java but get different results (7.01644573 in Python and 7.013072549019608 in Java, for example), so maybe this magic "==" operator does something?..

relgames
  • 1,356
  • 1
  • 16
  • 34

1 Answers1

6

cur == cur will be True for all numbers / objects EXCEPT if cur is a np.nan essentially a quick way of nan testing

Jeff
  • 125,376
  • 21
  • 220
  • 187