code: def test_polynomial_detrending():
      """Test that transformer results agree with manual detrending."""
      y = pd.Series(np.arange(20) * 0.5) + np.random.normal(
          0, 1, size=20
      )
      forecaster = PolynomialTrendForecaster(
          degree=1, with_intercept=True
      )
      transformer = Detrender(forecaster)
      transformer.fit(y)
  
      # check coefficients
      actual_coefs = transformer.forecaster_.regressor_.steps[-1][
          -1
      ].coef_
      expected_coefs = get_expected_polynomial_coefs(
          y, degree=1, with_intercept=True
      )[::-1]
      np.testing.assert_array_almost_equal(actual_coefs, expected_coefs)
  
      # check trend
      n = len(y)
      expected_trend = (
          expected_coefs[0] + np.arange(n) * expected_coefs[1]
      )
      expected_trend_2D = np.reshape(expected_trend, (n, 1))
      actual_trend = transformer.forecaster_.predict(-np.arange(n))
      np.testing.assert_array_almost_equal(
          actual_trend, expected_trend_2D
      )
  
      # check residuals
      actual = transformer.transform(y)
      expected = y - expected_trend
      np.testing.assert_array_almost_equal(actual, expected)
  
file_path: sktime/sktime/transformations/series/detrend/tests/test_detrend.py
imports: import numpy
  import pandas
  import pytest
  from sktime.datasets import load_airline
  from sktime.forecasting.trend import PolynomialTrendForecaster
  from sktime.forecasting.trend.tests.test_trend import get_expected_polynomial_coefs
  from sktime.transformations.series.detrend import Detrender
label_desc: Use image node_id 3 for calling a global function with example usage: test_polynomial_detrending() without return types