class_docstr: Wrapper for forecasting models.
  
  This provides a unified API for the forecast method.
  Additionally, this wrapper knows how to work with models from
  certain packages such as AzureML and sktime.
  Other models are expected to have a forecast method that takes
  a DataFrame with the time series ID features and time feature.
class_docstr_tok: ["Wrapper","for","forecasting","models",".","This","provides","a","unified","API","for","the","forecast","method",".","Additionally",",","this","wrapper","knows","how","to","work","with","models","from","certain","packages","such","as","AzureML","and","sktime",".","Other","models","are","expected","to","have","a","forecast","method","that","takes","a","DataFrame","with","the","time","series","ID","features","and","time","feature","."]
docstr: Applies the passed sktime forecasting method.
  
  This method is just a helper for sktime models.
docstr_tok: ["Applies","the","passed","sktime","forecasting","method",".","This","method","is","just","a","helper","for","sktime","models","."]
code: def _apply_sktime_method(self, method, X):
      """Applies the passed sktime forecasting method.
  
      This method is just a helper for sktime models.
      """
      fh = self._get_forecast_horizon(X)
      # sktime expects the time series ID features and time feature
      # in the index rather than as a regular column.
      X_temp = X.copy()
      X_temp.set_index(
          self._time_series_id_features + [self._time_feature],
          inplace=True,
          drop=True,
      )
      if len(self._time_series_id_features) == 0:
          return method(X=X_temp, fh=fh)
  
      # If there are potentially multiple time series in the data
      # we need to ensure that sktime receives data for all of them.
      # This is currently an issue in sktime:
      # https://github.com/sktime/sktime/issues/4209
      # When this is supported in sktime we can remove the code in this
      # if-branch.
  
      # Check that all input time series have all required rows.
      time_series_id_features_index_levels = list(
          range(len(self._time_series_id_features))
      )
      time_series_counts = (
          X_temp.groupby(level=time_series_id_features_index_levels)
          .size()
          .to_list()
      )
      all_time_series_have_same_number_of_rows = all(
          count == time_series_counts[0] for count in time_series_counts
      )
      if not all_time_series_have_same_number_of_rows:
          raise ValueError(
              "Not all time series have the same number of rows."
          )
      # Determine which time series are missing from the data.
      # All index levels except for the last one are time series ID features.
      # The last level is the datetime feature.
      existing_time_series = (
          X_temp.index.droplevel(level=-1).unique().to_list()
      )
      all_time_series = self._model.forecasters_.index.to_list()
      missing_time_series = list(
          set(all_time_series) - set(existing_time_series)
      )
      # Add the missing time series to the data by duplicating
      # the first time series.
      n_rows = int(len(X_temp) / len(existing_time_series))
      for time_series in missing_time_series:
          X_add = X_temp.iloc[:n_rows].copy()
          id_feature_value_mapping = dict(
              zip(self._time_series_id_features, time_series)
          )
          for id_feature, value in id_feature_value_mapping.items():
              X_add[id_feature] = value
          X_add[self._time_feature] = X_add.index.get_level_values(
              level=-1
          )
          X_add.set_index(
              self._time_series_id_features + [self._time_feature],
              drop=True,
              inplace=True,
          )
          X_temp = pd.concat((X_temp, X_add))
  
      preds = method(X=X_temp, fh=fh)
      # Remove the predictions that weren't requested.
      return preds.head(len(X))
  
file_path: responsible-ai-toolbox/responsibleai/responsibleai/_internal/_forecasting_wrappers.py
imports: import inspect
  import sys
  import pandas
  from ml_wrappers.model.base_wrapped_model import BaseWrappedModel
  from raiutils.models import Forecasting, ModelTask
label_desc: Use image node_id 5 for calling the _WrappedForecastingModel obj's underlying member method code with example usage: obj._apply_sktime_method(method, X) and returns: preds, method