code: def test_find_trend_changepoints(hourly_data):
      df = hourly_data["df"]
      dl = DataLoader()
      df_pt = dl.load_peyton_manning()
  
      model = ChangepointDetector()
      # test class variables are initialized as None
      assert model.trend_model is None
      assert model.trend_coef is None
      assert model.trend_intercept is None
      assert model.trend_changepoints is None
      assert model.trend_potential_changepoint_n is None
      assert model.trend_df is None
      assert model.y is None
      assert model.original_df is None
      assert model.value_col is None
      assert model.time_col is None
      assert model.adaptive_lasso_coef is None
      # model training with default values
      model.find_trend_changepoints(df=df, time_col="ts", value_col="y")
      assert isinstance(model.trend_model, RegressorMixin)
      assert model.trend_model.coef_.shape[0] == 100 + 1 + 8 * 2
      assert model.trend_coef.shape[0] == 100 + 1 + 8 * 2
      assert model.trend_intercept is not None
      assert model.trend_changepoints is not None
      assert model.trend_potential_changepoint_n == 100
      assert model.trend_df.shape[1] == 100 + 1 + 8 * 2
      assert model.original_df.shape == df.shape
      assert model.time_col is not None
      assert model.value_col is not None
      assert model.adaptive_lasso_coef[1].shape[0] == 100 + 1 + 8 * 2
      assert model.y.index[0] not in model.trend_changepoints
      # model training with given values
      model = ChangepointDetector()
      model.find_trend_changepoints(
          df=df,
          time_col="ts",
          value_col="y",
          potential_changepoint_n=50,
          yearly_seasonality_order=6,
          resample_freq="2D",
          trend_estimator="lasso",
          adaptive_lasso_initial_estimator="ols",
      )
      assert isinstance(model.trend_model, RegressorMixin)
      assert model.trend_model.coef_.shape[0] == 50 + 1 + 6 * 2
      assert model.trend_coef.shape[0] == 50 + 1 + 6 * 2
      assert model.trend_intercept is not None
      assert model.trend_changepoints is not None
      assert model.trend_potential_changepoint_n == 50
      assert model.trend_df.shape[1] == 50 + 1 + 6 * 2
      assert model.original_df.shape == df.shape
      assert model.time_col is not None
      assert model.value_col is not None
      assert model.adaptive_lasso_coef[1].shape[0] == 50 + 1 + 6 * 2
      assert model.y.index[0] not in model.trend_changepoints
      # test a given ``regularization_strength``
      model = ChangepointDetector()
      model.find_trend_changepoints(
          df=df,
          time_col="ts",
          value_col="y",
          regularization_strength=1.0,
      )
      assert isinstance(model.trend_model, RegressorMixin)
      assert model.trend_model.coef_.shape[0] == 100 + 1 + 8 * 2
      assert model.trend_coef.shape[0] == 100 + 1 + 8 * 2
      assert model.trend_intercept is not None
      assert model.trend_changepoints is not None
      assert model.trend_potential_changepoint_n == 100
      assert model.trend_df.shape[1] == 100 + 1 + 8 * 2
      assert model.original_df.shape == df.shape
      assert model.time_col is not None
      assert model.value_col is not None
      assert model.adaptive_lasso_coef[1].shape[0] == 100 + 1 + 8 * 2
      assert model.y.index[0] not in model.trend_changepoints
      # ``regularization_strength`` == 1.0 indicates no change point
      assert model.trend_changepoints == []
      model.find_trend_changepoints(
          df=df,
          time_col="ts",
          value_col="y",
          regularization_strength=0.5,
      )
      # ``regularization_strength`` between 0 and 1 indicates at least one change point
      assert len(model.trend_changepoints) > 0
      model.find_trend_changepoints(
          df=df,
          time_col="ts",
          value_col="y",
          actual_changepoint_min_distance="D",
          regularization_strength=0.0,
      )
      # ``regularization_strength`` == 0.0 indicates all potential change points are present
      assert len(model.trend_changepoints) == 100
      # test `potential_changepoint_distance`
      model = ChangepointDetector()
      model.find_trend_changepoints(
          df=df,
          time_col="ts",
          value_col="y",
          potential_changepoint_distance="100D",
      )
      # test override `potential_changepoint_n`
      # df has length 500 days, with distance "100D", only 4 change points are placed.
      assert model.trend_potential_changepoint_n == 4
      with pytest.raises(
          ValueError,
          match="In potential_changepoint_distance, the maximal unit is 'D', "
          "i.e., you may use units no more than 'D' such as"
          "'10D', '5H', '100T', '200S'. The reason is that 'W', 'M' "
          "or higher has either cycles or indefinite number of days, "
          "thus is not parsable by pandas as timedelta.",
      ):
          model.find_trend_changepoints(
              df=df,
              time_col="ts",
              value_col="y",
              potential_changepoint_distance="2M",
          )
      # test `no_changepoint_distance_from_end` with the Peyton Manning data
      model = ChangepointDetector()
      res = model.find_trend_changepoints(
          df=df_pt,
          time_col="ts",
          value_col="y",
          no_changepoint_distance_from_begin="730D",
          no_changepoint_distance_from_end="730D",
          regularization_strength=0,
      )
      changepoints = res["trend_changepoints"]
      # test override `no_changepoint_proportion_from_end` and no change points in the last piece
      no_changepoint_proportion_from_end = timedelta(days=730) / (
          pd.to_datetime(df_pt["ts"].iloc[-1])
          - pd.to_datetime(df_pt["ts"].iloc[0])
      )
      last_date_to_have_changepoint = pd.to_datetime(
          df_pt["ts"].iloc[
              int(
                  df_pt.shape[0]
                  * (1 - no_changepoint_proportion_from_end)
              )
          ]
      )
      first_date_to_have_changepoint = pd.to_datetime(
          df_pt["ts"].iloc[
              int(df_pt.shape[0] * no_changepoint_proportion_from_end)
          ]
      )
      assert changepoints[-1] <= last_date_to_have_changepoint
      assert changepoints[0] >= first_date_to_have_changepoint
      # test value error
      with pytest.raises(
          ValueError,
          match="In no_changepoint_distance_from_end, the maximal unit is 'D', "
          "i.e., you may use units no more than 'D' such as"
          "'10D', '5H', '100T', '200S'. The reason is that 'W', 'M' "
          "or higher has either cycles or indefinite number of days, "
          "thus is not parsable by pandas as timedelta.",
      ):
          model.find_trend_changepoints(
              df=df_pt,
              time_col="ts",
              value_col="y",
              no_changepoint_distance_from_end="2M",
          )
      # test `no_changepoint_proportion_from_end` and `actual_changepoint_min_distance`
      # generates a df with trend change points, ensuring we detect change points
      df_trend = generate_test_changepoint_df()
      model = ChangepointDetector()
      res = model.find_trend_changepoints(
          df=df_trend,
          time_col="ts",
          value_col="y",
          potential_changepoint_n=50,
          yearly_seasonality_order=0,
          adaptive_lasso_initial_estimator="lasso",
          no_changepoint_proportion_from_end=0.3,
          actual_changepoint_min_distance="10D",
      )
      changepoints = res["trend_changepoints"]
      # last changepoint in first 70% data
      assert (
          changepoints[-1]
          <= df_trend["ts"][int(df_trend.shape[0] * 0.7)]
      )
      assert all(
          (changepoints[i + 1] - changepoints[i] >= to_offset("10D"))
          for i in range(len(changepoints) - 1)
      )
      # test the asserts above are violated when not specifying `no_changepoint_proportion_from_end`
      model = ChangepointDetector()
      res = model.find_trend_changepoints(
          df=df_trend,
          time_col="ts",
          value_col="y",
          potential_changepoint_n=50,
          yearly_seasonality_order=0,
          adaptive_lasso_initial_estimator="ridge",
          no_changepoint_proportion_from_end=0.0,
          actual_changepoint_min_distance="1D",
      )
      changepoints = res["trend_changepoints"]
      # last changepoint after first 70% data
      assert (
          changepoints[-1]
          > df_trend["ts"][int(df_trend.shape[0] * 0.7)]
      )
      # negative potential_changepoint_n
      model = ChangepointDetector()
      with pytest.raises(
          ValueError,
          match="potential_changepoint_n can not be negative. "
          "A large number such as 100 is recommended",
      ):
          model.find_trend_changepoints(
              df=df,
              time_col="ts",
              value_col="y",
              potential_changepoint_n=-1,
          )
      # negative year_seasonality_order
      model = ChangepointDetector()
      with pytest.raises(
          ValueError,
          match="year_seasonality_order can not be negative. "
          "A number less than or equal to 10 is recommended",
      ):
          model.find_trend_changepoints(
              df=df,
              time_col="ts",
              value_col="y",
              yearly_seasonality_order=-1,
          )
      # negative regularization_strength
      with pytest.raises(
          ValueError,
          match="regularization_strength must be between 0.0 and 1.0.",
      ):
          model.find_trend_changepoints(
              df=df,
              time_col="ts",
              value_col="y",
              regularization_strength=-1,
          )
      # estimator parameter combination not valid warning
      with pytest.warns(UserWarning, match="trend_estimator not in"):
          model = ChangepointDetector()
          model.find_trend_changepoints(
              df=df,
              time_col="ts",
              value_col="y",
              trend_estimator="something",
          )
      with pytest.warns(UserWarning, match="trend_estimator"):
          model = ChangepointDetector()
          model.find_trend_changepoints(
              df=df,
              time_col="ts",
              value_col="y",
              trend_estimator="ols",
              yearly_seasonality_order=8,
          )
      with pytest.warns(
          UserWarning, match="adaptive_lasso_initial_estimator"
      ):
          model = ChangepointDetector()
          model.find_trend_changepoints(
              df=df,
              time_col="ts",
              value_col="y",
              adaptive_lasso_initial_estimator="something",
          )
      # df sample size too small
      df = pd.DataFrame(
          data={
              "ts": pd.date_range(
                  start="2020-1-1", end="2020-1-3", freq="D"
              ),
              "y": [1, 2, 3],
          }
      )
      model = ChangepointDetector()
      with pytest.raises(
          ValueError,
          match="Change point detector does not work for less than "
          "5 observations. Please increase sample size.",
      ):
          model.find_trend_changepoints(
              df=df,
              time_col="ts",
              value_col="y",
          )
      # test when training data has missing dates, the model drops na from resample
      df = pd.DataFrame(
          data={
              "ts": pd.date_range(
                  start="2020-1-1", end="2020-1-9", freq="2D"
              ),
              "y": [1, 2, 3, 4, 5],
          }
      )
      model = ChangepointDetector()
      model.find_trend_changepoints(df=df, time_col="ts", value_col="y")
      assert model.y.isnull().sum().sum() == 0
      assert model.y.shape[0] == 5
      # tests varying yearly seasonality effect
      model = ChangepointDetector()
      model.find_trend_changepoints(
          df=df_pt,
          time_col="ts",
          value_col="y",
          yearly_seasonality_change_freq="365D",
      )
      assert model.trend_df.shape[1] > 100 + 1 + 8 * 2
  
imports: from datetime import timedelta
  import numpy
  import pandas
  import pytest
  from pandas.tseries.frequencies import to_offset
  from sklearn.base import RegressorMixin
  from testfixtures import LogCapture
  from greykite.algo.changepoint.adalasso.changepoint_detector import ChangepointDetector
  from greykite.algo.changepoint.adalasso.changepoint_detector import get_changepoints_dict
  from greykite.algo.changepoint.adalasso.changepoint_detector import get_seasonality_changepoints
  from greykite.algo.changepoint.shift_detection.shift_detector import ShiftDetection
  from greykite.common.data_loader import DataLoader
  from greykite.common.logging import LOGGER_NAME
  from greykite.common.testing_utils import generate_df_for_tests
  from greykite.common.testing_utils import generate_df_with_arbitrary_trends_and_shifts
  from greykite.common.testing_utils import generate_test_changepoint_df
label_desc: Use image node_id 2 for calling a global function with example usage: test_find_trend_changepoints(hourly_data) without return types