code: def get_changepoints_dict(df, time_col, value_col, changepoints_dict):
      """The functions takes the ``changepoints_dict`` dictionary and returns the processed
      ``changepoints_dict``.
  
      If "method" == "auto", the change point detection algorithm is run and the function returns
      the ``changepoints_dict`` with "method"="custom" and automatically detected change points.
      If "method" == "custom" or "uniform", the original ``changepoints_dict`` is returned.
  
      Parameters
      ----------
      df : `pandas.DataFrame`
          The dataframe used to do change point detection.
      time_col : `str`
          The column name of time in ``df``.
      value_col : `str`
          The column name of values in ``df``.
      changepoints_dict : `dict`
          The ``changepoints_dict`` parameter that is fed into
          `~greykite.algo.forecast.silverkite.forecast_silverkite.SilverkiteForecast.forecast` or
          `~greykite.algo.forecast.silverkite.forecast_simple_silverkite.forecast_simple_silverkite`
          It must have keys:
  
              `"method"` : `str`, equals "custom", "uniform" or "auto"
  
          Depending on `"method"`, it must have keys:
  
              `"n_changepoints"` : `int`, when "method" == "uniform".
              `"dates"` : `Iterable[Union[int, float, str, datetime]]`, when "method" == "custom"
  
          When `"method"` == "auto", it can have optional keys that matches the parameters in
          `~greykite.algo.changepoint.adalasso.changepoint_detector.ChangepointDetector.find_trend_changepoints`,
          except ``df``, ``time_col`` and ``value_col``, and extra keys "dates", "combine_changepoint_min_distance"
          and "keep_detected", which correspond to the three parameters "custom_changepoint_dates", "min_distance"
          and "keep_detected" in `~greykite.algo.changepoint.adalasso.changepoints_utils.combine_detected_and_custom_trend_changepoints`.
          In all three "method" cases, it can have optional keys:
  
              "continuous_time_col": ``str`` or ``None``
                  Column to apply `growth_func` to, to generate changepoint features
                  Typically, this should match the growth term in the model
              "growth_func": ``callable`` or ``None``
                  Growth function (scalar -> scalar). Changepoint features are created
                  by applying `growth_func` to "continuous_time_col" with offsets.
                  If None, uses identity function to use `continuous_time_col` directly
                  as growth term.
  
      Returns
      -------
      changepoints_dict : `dict`
          If "method" == "custom" or "method" == "uniform", the return is the original dictionary.
          If "method" == "auto", the return is the dictionary with "method" = "custom" and
          "dates" = detected_changepoints. Change point detection related keys and values are used
          for change point detection, other keys and values will be included in the return dictionary.
  
      changepoint_detector : `ChangepointDetector` or `None`
          The ChangepointDetector class used for automatically trend changepoint detection if "method" == "auto",
          otherwise None.
      """
      if (
          changepoints_dict is not None
          and "method" in changepoints_dict.keys()
          and changepoints_dict["method"] == "auto"
      ):
          changepoint_detection_args = {
              "df": df,
              "time_col": time_col,
              "value_col": value_col,
          }
          changepoint_detection_keys = [
              "yearly_seasonality_order",
              "yearly_seasonality_change_freq",
              "resample_freq",
              "trend_estimator",
              "adaptive_lasso_initial_estimator",
              "regularization_strength",
              "actual_changepoint_min_distance",
              "potential_changepoint_distance",
              "potential_changepoint_n",
              "potential_changepoint_n_max",
              "no_changepoint_distance_from_begin",
              "no_changepoint_proportion_from_end",
              "no_changepoint_distance_from_end",
              "no_changepoint_proportion_from_end",
              "shift_detector",
          ]
          changepoints_dict_keys = [
              "continuous_time_col",
              "growth_func",
          ]
          for key in changepoint_detection_keys:
              if key in changepoints_dict.keys():
                  changepoint_detection_args[key] = changepoints_dict[
                      key
                  ]
          model = ChangepointDetector()
          result = model.find_trend_changepoints(
              **changepoint_detection_args
          )
          new_changepoints_dict = result["changepoints_dict"]
          custom_changepoint_keys = []
          if "dates" in changepoints_dict:
              # Here we reuse the key "dates" which is used in "method"=="custom" as additional custom dates
              # when "method"=="auto" to avoid having too many keys.
              # Gets the custom changepoints.
              custom_changepoints = changepoints_dict["dates"]
              df_dates = pd.to_datetime(df[time_col])
              min_date = min(df_dates)
              max_date = max(df_dates)
              custom_changepoints = pd.to_datetime(custom_changepoints)
              custom_changepoints = [
                  cp
                  for cp in custom_changepoints
                  if min_date < cp < max_date
              ]
              min_distance = changepoints_dict.get(
                  "combine_changepoint_min_distance", None
              )
              # If ``combine_changepoint_min_distance`` is not set, try to set is with ``actual_changepoint_min_distance``.
              if min_distance is None:
                  min_distance = changepoints_dict.get(
                      "actual_changepoint_min_distance", None
                  )
              # If ``keep_detected`` is not set, the default is False to keep custom changepoints.
              keep_detected = changepoints_dict.get(
                  "keep_detected", False
              )
              # Checks if custom changepoints are provided.
              # If provided, combines the detected changepoints and custom changepoints.
              custom_changepoint_keys = ["dates"]
              if custom_changepoints is not None:
                  # Keys used in adding custom changepoints
                  custom_changepoint_keys = [
                      "dates",
                      "combine_changepoint_min_distance",
                      "keep_detected",
                  ]
                  combined_changepoints = combine_detected_and_custom_trend_changepoints(
                      detected_changepoint_dates=new_changepoints_dict[
                          "dates"
                      ],
                      custom_changepoint_dates=custom_changepoints,
                      min_distance=min_distance,
                      keep_detected=keep_detected,
                  )
                  # Logs info if the detected changepoints are altered.
                  if not set(combined_changepoints) == set(
                      new_changepoints_dict["dates"]
                  ):
                      log_message(
                          f"Custom trend changepoints have been added to the detected trend changepoints."
                          f" The final trend changepoints are {combined_changepoints}",
                          LoggingLevelEnum.INFO,
                      )
                  new_changepoints_dict["dates"] = combined_changepoints
          for key in changepoints_dict_keys:
              if key in changepoints_dict.keys():
                  new_changepoints_dict[key] = changepoints_dict[key]
          unused_keys = [
              key
              for key in changepoints_dict.keys()
              if key
              not in ["method"]
              + changepoints_dict_keys
              + changepoint_detection_keys
              + custom_changepoint_keys
          ]
          if unused_keys:
              warnings.warn(
                  f"The following keys in ``changepoints_dict`` are not recognized\n"
                  f"{unused_keys}"
              )
          return new_changepoints_dict, model
      else:
          return changepoints_dict, None
  
