def _restore_coord_attrs(ds):
    """
    Put back coordinates attribute that
    to_netcdf and to_zarr didn't like.

    Parameters
    ----------
    ds: xarray.Dataset

    Returns
    -------
    ds: xarray.Dataset
    """

    for var in ds.variables:
        attrs = ds[var].attrs
        coordinates = attrs.pop("_coordinates", None)
        ds[var].attrs = attrs
        if coordinates is not None:
            ds[var].attrs["coordinates"] = coordinates
    return ds