code: def test_plot_event_periods_multi():
      """Tests ``plot_event_periods_multi`` function."""
      df = pd.DataFrame(
          {
              "start_time": [
                  "2020-01-01",
                  "2020-02-01",
                  "2020-01-02",
                  "2020-02-02",
                  "2020-02-05",
              ],
              "end_time": [
                  "2020-01-03",
                  "2020-02-04",
                  "2020-01-05",
                  "2020-02-06",
                  "2020-02-08",
              ],
              "metric": [
                  "impressions",
                  "impressions",
                  "clicks",
                  "clicks",
                  "bookings",
              ],
          }
      )
  
      # ``grouping_col`` is not passed.
      res = plot_event_periods_multi(
          periods_df=df,
          start_time_col="start_time",
          end_time_col="end_time",
          freq=None,
          grouping_col=None,
          min_timestamp=None,
          max_timestamp=None,
      )
  
      fig = res["fig"]
      labels_df = res["labels_df"]
      ts = res["ts"]
      min_timestamp = res["min_timestamp"]
      max_timestamp = res["max_timestamp"]
      new_cols = res["new_cols"]
  
      assert labels_df.shape == (913, 2)
      assert list(labels_df.columns) == ["ts", "metric_is_anomaly"]
      assert len(fig.data) == 1
      assert len(fig.data[0]["x"]) == 913
      assert len(ts) == 913
      assert min_timestamp == "2020-01-01"
      assert max_timestamp == "2020-02-08"
      assert new_cols == ["metric_is_anomaly"]
  
      # ``grouping_col`` is passed.
      res = plot_event_periods_multi(
          periods_df=df,
          start_time_col="start_time",
          end_time_col="end_time",
          freq=None,
          grouping_col="metric",
          min_timestamp=None,
          max_timestamp=None,
      )
  
      fig = res["fig"]
      labels_df = res["labels_df"]
      ts = res["ts"]
      min_timestamp = res["min_timestamp"]
      max_timestamp = res["max_timestamp"]
      new_cols = res["new_cols"]
  
      assert labels_df.shape == (913, 4)
      assert set(labels_df.columns) == {
          "ts",
          "bookings_is_anomaly",
          "impressions_is_anomaly",
          "clicks_is_anomaly",
      }
      assert len(fig.data) == 3
      assert len(fig.data[0]["x"]) == 913
      assert len(ts) == 913
      assert min_timestamp == "2020-01-01"
      assert max_timestamp == "2020-02-08"
      assert set(new_cols) == {
          "bookings_is_anomaly",
          "impressions_is_anomaly",
          "clicks_is_anomaly",
      }
  
      # Specifies ``freq``
      res = plot_event_periods_multi(
          periods_df=df,
          start_time_col="start_time",
          end_time_col="end_time",
          freq="min",
          grouping_col="metric",
          min_timestamp=None,
          max_timestamp=None,
      )
  
      fig = res["fig"]
      labels_df = res["labels_df"]
      ts = res["ts"]
      min_timestamp = res["min_timestamp"]
      max_timestamp = res["max_timestamp"]
      new_cols = res["new_cols"]
  
      assert labels_df.shape == (54721, 4)
      assert set(labels_df.columns) == {
          "ts",
          "bookings_is_anomaly",
          "impressions_is_anomaly",
          "clicks_is_anomaly",
      }
      assert len(fig.data) == 3
      assert len(fig.data[0]["x"]) == 54721
      assert len(ts) == 54721
      assert min_timestamp == "2020-01-01"
      assert max_timestamp == "2020-02-08"
      assert set(new_cols) == {
          "bookings_is_anomaly",
          "impressions_is_anomaly",
          "clicks_is_anomaly",
      }
  
      # ``min_timestamp``, ``max_timestamp`` specified.
      res = plot_event_periods_multi(
          periods_df=df,
          start_time_col="start_time",
          end_time_col="end_time",
          freq=None,
          grouping_col="metric",
          min_timestamp="2019-12-15",
          max_timestamp="2020-02-15",
      )
  
      fig = res["fig"]
      labels_df = res["labels_df"]
      ts = res["ts"]
      min_timestamp = res["min_timestamp"]
      max_timestamp = res["max_timestamp"]
      new_cols = res["new_cols"]
  
      assert labels_df.shape == (1489, 4)
      assert set(labels_df.columns) == {
          "ts",
          "bookings_is_anomaly",
          "impressions_is_anomaly",
          "clicks_is_anomaly",
      }
      assert len(fig.data) == 3
      assert len(fig.data[0]["x"]) == 1489
      assert len(ts) == 1489
      assert min_timestamp == "2019-12-15"
      assert max_timestamp == "2020-02-15"
      assert set(new_cols) == {
          "bookings_is_anomaly",
          "impressions_is_anomaly",
          "clicks_is_anomaly",
      }
  
      # Tests for raising ``ValueError`` due to start time being larger than end time.
      df = pd.DataFrame(
          {
              "start_time": ["2020-01-03"],
              "end_time": ["2020-01-02"],
              "metric": ["impressions"],
          }
      )
  
      expected_match = "End Time:"
      with pytest.raises(ValueError, match=expected_match):
          plot_event_periods_multi(
              periods_df=df,
              start_time_col="start_time",
              end_time_col="end_time",
              freq=None,
              grouping_col=None,
              min_timestamp=None,
              max_timestamp=None,
          )
  
imports: import numpy
  import pandas
  import pytest
  from greykite.common.constants import END_TIME_COL
  from greykite.common.constants import START_TIME_COL
  from greykite.common.python_utils import assert_equal
  from greykite.common.viz.colors_utils import get_distinct_colors
  from greykite.common.viz.timeseries_annotate import add_multi_vrects
  from greykite.common.viz.timeseries_annotate import plot_anomalies_over_forecast_vs_actual
  from greykite.common.viz.timeseries_annotate import plot_event_periods_multi
  from greykite.common.viz.timeseries_annotate import plot_lines_markers
  from greykite.common.viz.timeseries_annotate import plot_overlay_anomalies_multi_metric
  from greykite.common.viz.timeseries_annotate import plot_precision_recall_curve
  from greykite.common.viz.timeseries_annotate import plt_annotate_series
  from greykite.common.viz.timeseries_annotate import plt_compare_series_annotations
label_desc: Use image node_id 6 for calling a global function with example usage: test_plot_event_periods_multi() without return types