code: def test_get_canonical_anomaly_df():
      """Tests `get_canonical_anomaly_df`."""
      # Non-overlapping anomaly periods
      anomaly_df = pd.DataFrame(
          {
              START_TIME_COL: pd.to_datetime(
                  ["2020-01-01", "2020-02-01"]
              ),
              END_TIME_COL: pd.to_datetime(
                  ["2020-01-02", "2020-02-05"]
              ),
          }
      )
      canonical_anomaly_df = get_canonical_anomaly_df(
          anomaly_df=anomaly_df, freq="D"
      )
      assert_equal(canonical_anomaly_df, anomaly_df)
      # Partially overlapping anomaly periods
      anomaly_df = pd.DataFrame(
          {
              "begin": [
                  "2020-01-02-05",
                  "2020-01-02-10",
                  "2020-01-02-03",
                  "2020-01-02-05",
              ],
              "end": [
                  "2020-01-02-15",
                  "2020-01-02-20",
                  "2020-01-02-17",
                  "2020-01-02-13",
              ],
          }
      )
      canonical_anomaly_df = get_canonical_anomaly_df(
          anomaly_df=anomaly_df,
          freq="H",
          start_time_col="begin",
          end_time_col="end",
      )
      expected_anomaly_df = pd.DataFrame(
          {
              START_TIME_COL: pd.to_datetime(["2020-01-02-03"]),
              END_TIME_COL: pd.to_datetime(["2020-01-02-20"]),
          }
      )
      assert_equal(canonical_anomaly_df, expected_anomaly_df)
      # One anomaly period covers others
      anomaly_df = pd.DataFrame(
          {
              "begin": [
                  "2020-02-05",
                  "2020-02-19",
                  "2020-02-03",
                  "2020-02-05",
              ],
              "end": [
                  "2020-02-15",
                  "2020-02-20",
                  "2020-02-17",
                  "2020-02-13",
              ],
          }
      )
      canonical_anomaly_df = get_canonical_anomaly_df(
          anomaly_df=anomaly_df,
          freq="D",
          start_time_col="begin",
          end_time_col="end",
      )
      expected_anomaly_df = pd.DataFrame(
          {
              START_TIME_COL: pd.to_datetime(
                  ["2020-02-03", "2020-02-19"]
              ),
              END_TIME_COL: pd.to_datetime(
                  ["2020-02-17", "2020-02-20"]
              ),
          }
      )
      assert_equal(canonical_anomaly_df, expected_anomaly_df)
      # Checks anomaly merging logic.
      anomaly_df = pd.DataFrame(
          {
              START_TIME_COL: pd.to_datetime(
                  ["2020-01-01", "2020-01-02", "2020-01-04"]
              ),
              END_TIME_COL: pd.to_datetime(
                  ["2020-01-02", "2020-01-03", "2020-01-05"]
              ),
          }
      )
      canonical_anomaly_df = get_canonical_anomaly_df(
          anomaly_df=anomaly_df, freq="D"
      )
      expected_anomaly_df = pd.DataFrame(
          {
              START_TIME_COL: pd.to_datetime(["2020-01-01"]),
              END_TIME_COL: pd.to_datetime(["2020-01-05"]),
          }
      )
      assert_equal(canonical_anomaly_df, expected_anomaly_df)
      # Checks anomaly merging logic
      anomaly_df = pd.DataFrame(
          {
              START_TIME_COL: pd.to_datetime(
                  ["2020-01-01", "2020-01-02", "2020-01-04"]
              ),
              END_TIME_COL: pd.to_datetime(
                  ["2020-01-02", "2020-01-03", "2020-01-05"]
              ),
          }
      )
      canonical_anomaly_df = get_canonical_anomaly_df(
          anomaly_df=anomaly_df, freq="H"
      )
      expected_anomaly_df = pd.DataFrame(
          {
              START_TIME_COL: pd.to_datetime(
                  ["2020-01-01", "2020-01-04"]
              ),
              END_TIME_COL: pd.to_datetime(
                  ["2020-01-03", "2020-01-05"]
              ),
          }
      )
      assert_equal(canonical_anomaly_df, expected_anomaly_df)
  
imports: import itertools
  import numpy
  import pandas
  import pytest
  from testfixtures import LogCapture
  from greykite.common.constants import ANOMALY_COL
  from greykite.common.constants import END_TIME_COL
  from greykite.common.constants import LOGGER_NAME
  from greykite.common.constants import START_TIME_COL
  from greykite.common.constants import TIME_COL
  from greykite.common.constants import TimeFeaturesEnum
  from greykite.common.testing_utils import assert_equal
  from greykite.detection.detector.ad_utils import add_new_params_to_records
  from greykite.detection.detector.ad_utils import get_anomaly_df
  from greykite.detection.detector.ad_utils import get_anomaly_df_from_outliers
  from greykite.detection.detector.ad_utils import get_canonical_anomaly_df
  from greykite.detection.detector.ad_utils import get_timestamp_ceil
  from greykite.detection.detector.ad_utils import get_timestamp_floor
  from greykite.detection.detector.ad_utils import optimize_df_with_constraints
  from greykite.detection.detector.ad_utils import partial_return
  from greykite.detection.detector.ad_utils import validate_volatility_features
  from greykite.detection.detector.ad_utils import vertical_concat_dfs
label_desc: Use image node_id 6 for calling a global function with example usage: test_get_canonical_anomaly_df() without return types