Replace astype by as_ndarray