def _encode(
        self, index: SupportedIndex, target_end: pd.Timestamp, dtype: np.dtype
    ) -> TimeSeries:
        """Adds integer index value (position) to the provided `index`.
        For attribute=='relative', the reference point/index is the prediction/forecast index of the target series.
        """
        super()._encode(index, target_end, dtype)

        idx_larger_end = (index <= target_end).sum()
        freq = index.freq if isinstance(index, pd.DatetimeIndex) else index.step
        if idx_larger_end:
            idx_larger_end -= 1
        if index[0] > target_end:
            idx_diff = (
                len(generate_index(start=target_end, end=index[0], freq=freq)) - 1
            )
        elif index[-1] < target_end:
            idx_diff = (
                -len(generate_index(start=index[-1], end=target_end, freq=freq)) + 1
            )
        else:
            idx_diff = 0
        return TimeSeries.from_times_and_values(
            times=index,
            values=np.arange(
                start=idx_diff - idx_larger_end,
                stop=idx_diff - idx_larger_end + len(index),
            ),
            columns=[self.base_component_name + self.attribute],
        ).astype(np.dtype(dtype))
Adds integer index value (position) to the provided `index`.
        For attribute=='relative', the reference point/index is the prediction/forecast index of the target series.
        
darts/dataprocessing/encoders/encoders.py