The logical grouping here is not clear - please wrap `z is not None and np.any(np.isnan(z))` in brackets.