Revert "Replaces math.isnan with simple None comparisons."

This reverts commit ebbb44261bb1082c80f819b435fef91abb1795ce.

And this fixes the broken test introduced in the previous commit.