code: def add_groupby_column(
      df,
      time_col,
      groupby_time_feature=None,
      groupby_sliding_window_size=None,
      groupby_custom_column=None,
  ):
      """Extracts a column to group by from ``df``.
  
      Exactly one of ``groupby_time_feature``, ``groupby_sliding_window_size``,
      `groupby_custom_column` must be provided.
  
      Parameters
      ----------
      df : 'pandas.DataFrame`
          Contains the univariate time series / forecast
      time_col : `str`
          The name of the time column of the univariate time series / forecast
      groupby_time_feature : `str` or None, optional
          If provided, groups by a column generated by
          `~greykite.common.features.timeseries_features.build_time_features_df`.
          See that function for valid values.
      groupby_sliding_window_size : `int` or None, optional
          If provided, sequentially partitions data into groups of size
          ``groupby_sliding_window_size``.
      groupby_custom_column : `pandas.Series` or None, optional
          If provided, groups by this column value.
          Should be same length as the ``df``.
  
      Returns
      -------
      result : `dict`
          Dictionary with two items:
  
          * ``"df"`` : `pandas.DataFrame`
              ``df`` with a grouping column added.
              The column can be used to group rows together.
  
          * ``"groupby_col"`` : `str`
              The name of the groupby column added to ``df``.
              The column name depends on the grouping method:
  
                  - ``groupby_time_feature`` for ``groupby_time_feature``
                  - ``{cst.TIME_COL}_downsample`` for ``groupby_sliding_window_size``
                  - ``groupby_custom_column.name`` for ``groupby_custom_column``.
      """
      # Resets index to support indexing in groupby_sliding_window_size
      df = df.copy()
      dt = pd.Series(df[time_col].values)
      # Determines the groups
      is_groupby_time_feature = (
          1 if groupby_time_feature is not None else 0
      )
      is_groupby_sliding_window_size = (
          1 if groupby_sliding_window_size is not None else 0
      )
      is_groupby_custom_column = (
          1 if groupby_custom_column is not None else 0
      )
      if (
          is_groupby_time_feature
          + is_groupby_sliding_window_size
          + is_groupby_custom_column
          != 1
      ):
          raise ValueError(
              "Exactly one of (groupby_time_feature, groupby_rolling_window_size, groupby_custom_column)"
              "must be specified"
          )
      groups = None
      if is_groupby_time_feature == 1:
          # Group by a value derived from the time column
          time_features = build_time_features_df(
              dt, conti_year_origin=min(dt).year
          )
          groups = time_features[groupby_time_feature]
          groups.name = groupby_time_feature
      elif is_groupby_sliding_window_size == 1:
          # Group by sliding window for evaluation over time
          index_dates = split_range_into_groups(
              n=df.shape[0],
              group_size=groupby_sliding_window_size,
              which_group_complete="last",
          )  # ensures the last group is complete (first group may be partial)
          groups = dt[
              index_dates * groupby_sliding_window_size
          ]  # uses first date in each group as grouping value
          groups.name = f"{time_col}_downsample"
      elif is_groupby_custom_column == 1:
          # Group by custom column
          groups = groupby_custom_column
  
      groups_col_name = (
          groups.name if groups.name is not None else "groups"
      )
      df[groups_col_name] = groups.values
      if df.index.name in df.columns:
          # Removes ambiguity in case the index name is the same as the newly added column,
          # (or an existing column).
          df.index.name = None
      return {"df": df, "groupby_col": groups_col_name}
  
imports: import warnings
  import numpy
  import pandas
  import plotly.graph_objects
  from plotly.colors import DEFAULT_PLOTLY_COLORS
  from plotly.subplots import make_subplots
  from greykite.common import constants
  from greykite.common.features.timeseries_features import build_time_features_df
  from greykite.common.logging import LoggingLevelEnum
  from greykite.common.logging import log_message
  from greykite.common.python_utils import update_dictionary
  from greykite.common.viz.colors_utils import get_color_palette
  from greykite.common.viz.colors_utils import get_distinct_colors
label_desc: Use image node_id 6 for calling a global function with example usage: add_groupby_column(df, time_col, groupby_time_feature, groupby_sliding_window_size, groupby_custom_column) and returns: dict