def _restore_xarray_from_frequency(
        cls, xa: xr.DataArray, freq: Union[str, int]
    ) -> xr.DataArray:
        """Return an xarray DataArray instance that is resampled from an input xarray DataArray `xa` with frequency
        `freq`. `freq` should be the inferred or actual frequency of `xa`. All data from `xa` is maintained in the
        output DataArray at the corresponding dates. Any missing dates from `xa` will be inserted into the returned
        DataArray with np.nan values.

        The first dimension of the input DataArray `xa` has to be the time dimension.

        This requires a provided frequency/step size `freq`

        Parameters
        ----------
        xa
            The xarray DataArray
        freq
            If a string, represents the actual or inferred frequency of the pandas DatetimeIndex from `xa` (see
            `offset aliases <https://pandas.pydata.org/pandas-docs/stable/user_guide/timeseries.html#offset-aliases>`_
            for more info on supported frequencies).
            If an integer, represents the actual or inferred step size of the pandas Index or pandas RangeIndex from
            `xa`.

        Raises
        -------
        ValueError
            If the resampled/reindexed DateTimeIndex/RangeIndex does not contain all dates from `xa`

        Returns
        -------
        xarray DataArray
            xarray DataArray resampled from `xa` with `freq` including all data from `xa` and inserted missing dates
        """

        time_dim = xa.dims[0]
        sorted_xa = cls._sort_index(xa, copy=False)

        time_index = sorted_xa.get_index(time_dim)
        resampled_time_index = pd.Series(index=time_index, dtype="object")
        if isinstance(time_index, pd.DatetimeIndex):
            has_datetime_index = True
            resampled_time_index = resampled_time_index.asfreq(freq)
        else:  # integer index (non RangeIndex) -> resampled to RangeIndex
            has_datetime_index = False
            resampled_time_index = resampled_time_index.reindex(
                range(min(time_index), max(time_index) + freq, freq)
            )
        # check if new time index with inferred frequency contains all input data
        contains_all_data = time_index.isin(resampled_time_index.index).all()

        offset_alias_info = (
            (
                " For more information about frequency aliases, read "
                "https://pandas.pydata.org/pandas-docs/stable/user_guide/timeseries.html#offset-aliases"
            )
            if has_datetime_index
            else ""
        )
        if not contains_all_data:
            raise_log(
                ValueError(
                    f"Could not correctly fill missing {'dates' if has_datetime_index else 'indices'} with the "
                    f"observed/passed {'frequency' if has_datetime_index else 'step size'} `freq='{freq}'`. "
                    f"Not all input {'time stamps' if has_datetime_index else 'indices'} contained in the newly "
                    f"created TimeSeries.{offset_alias_info}"
                ),
                logger,
            )

        coords = {
            str(xa.dims[0]): resampled_time_index.index,
            str(xa.dims[1]): xa.coords[DIMS[1]],
        }

        # convert to float as for instance integer arrays cannot accept nans
        dtype = (
            xa.dtype
            if (
                np.issubdtype(xa.values.dtype, np.float32)
                or np.issubdtype(xa.values.dtype, np.float64)
            )
            else np.float64
        )
        resampled_xa = xr.DataArray(
            data=np.empty(
                shape=((len(resampled_time_index),) + xa.shape[1:]), dtype=dtype
            ),
            dims=xa.dims,
            coords=coords,
            attrs=xa.attrs,
        )
        resampled_xa[:] = np.nan
        resampled_xa[resampled_time_index.index.isin(time_index)] = sorted_xa.data
        return resampled_xa
Return an xarray DataArray instance that is resampled from an input xarray DataArray `xa` with frequency
        `freq`. `freq` should be the inferred or actual frequency of `xa`. All data from `xa` is maintained in the
        output DataArray at the corresponding dates. Any missing dates from `xa` will be inserted into the returned
        DataArray with np.nan values.

        The first dimension of the input DataArray `xa` has to be the time dimension.

        This requires a provided frequency/step size `freq`

        Parameters
        ----------
        xa
            The xarray DataArray
        freq
            If a string, represents the actual or inferred frequency of the pandas DatetimeIndex from `xa` (see
            `offset aliases <https://pandas.pydata.org/pandas-docs/stable/user_guide/timeseries.html#offset-aliases>`_
            for more info on supported frequencies).
            If an integer, represents the actual or inferred step size of the pandas Index or pandas RangeIndex from
            `xa`.

        Raises
        -------
        ValueError
            If the resampled/reindexed DateTimeIndex/RangeIndex does not contain all dates from `xa`

        Returns
        -------
        xarray DataArray
            xarray DataArray resampled from `xa` with `freq` including all data from `xa` and inserted missing dates
        
darts/timeseries.py