code: def test_adjust_trend(df):
      """Tests adjust trend methods."""
      # Seasonal average
      model = SeasonalityInferrer()
      df_adj = model._adjust_trend(
          df=df,
          time_col=cst.TIME_COL,
          value_col=cst.VALUE_COL,
          method=TrendAdjustMethodEnum.seasonal_average.value,
          trend_average_col="year_woy_iso",
      )
      assert len(df_adj.columns) == 3
      assert_equal(
          df[cst.VALUE_COL].values,
          (
              df_adj[cst.VALUE_COL] + df_adj[model.FITTED_TREND_COL]
          ).values,
          rel=1e-10,
      )
      assert_equal(
          df_adj.loc[:4, "y"],
          pd.Series([0, 2.7583, 3.6115, 0.5488, 0.7180], name="y"),
          rel=1e-3,
      )
      assert_equal(
          df_adj.loc[:4, model.FITTED_TREND_COL],
          pd.Series(
              [-4.4135, -0.7247, -0.7247, -0.7247, -0.7247],
              name=model.FITTED_TREND_COL,
          ),
          rel=1e-3,
      )
  
      # Overall average
      df_adj = model._adjust_trend(
          df=df,
          time_col=cst.TIME_COL,
          value_col=cst.VALUE_COL,
          method=TrendAdjustMethodEnum.overall_average.value,
      )
      assert len(df_adj.columns) == 3
      assert_equal(
          df[cst.VALUE_COL].values,
          (
              df_adj[cst.VALUE_COL] + df_adj[model.FITTED_TREND_COL]
          ).values,
          rel=1e-10,
      )
      assert_equal(
          df_adj.loc[:4, "y"],
          pd.Series(
              [-8.4033, -1.9561, -1.1030, -4.1656, -3.9965], name="y"
          ),
          rel=1e-3,
      )
      assert_equal(
          df_adj.loc[:4, model.FITTED_TREND_COL],
          pd.Series(
              [3.9898, 3.9898, 3.9898, 3.9898, 3.9898],
              name=model.FITTED_TREND_COL,
          ),
          rel=1e-3,
      )
  
      # Spline fit
      df_adj = model._adjust_trend(
          df=df,
          time_col=cst.TIME_COL,
          value_col=cst.VALUE_COL,
          method=TrendAdjustMethodEnum.spline_fit.value,
          spline_fit_degree=3,
      )
      assert len(df_adj.columns) == 3
      assert_equal(
          df[cst.VALUE_COL].values,
          (
              df_adj[cst.VALUE_COL] + df_adj[model.FITTED_TREND_COL]
          ).values,
          rel=1e-10,
      )
      assert_equal(
          df_adj.loc[:4, "y"],
          pd.Series(
              [-3.4947, 2.9445, 3.7897, 0.7191, 0.8803], name="y"
          ),
          rel=1e-3,
      )
      assert_equal(
          df_adj.loc[:4, model.FITTED_TREND_COL],
          pd.Series(
              [-0.9188, -0.9108, -0.9029, -0.8950, -0.8870],
              name=model.FITTED_TREND_COL,
          ),
          rel=1e-3,
      )
  
      # Method not recognized
      method = "some_method"
      with pytest.raises(
          ValueError,
          match=f"The trend adjust method '{method}' is not a valid name. "
          f"Available methods are \\['seasonal_average', 'overall_average', 'spline_fit', 'none'\\].",
      ):
          model._adjust_trend(
              df=df,
              time_col=cst.TIME_COL,
              value_col=cst.VALUE_COL,
              method=method,
          )
  
      # ``trend_average_col`` not found.
      with pytest.raises(
          ValueError,
          match=f"The trend_average_col 'some_col' is neither found in df ",
      ):
          model._adjust_trend(
              df=df,
              time_col=cst.TIME_COL,
              value_col=cst.VALUE_COL,
              method=TrendAdjustMethodEnum.seasonal_average.value,
              trend_average_col="some_col",
          )
  
      # Negative spline degree.
      with pytest.raises(
          ValueError,
          match=f"Spline degree has be to a positive integer, "
          f"but found -1.",
      ):
          model._adjust_trend(
              df=df,
              time_col=cst.TIME_COL,
              value_col=cst.VALUE_COL,
              method=TrendAdjustMethodEnum.spline_fit.value,
              spline_fit_degree=-1,
          )
  
file_path: greykite/greykite/tests/algo/common/test_seasonality_inferrer.py
imports: from copy import deepcopy
  import pandas
  import pytest
  from greykite.algo.common.seasonality_inferrer import SeasonalityInferConfig
  from greykite.algo.common.seasonality_inferrer import SeasonalityInferrer
  from greykite.algo.common.seasonality_inferrer import TrendAdjustMethodEnum
  from greykite.common import constants
  from greykite.common.testing_utils import assert_equal
  from greykite.common.testing_utils import generate_df_for_tests
  from greykite.common.time_properties import infer_freq
label_desc: Use image node_id 7 for calling a global function with example usage: test_adjust_trend(df) without return types