np.std will always be nan if any nan is present so the if/else is not needed here.