0

On a simple Pandas Series, when I am comparing the results of mul() and __mul__(), there is a 'False' boolean that is being returned for NaN value.

Why?

    x = pd.Series([0,1,2,np.nan,5])

    x.mul(1) == x.__mul__(1)

Result:
    0     True
    1     True
    2     True
    3    False
    4     True
    dtype: bool
Randy
  • 14,349
  • 2
  • 36
  • 42
quietboy
  • 159
  • 11

1 Answers1

1

One of the defining properties of NaN is that it is not equal to itself. See What is the rationale for all comparisons returning false for IEEE754 NaN values?

So when x equals np.nan, presumably x.mul(1) and x.__mul__(1) are both np.nan again, and the result of testing this value for equality with itself is false.

Nate Eldredge
  • 48,811
  • 6
  • 54
  • 82