imports: import warnings
  from datetime import timedelta
  from typing import List
  from typing import Optional
  import numpy
  import pandas
  from pandas.tseries.frequencies import to_offset
  from sklearn.base import RegressorMixin
  from sklearn.exceptions import ConvergenceWarning
  from sklearn.linear_model import LassoCV
  from sklearn.linear_model import LinearRegression
  from sklearn.linear_model import RidgeCV
  from greykite.algo.changepoint.adalasso.changepoints_utils import build_seasonality_feature_df_with_changes
  from greykite.algo.changepoint.adalasso.changepoints_utils import build_trend_feature_df_with_changes
  from greykite.algo.changepoint.adalasso.changepoints_utils import check_freq_unit_at_most_day
  from greykite.algo.changepoint.adalasso.changepoints_utils import combine_detected_and_custom_trend_changepoints
  from greykite.algo.changepoint.adalasso.changepoints_utils import compute_fitted_components
  from greykite.algo.changepoint.adalasso.changepoints_utils import compute_min_changepoint_index_distance
  from greykite.algo.changepoint.adalasso.changepoints_utils import estimate_seasonality_with_detected_changepoints
  from greykite.algo.changepoint.adalasso.changepoints_utils import estimate_trend_with_detected_changepoints
  from greykite.algo.changepoint.adalasso.changepoints_utils import get_changepoint_dates_from_changepoints_dict
  from greykite.algo.changepoint.adalasso.changepoints_utils import get_seasonality_changes_from_adaptive_lasso
  from greykite.algo.changepoint.adalasso.changepoints_utils import get_trend_changes_from_adaptive_lasso
  from greykite.algo.changepoint.adalasso.changepoints_utils import get_yearly_seasonality_changepoint_dates_from_freq
  from greykite.algo.changepoint.adalasso.changepoints_utils import plot_change
  from greykite.algo.changepoint.shift_detection.shift_detector import ShiftDetection
  from greykite.common.constants import TimeFeaturesEnum
  from greykite.common.features.timeseries_features import get_evenly_spaced_changepoints_dates
  from greykite.common.logging import LoggingLevelEnum
  from greykite.common.logging import log_message
  from greykite.common.logging import pprint
  from greykite.common.python_utils import ignore_warnings
label_desc: Use image node_id 1 for calling a global function with example usage: get_changepoints_dict(df, time_col, value_col, changepoints_dict) and returns: new_changepoints_dict,  model, changepoints_dict,  None