code: def test_get_quantiles_and_overlays():
      """Tests get_quantiles_and_overlays"""
      dl = DataLoaderTS()
      peyton_manning_ts = dl.load_peyton_manning_ts()
  
      # no columns are requested
      with pytest.raises(
          ValueError,
          match="Must enable at least one of: show_mean, show_quantiles, show_overlays.",
      ):
          peyton_manning_ts.get_quantiles_and_overlays(
              groupby_time_feature="doy"
          )
  
      # show_mean only
      grouped_df = peyton_manning_ts.get_quantiles_and_overlays(
          groupby_time_feature="dow",
          show_mean=True,
          mean_col_name="custom_name",
      )
      assert_equal(
          grouped_df.columns,
          pd.MultiIndex.from_arrays(
              [[MEAN_COL_GROUP], ["custom_name"]],
              names=["category", "name"],
          ),
      )
      assert grouped_df.index.name == "dow"
      assert grouped_df.shape == (7, 1)
      assert grouped_df.index[0] == 1
  
      # show_quantiles only (bool)
      grouped_df = peyton_manning_ts.get_quantiles_and_overlays(
          groupby_sliding_window_size=180, show_quantiles=True
      )
      assert_equal(
          grouped_df.columns,
          pd.MultiIndex.from_arrays(
              [
                  [QUANTILE_COL_GROUP, QUANTILE_COL_GROUP],
                  ["Q0.1", "Q0.9"],
              ],
              names=["category", "name"],
          ),
      )
      assert grouped_df.index.name == "ts_downsample"
      assert grouped_df.shape == (17, 2)
      assert grouped_df.index[0] == pd.Timestamp(2007, 12, 10)
  
      # show_quantiles only (list)
      custom_col = pd.Series(
          np.random.choice(
              list("abcd"), size=peyton_manning_ts.df.shape[0]
          )
      )
      grouped_df = peyton_manning_ts.get_quantiles_and_overlays(
          groupby_custom_column=custom_col,
          show_quantiles=[0, 0.25, 0.5, 0.75, 1],
          quantile_col_prefix="prefix",
      )
      assert_equal(
          grouped_df.columns,
          pd.MultiIndex.from_arrays(
              [
                  [QUANTILE_COL_GROUP] * 5,
                  [
                      "prefix0",
                      "prefix0.25",
                      "prefix0.5",
                      "prefix0.75",
                      "prefix1",
                  ],
              ],
              names=["category", "name"],
          ),
      )
      assert grouped_df.index.name == "groups"
      assert grouped_df.shape == (4, 5)
      assert grouped_df.index[0] == "a"
      # checks quantile computation
      df = peyton_manning_ts.df.copy()
      df["custom_col"] = custom_col.values
      quantile_df = df.groupby("custom_col")[VALUE_COL].agg(
          [np.nanmin, np.nanmedian, np.nanmax]
      )
      assert_equal(
          grouped_df["quantile"]["prefix0"],
          quantile_df["nanmin"],
          check_names=False,
      )
      assert_equal(
          grouped_df["quantile"]["prefix0.5"],
          quantile_df["nanmedian"],
          check_names=False,
      )
      assert_equal(
          grouped_df["quantile"]["prefix1"],
          quantile_df["nanmax"],
          check_names=False,
      )
  
      # show_overlays only (bool), no overlay label
      grouped_df = peyton_manning_ts.get_quantiles_and_overlays(
          groupby_time_feature="doy", show_overlays=True
      )
      assert_equal(
          grouped_df.columns,
          pd.MultiIndex.from_arrays(
              [
                  [OVERLAY_COL_GROUP] * 9,
                  [f"overlay{i}" for i in range(9)],
              ],
              names=["category", "name"],
          ),
      )
      assert grouped_df.index.name == "doy"
      assert grouped_df.shape == (366, 9)
      assert grouped_df.index[0] == 1
  
      # show_overlays only (int below the available number), time feature overlay label
      np.random.seed(123)
      grouped_df = peyton_manning_ts.get_quantiles_and_overlays(
          groupby_time_feature="doy",
          show_overlays=4,
          overlay_label_time_feature="year",
      )
      assert_equal(
          grouped_df.columns,
          pd.MultiIndex.from_arrays(
              [
                  [OVERLAY_COL_GROUP] * 4,
                  ["2007", "2011", "2012", "2014"],
              ],
              names=["category", "name"],
          ),
      )
      assert grouped_df.index.name == "doy"
      assert grouped_df.shape == (366, 4)
      assert grouped_df.index[0] == 1
  
      # show_overlays only (int above the available number), custom overlay label
      grouped_df = peyton_manning_ts.get_quantiles_and_overlays(
          groupby_time_feature="dom",
          show_overlays=200,
          overlay_label_custom_column=custom_col,
      )
      assert_equal(
          grouped_df.columns,
          pd.MultiIndex.from_arrays(
              [[OVERLAY_COL_GROUP] * 4, ["a", "b", "c", "d"]],
              names=["category", "name"],
          ),
      )
      assert grouped_df.index.name == "dom"
      assert grouped_df.shape == (31, 4)
      assert grouped_df.index[0] == 1
  
      # show_overlays only (list of indices), sliding window overlay label
      grouped_df = peyton_manning_ts.get_quantiles_and_overlays(
          groupby_time_feature="dom",
          show_overlays=[0, 4],
          overlay_label_sliding_window_size=365 * 2,
      )
      assert_equal(
          grouped_df.columns,
          pd.MultiIndex.from_arrays(
              [
                  [OVERLAY_COL_GROUP] * 2,
                  ["2007-12-10 00:00:00", "2015-12-08 00:00:00"],
              ],
              names=["category", "name"],
          ),
      )
      assert grouped_df.index.name == "dom"
      assert grouped_df.shape == (31, 2)
      assert grouped_df.index[0] == 1
  
      # show_overlays only (np.ndarray), sliding window overlay label
      grouped_df = peyton_manning_ts.get_quantiles_and_overlays(
          groupby_time_feature="dom",
          show_overlays=np.arange(0, 6, 2),
          overlay_label_sliding_window_size=365 * 2,
      )
      assert_equal(
          grouped_df.columns,
          pd.MultiIndex.from_arrays(
              [
                  [OVERLAY_COL_GROUP] * 3,
                  [
                      "2007-12-10 00:00:00",
                      "2011-12-09 00:00:00",
                      "2015-12-08 00:00:00",
                  ],
              ],
              names=["category", "name"],
          ),
      )
      assert grouped_df.index.name == "dom"
      assert grouped_df.shape == (31, 3)
      assert grouped_df.index[0] == 1
  
      # show_overlays only (list of column names), sliding window overlay label
      grouped_df = peyton_manning_ts.get_quantiles_and_overlays(
          groupby_time_feature="dom",
          show_overlays=["2007-12-10 00:00:00", "2015-12-08 00:00:00"],
          overlay_label_sliding_window_size=365 * 2,
      )
      assert_equal(
          grouped_df.columns,
          pd.MultiIndex.from_arrays(
              [
                  [OVERLAY_COL_GROUP] * 2,
                  ["2007-12-10 00:00:00", "2015-12-08 00:00:00"],
              ],
              names=["category", "name"],
          ),
      )
      assert grouped_df.index.name == "dom"
      assert grouped_df.shape == (31, 2)
      assert grouped_df.index[0] == 1
  
      # Show all 3 (no overlay label)
      grouped_df = peyton_manning_ts.get_quantiles_and_overlays(
          groupby_sliding_window_size=50,  # 50 per group (50 overlays)
          show_mean=True,
          show_quantiles=[0.05, 0.5, 0.95],  # 3 quantiles
          show_overlays=True,
      )
      assert_equal(
          grouped_df.columns,
          pd.MultiIndex.from_arrays(
              [
                  [MEAN_COL_GROUP]
                  + [QUANTILE_COL_GROUP] * 3
                  + [OVERLAY_COL_GROUP] * 50,
                  ["mean", "Q0.05", "Q0.5", "Q0.95"]
                  + [f"overlay{i}" for i in range(50)],
              ],
              names=["category", "name"],
          ),
      )
      assert grouped_df.index.name == "ts_downsample"
      assert grouped_df.shape == (60, 54)
      assert grouped_df.index[-1] == pd.Timestamp(2016, 1, 7)
  
      # Show all 3 (with overlay label).
      # Pass overlay_pivot_table_kwargs.
      grouped_df = peyton_manning_ts.get_quantiles_and_overlays(
          groupby_sliding_window_size=180,
          show_mean=True,
          show_quantiles=[0.05, 0.5, 0.95],  # 3 quantiles
          show_overlays=True,
          overlay_label_time_feature="dow",  # 7 possible values
          aggfunc="median",
      )
      assert_equal(
          grouped_df.columns,
          pd.MultiIndex.from_arrays(
              [
                  [MEAN_COL_GROUP]
                  + [QUANTILE_COL_GROUP] * 3
                  + [OVERLAY_COL_GROUP] * 7,
                  [
                      "mean",
                      "Q0.05",
                      "Q0.5",
                      "Q0.95",
                      "1",
                      "2",
                      "3",
                      "4",
                      "5",
                      "6",
                      "7",
                  ],
              ],
              names=["category", "name"],
          ),
      )
      assert grouped_df.index.name == "ts_downsample"
      assert grouped_df.shape == (17, 11)
      assert grouped_df.index[-1] == pd.Timestamp(2015, 10, 29)
      assert (
          np.linalg.norm(grouped_df[OVERLAY_COL_GROUP].mean()) > 1.0
      )  # not centered
  
      with pytest.raises(
          TypeError,
          match="pivot_table\\(\\) got an unexpected keyword argument 'aggfc'",
      ):
          peyton_manning_ts.get_quantiles_and_overlays(
              groupby_sliding_window_size=180,
              show_mean=True,
              show_quantiles=[0.05, 0.5, 0.95],
              show_overlays=True,
              overlay_label_time_feature="dow",
              aggfc=np.nanmedian,
          )  # unrecognized parameter
  
      # center_values with show_mean=True
      centered_df = peyton_manning_ts.get_quantiles_and_overlays(
          groupby_sliding_window_size=180,
          show_mean=True,
          show_quantiles=[0.05, 0.5, 0.95],
          show_overlays=True,
          overlay_label_time_feature="dow",
          aggfunc="median",
          center_values=True,
      )
      assert (
          np.linalg.norm(
              centered_df[[MEAN_COL_GROUP, OVERLAY_COL_GROUP]].mean()
          )
          < 1e-8
      )  # centered at 0
      assert_equal(
          centered_df[QUANTILE_COL_GROUP],
          grouped_df[QUANTILE_COL_GROUP]
          - grouped_df[MEAN_COL_GROUP].mean()[0],
      )
  
      # center_values with show_mean=False
      centered_df = peyton_manning_ts.get_quantiles_and_overlays(
          groupby_sliding_window_size=180,
          show_mean=False,
          show_quantiles=[0.05, 0.5, 0.95],
          show_overlays=True,
          overlay_label_time_feature="dow",
          aggfunc="median",
          center_values=True,
      )
      assert (
          np.linalg.norm(centered_df[[OVERLAY_COL_GROUP]].mean()) < 1e-8
      )  # centered at 0
      overall_mean = peyton_manning_ts.df[VALUE_COL].mean()
      assert_equal(
          centered_df[QUANTILE_COL_GROUP],
          grouped_df[QUANTILE_COL_GROUP] - overall_mean,
      )
  
      # new value_col
      df = generate_df_with_reg_for_tests(freq="D", periods=700)["df"]
      ts = UnivariateTimeSeries()
      ts.load_data(df=df)
      grouped_df = ts.get_quantiles_and_overlays(
          groupby_time_feature="dow",
          show_mean=True,
          show_quantiles=True,
          show_overlays=True,
          overlay_label_time_feature="woy",
          value_col="regressor1",
      )
  
      df_dow = add_groupby_column(
          df=ts.df, time_col=TIME_COL, groupby_time_feature="dow"
      )
      dow_mean = (
          df_dow["df"]
          .groupby("dow")
          .agg(
              mean=pd.NamedAgg(column="regressor1", aggfunc=np.nanmean)
          )
      )
      assert_equal(grouped_df["mean"], dow_mean, check_names=False)
  
imports: import datetime
  from datetime import datetime
  import numpy
  import pandas
  import pytest
  from pandas.testing import assert_frame_equal
  from greykite.common.constants import ADJUSTMENT_DELTA_COL
  from greykite.common.constants import END_TIME_COL
  from greykite.common.constants import METRIC_COL
  from greykite.common.constants import START_TIME_COL
  from greykite.common.constants import TIME_COL
  from greykite.common.constants import VALUE_COL
  from greykite.common.python_utils import assert_equal
  from greykite.common.testing_utils import generate_df_for_tests
  from greykite.common.testing_utils import generate_df_with_reg_for_tests
  from greykite.common.time_properties import get_canonical_data
  from greykite.common.viz.timeseries_plotting import add_groupby_column
  from greykite.framework.benchmark.data_loader_ts import DataLoaderTS
  from greykite.framework.constants import MEAN_COL_GROUP
  from greykite.framework.constants import OVERLAY_COL_GROUP
  from greykite.framework.constants import QUANTILE_COL_GROUP
  from greykite.framework.input.univariate_time_series import UnivariateTimeSeries
label_desc: Use image node_id 14 for calling a global function with example usage: test_get_quantiles_and_overlays() without return types