code: def _inverse_diff(X, lags, X_diff_seq=None):
      """Inverse to difference.
  
      Parameters
      ----------
      X : pd.Series or pd.DataFrame
      lags : int or iterable of int, e.g., list of int
      X_diff_seq : list of pd.Series or pd.DataFrame
          elements must match type, columns and index type of X
          length must be equal or longer than length of lags
  
      Returns
      -------
      `X` inverse differenced at lags `lags`, always a copy (no reference)
      if `lags` is int, applies cumsum to X at period `lag`
          for i in range(lag), X.iloc[i::lag] = X.iloc[i::lag].cumsum()
      if `lags` is list of int, loops over elements from start to end
          and applies cumsum to X at period lag[value], for value in the list `lag`
      if `X_diff_seq` is provided, uses values stored for indices outside `X` to invert
      """
      if isinstance(lags, int):
          lags = [lags]
  
      # if lag is numpy, convert to list
      if isinstance(lags, (np.ndarray, list, tuple)):
          lags = list(lags)
  
      # if lag is a list, recurse
      if isinstance(lags, (list, tuple)):
          if len(lags) == 0:
              return X
  
      lags = lags.copy()
  
      # lag_first = pop last element of lags
      lag_last = lags.pop()
  
      # invert last lag index
      if X_diff_seq is not None:
          # Get the train time series before the last difference
          X_diff_orig = X_diff_seq[len(lags)]
          # Shift the differenced time series index by the last lag
          # to match the original time series index
          X_ix_shift = _shift(X.index, -lag_last)
          # Get the original time series values for the intersecting
          # indices between the shifted index and the original index
          X_update = X_diff_orig.loc[
              X_ix_shift.intersection(X_diff_orig.index)
          ]
          # Set the values of the differenced time series to nan for all indices
          # that are in the indices of the original and the by the sum of all lags
          # shifted original time series that are available in the differenced time
          # series (intersection). These are the indices for which no valid differenced
          # values exist.
          X.loc[
              X_diff_orig.index.difference(
                  _shift(X_diff_orig.index, sum(lags) + lag_last)
              ).intersection(X.index)
          ] = np.nan
          X = X.combine_first(X_update)
  
      X_diff_last = X.copy()
  
      if lag_last < 0:
          X_diff_last = X_diff_last.iloc[::-1]
  
      abs_lag = abs(lag_last)
  
      for i in range(abs_lag):
          X_diff_last.iloc[i::abs_lag] = X_diff_last.iloc[
              i::abs_lag
          ].cumsum()
  
      if lag_last < 0:
          X_diff_last = X_diff_last.iloc[::-1]
  
      # if any more lags, recurse
      if len(lags) > 0:
          return _inverse_diff(X_diff_last, lags, X_diff_seq=X_diff_seq)
      # else return
      else:
          return X_diff_last
  
imports: from typing import Union
  import numpy
  import pandas
  from sklearn.utils import check_array
  from sktime.datatypes._utilities import get_cutoff, update_data
  from sktime.transformations.base import BaseTransformer
  from sktime.utils.validation import is_int
label_desc: Use image node_id 5 for calling a global function with example usage: _inverse_diff(X, lags, X_diff_seq) and returns: _inverse_diff, X_diff_last, X