code: def test_gcd_load_data_anomaly():
      """Checks anomaly_info parameter"""
      dl = DataLoader()
      df = dl.load_beijing_pm()
      value_col = "pm"
  
      # no anomaly adjustment
      canonical_data_dict = get_canonical_data(
          df=df, time_col=TIME_COL, value_col=value_col
      )
      assert canonical_data_dict["df_before_adjustment"] is None
  
      dim_one = "one"
      dim_two = "two"
      anomaly_df = pd.DataFrame(
          {
              START_TIME_COL: [
                  "2011-04-04-10",
                  "2011-10-10-00",
                  "2012-12-20-10",
              ],
              END_TIME_COL: [
                  "2011-04-05-20",
                  "2011-10-11-23",
                  "2012-12-20-13",
              ],
              ADJUSTMENT_DELTA_COL: [np.nan, 100.0, -100.0],
              METRIC_COL: [
                  dim_one,
                  dim_one,
                  dim_two,
              ],  # used to filter rows in this df
          }
      )
      # Adjusts one column (value_col)
      anomaly_info = {
          "value_col": value_col,
          "anomaly_df": anomaly_df,
          "start_time_col": START_TIME_COL,
          "end_time_col": END_TIME_COL,
          "adjustment_delta_col": ADJUSTMENT_DELTA_COL,
          "filter_by_dict": {METRIC_COL: dim_one},
          "adjustment_method": "add",
      }
      canonical_data_dict2 = get_canonical_data(
          df=df,
          time_col=TIME_COL,
          value_col=value_col,
          anomaly_info=anomaly_info,
      )
      assert_equal(
          canonical_data_dict2["df_before_adjustment"],
          canonical_data_dict["df"],
      )
      expected_df = canonical_data_dict["df"].copy()
      # first anomaly
      idx = (expected_df[TIME_COL] >= anomaly_df[START_TIME_COL][0]) & (
          expected_df[TIME_COL] <= anomaly_df[END_TIME_COL][0]
      )
      expected_df.loc[idx, VALUE_COL] = np.nan
      # second anomaly
      idx = (expected_df[TIME_COL] >= anomaly_df[START_TIME_COL][1]) & (
          expected_df[TIME_COL] <= anomaly_df[END_TIME_COL][1]
      )
      expected_df.loc[idx, VALUE_COL] += 100.0
      assert_equal(canonical_data_dict2["df"], expected_df)
  
      # Adjusts two columns
      value_col_two = "pres"  # second column to adjust
      anomaly_info = [
          anomaly_info,
          {
              "value_col": value_col_two,
              "anomaly_df": anomaly_df,
              "start_time_col": START_TIME_COL,
              "end_time_col": END_TIME_COL,
              "adjustment_delta_col": ADJUSTMENT_DELTA_COL,
              "filter_by_dict": {METRIC_COL: dim_two},
              "adjustment_method": "subtract",
          },
      ]
      canonical_data_dict3 = get_canonical_data(
          df=df,
          time_col=TIME_COL,
          value_col=value_col,
          anomaly_info=anomaly_info,
      )
      # third anomaly. The value is subtracted, according to `adjustment_method`.
      idx = (expected_df[TIME_COL] >= anomaly_df[START_TIME_COL][2]) & (
          expected_df[TIME_COL] <= anomaly_df[END_TIME_COL][2]
      )
      expected_df.loc[idx, value_col_two] -= -100.0
      assert_equal(
          canonical_data_dict3["df_before_adjustment"],
          canonical_data_dict["df"],
      )
      assert_equal(canonical_data_dict3["df"], expected_df)
  
      # Checks that when `anomaly_df` sets the last few datapoints in `df` to NA,
      # `train_end_date` will not be affected.
      value_col = "pm"
      anomaly_df = pd.DataFrame(
          {
              START_TIME_COL: ["2014-12-31-22"],
              END_TIME_COL: ["2015-01-01-22"],
              ADJUSTMENT_DELTA_COL: [np.nan],
          }
      )
      # Adjusts one column (value_col)
      anomaly_info = {
          "value_col": value_col,
          "anomaly_df": anomaly_df,
          "start_time_col": START_TIME_COL,
          "end_time_col": END_TIME_COL,
          "adjustment_delta_col": ADJUSTMENT_DELTA_COL,
          "adjustment_method": "add",
      }
  
      canonical_data_dict4 = get_canonical_data(
          df=df,
          time_col=TIME_COL,
          value_col=value_col,
          anomaly_info=anomaly_info,
      )
  
      # Checks `train_end_date`.
      assert (
          canonical_data_dict4["train_end_date"] == df[TIME_COL].max()
      )
  
      # Checks if the adjustment was done correctly.
      values_after_adjustment = (
          canonical_data_dict4["df"][VALUE_COL].tail(3).values
      )
      expected_after_adjustment = np.array([10, np.nan, np.nan])
      assert_equal(values_after_adjustment, expected_after_adjustment)
  
imports: import datetime
  import numpy
  import pandas
  import pytest
  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.data_loader import DataLoader
  from greykite.common.enums import TimeEnum
  from greykite.common.python_utils import assert_equal
  from greykite.common.testing_utils import generate_df_with_reg_for_tests
  from greykite.common.time_properties import describe_timeseries
  from greykite.common.time_properties import fill_missing_dates
  from greykite.common.time_properties import find_missing_dates
  from greykite.common.time_properties import get_canonical_data
  from greykite.common.time_properties import infer_freq
  from greykite.common.time_properties import min_gap_in_seconds
label_desc: Use image node_id 9 for calling a global function with example usage: test_gcd_load_data_anomaly() without return types