code: def test_rolling_time_series_split3():
      """Tests rolling_time_series_split with max_splits"""
      # only the last split is kept
      with pytest.warns(Warning) as record:
          max_splits = 1
          tscv = RollingTimeSeriesSplit(
              forecast_horizon=2,
              min_train_periods=4,
              expanding_window=True,
              periods_between_splits=4,
              periods_between_train_test=2,
              max_splits=max_splits,
          )
  
          X = np.random.rand(20, 4)
          expected = [
              (np.array([0, 1, 2, 3]), np.array([6, 7])),
              (np.array([0, 1, 2, 3, 4, 5, 6, 7]), np.array([10, 11])),
              (
                  np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]),
                  np.array([14, 15]),
              ),
              (
                  np.array(
                      [
                          0,
                          1,
                          2,
                          3,
                          4,
                          5,
                          6,
                          7,
                          8,
                          9,
                          10,
                          11,
                          12,
                          13,
                          14,
                          15,
                      ]
                  ),
                  np.array([18, 19]),
              ),
          ]
          assert tscv.get_n_splits_without_capping(X=X) == 4
          assert tscv.get_n_splits(X=X) == max_splits
          assert_splits_equal(tscv.split(X=X), expected[-max_splits:])
  
          obtained_messages = "--".join(
              [r.message.args[0] for r in record]
          )
          assert "There is only one CV split" in obtained_messages
  
      # only the last two splits are kept
      max_splits = 2
      tscv = RollingTimeSeriesSplit(
          forecast_horizon=2,
          min_train_periods=4,
          expanding_window=True,
          use_most_recent_splits=False,
          periods_between_splits=4,
          periods_between_train_test=2,
          max_splits=max_splits,
      )
      assert tscv.get_n_splits_without_capping(X=X) == 4
      assert tscv.get_n_splits(X=X) == max_splits
      assert_splits_equal(tscv.split(X=X), expected[-max_splits:])
  
      # two splits and a random split are kept
      max_splits = 3
      tscv = RollingTimeSeriesSplit(
          forecast_horizon=2,
          min_train_periods=4,
          expanding_window=True,
          use_most_recent_splits=False,
          periods_between_splits=4,
          periods_between_train_test=2,
          max_splits=max_splits,
      )
      assert tscv.get_n_splits_without_capping(X=X) == 4
      assert tscv.get_n_splits(X=X) == max_splits
      expected_to_assert = [expected[i] for i in [0, 2, 3]]
      assert_splits_equal(
          tscv.split(X=X), expected_to_assert
      )  # picked at random (selection fixed by random seed)
  
      # all splits are kept (max_splits == get_n_splits)
      max_splits = 4
      tscv = RollingTimeSeriesSplit(
          forecast_horizon=2,
          min_train_periods=4,
          expanding_window=True,
          use_most_recent_splits=False,
          periods_between_splits=4,
          periods_between_train_test=2,
          max_splits=max_splits,
      )
      assert tscv.get_n_splits_without_capping(X=X) == 4
      assert tscv.get_n_splits(X=X) == 4
      assert_splits_equal(tscv.split(X=X), expected)
  
      # all splits are kept (max_splits > get_n_splits)
      max_splits = 5
      tscv = RollingTimeSeriesSplit(
          forecast_horizon=2,
          min_train_periods=4,
          expanding_window=True,
          use_most_recent_splits=False,
          periods_between_splits=4,
          periods_between_train_test=2,
          max_splits=max_splits,
      )
      assert tscv.get_n_splits_without_capping(X=X) == 4
      assert tscv.get_n_splits(X=X) == 4
      assert_splits_equal(tscv.split(X=X), expected)
  
      # rolling window evaluation
      # splits from end up to max_splits are kept
      max_splits = 3
      tscv = RollingTimeSeriesSplit(
          forecast_horizon=2,
          min_train_periods=4,
          expanding_window=True,
          use_most_recent_splits=True,
          periods_between_splits=4,
          periods_between_train_test=2,
          max_splits=max_splits,
      )
      assert tscv.use_most_recent_splits
      assert tscv.get_n_splits_without_capping(X=X) == 4
      assert tscv.get_n_splits(X=X) == max_splits
      expected_to_assert = [expected[i] for i in [1, 2, 3]]
      assert_splits_equal(tscv.split(X=X), expected_to_assert)
  
file_path: greykite/greykite/tests/sklearn/test_cross_validation.py
imports: import numpy
  import pytest
  from greykite.sklearn.cross_validation import RollingTimeSeriesSplit
label_desc: Use image node_id 4 for calling a global function with example usage: test_rolling_time_series_split3() without return types