code: def test_set_out_sample_residuals_when_residuals_length_is_more_than_1000_and_append():
      """
      Test residuals stored when new residuals length is more than 1000 and append is True.
      """
      forecaster = ForecasterAutoregDirect(
          LinearRegression(fit_intercept=True), lags=3, steps=2
      )
      forecaster.fit(y=y)
      residuals = {1: np.arange(10), 2: np.arange(10)}
      residuals_2 = {1: np.arange(1200), 2: np.arange(1200)}
  
      forecaster.set_out_sample_residuals(residuals=residuals)
      forecaster.set_out_sample_residuals(
          residuals=residuals_2, append=True
      )
  
      expected = {}
      for key, value in residuals_2.items():
          rng = np.random.default_rng(seed=123)
          expected_2 = rng.choice(a=value, size=1000, replace=False)
          expected[key] = np.append(np.arange(10), expected_2)[:1000]
  
      results = forecaster.out_sample_residuals
  
      assert expected.keys() == results.keys()
      assert all(
          all(expected[k] == results[k]) for k in expected.keys()
      )
      assert all(len(value) == 1000 for value in results.values())
  
file_path: skforecast/skforecast/ForecasterAutoregDirect/tests/test_set_out_sample_residuals.py
imports: import re
  import pytest
  import numpy
  import pandas
  from skforecast.ForecasterAutoregDirect import ForecasterAutoregDirect
  from sklearn.linear_model import LinearRegression
  from sklearn.exceptions import NotFittedError
  from sklearn.preprocessing import StandardScaler
label_desc: Use image node_id 9 for calling a global function with example usage: test_set_out_sample_residuals_when_residuals_length_is_more_than_1000_and_append() without return types