Updated ValueError check to use np.nan