code: def test_add_groupby_column():
      """Tests add_groupby_column function"""
      # ``groupby_time_feature``
      df = pd.DataFrame(
          {
              cst.TIME_COL: [
                  datetime.datetime(2018, 1, 1),
                  datetime.datetime(2018, 1, 2),
                  datetime.datetime(2018, 1, 3),
                  datetime.datetime(2018, 1, 4),
                  datetime.datetime(2018, 1, 5),
              ],
              cst.VALUE_COL: [1.0, 2.0, 3.0, 4.0, 5.0],
          }
      )
      result = add_groupby_column(
          df=df,
          time_col=cst.TIME_COL,
          groupby_time_feature="dow",
          groupby_sliding_window_size=None,
          groupby_custom_column=None,
      )
      expected_col = (
          "dow"  # ``groupby_time_feature`` is used as the column name
      )
      expected = df.copy()
      expected[expected_col] = pd.Series(
          [1, 2, 3, 4, 5]
      )  # Monday, Tuesday, etc.
      assert_frame_equal(result["df"], expected)
      assert result["groupby_col"] == expected_col
  
      # ``groupby_sliding_window_size``
      result = add_groupby_column(
          df=df,
          time_col=cst.TIME_COL,
          groupby_time_feature=None,
          groupby_sliding_window_size=2,
          groupby_custom_column=None,
      )
      expected_col = f"{cst.TIME_COL}_downsample"
      expected = df.copy()
      expected[expected_col] = pd.Series(
          [
              datetime.datetime(2018, 1, 1),
              datetime.datetime(2018, 1, 3),
              datetime.datetime(2018, 1, 3),
              datetime.datetime(2018, 1, 5),
              datetime.datetime(2018, 1, 5),
          ]
      )
      assert_frame_equal(result["df"], expected)
      assert result["groupby_col"] == expected_col
  
      # ``groupby_custom_column`` without a name
      df.index.name = "index_name"
      custom_groups = pd.Series(["g1", "g2", "g1", "g3", "g2"])
      result = add_groupby_column(
          df=df,
          time_col=cst.TIME_COL,
          groupby_time_feature=None,
          groupby_sliding_window_size=None,
          groupby_custom_column=custom_groups,
      )
      expected_col = "groups"  # default name
      expected = df.copy()
      expected[expected_col] = custom_groups.values
      assert_frame_equal(result["df"], expected)
      assert result["groupby_col"] == expected_col
  
      # ``groupby_custom_column`` with a name
      custom_groups = pd.Series(
          ["g1", "g2", "g1", "g3", "g2"], name="custom_groups"
      )
      result = add_groupby_column(
          df=df,
          time_col=cst.TIME_COL,
          groupby_time_feature=None,
          groupby_sliding_window_size=None,
          groupby_custom_column=custom_groups,
      )
      expected_col = custom_groups.name
      expected = df.copy()
      expected[expected_col] = custom_groups.values
      assert_frame_equal(result["df"], expected)
      assert result["groupby_col"] == expected_col
  
      # If a column has the same name as the index, the
      # index name is set to None.
      custom_groups = pd.Series(
          ["g1", "g2", "g1", "g3", "g2"], name="index_name"
      )
      result = add_groupby_column(
          df=df,
          time_col=cst.TIME_COL,
          groupby_time_feature=None,
          groupby_sliding_window_size=None,
          groupby_custom_column=custom_groups,
      )
      expected_col = custom_groups.name
      expected = df.copy()
      expected[expected_col] = custom_groups.values
      expected.index.name = None
      assert_frame_equal(result["df"], expected)
      assert result["groupby_col"] == expected_col
  
      # Throws exception if multiple grouping dimensions are provided
      with pytest.raises(
          ValueError, match="Exactly one of.*must be specified"
      ):
          add_groupby_column(
              df=df,
              time_col=cst.TIME_COL,
              groupby_time_feature=None,
              groupby_sliding_window_size=2,
              groupby_custom_column=custom_groups,
          )
  
      with pytest.raises(
          ValueError, match="Exactly one of.*must be specified"
      ):
          add_groupby_column(
              df=df,
              time_col=cst.TIME_COL,
              groupby_time_feature="dow",
              groupby_sliding_window_size=None,
              groupby_custom_column=custom_groups,
          )
  
      with pytest.raises(
          ValueError, match="Exactly one of.*must be specified"
      ):
          add_groupby_column(
              df=df,
              time_col=cst.TIME_COL,
              groupby_time_feature="dow",
              groupby_sliding_window_size=2,
              groupby_custom_column=None,
          )
  
      with pytest.raises(
          ValueError, match="Exactly one of.*must be specified"
      ):
          add_groupby_column(
              df=df,
              time_col=cst.TIME_COL,
              groupby_time_feature="dow",
              groupby_sliding_window_size=2,
              groupby_custom_column=custom_groups,
          )
  
imports: import datetime
  from datetime import datetime
  from functools import partial
  import numpy
  import pandas
  import pytest
  from pandas.testing import assert_frame_equal
  from plotly.colors import DEFAULT_PLOTLY_COLORS
  from testfixtures import LogCapture
  import greykite.common.constants
  from greykite.common.evaluation import EvaluationMetricEnum
  from greykite.common.viz.timeseries_plotting import add_groupby_column
  from greykite.common.viz.timeseries_plotting import flexible_grouping_evaluation
  from greykite.common.viz.timeseries_plotting import grouping_evaluation
  from greykite.common.viz.timeseries_plotting import plot_dual_axis_figure
  from greykite.common.viz.timeseries_plotting import plot_forecast_vs_actual
  from greykite.common.viz.timeseries_plotting import plot_multivariate
  from greykite.common.viz.timeseries_plotting import plot_multivariate_grouped
  from greykite.common.viz.timeseries_plotting import plot_univariate
  from greykite.common.viz.timeseries_plotting import split_range_into_groups
label_desc: Use image node_id 6 for calling a global function with example usage: test_add_groupby_column() without return types