code: def test_cv_for_global_model():
      def check_folds_dict(
          df,
          n_lags,
          n_forecasts,
          valid_fold_num,
          valid_fold_pct,
          fold_overlap_pct,
          global_model_cv_type="local",
      ):
          "Does not work with global_model_cv_type == global-time or global_model_cv_type is None"
          folds = df_utils.crossvalidation_split_df(
              df,
              n_lags,
              n_forecasts,
              valid_fold_num,
              valid_fold_pct,
              fold_overlap_pct,
              global_model_cv_type=global_model_cv_type,
          )
          for df_name, df_i in df.groupby("ID"):
              train_folds_len = []
              val_folds_len = []
              for f_train, f_val in folds:
                  train_folds_len.append(
                      len(f_train[f_train["ID"] == df_name])
                  )
                  val_folds_len.append(
                      len(f_val[f_val["ID"] == df_name])
                  )
              if global_model_cv_type == "local":
                  total_samples = (
                      len(df_i) - n_lags - (2 * n_forecasts) + 2
                  )
              elif global_model_cv_type == "intersect":
                  (
                      start_date,
                      end_date,
                  ) = df_utils.find_valid_time_interval_for_cv(df)
                  total_samples = (
                      len(pd.date_range(start=start_date, end=end_date))
                      - n_lags
                      - (2 * n_forecasts)
                      + 2
                  )
              else:
                  raise ValueError(
                      "Insert valid value for global_model_cv_type (None or global-type does not work for this function"
                  )
              train_folds_samples = [
                  x - n_lags - n_forecasts + 1 for x in train_folds_len
              ]
              val_folds_samples = [
                  x - n_lags - n_forecasts + 1 for x in val_folds_len
              ]
              val_fold_each = max(
                  1, int(total_samples * valid_fold_pct)
              )
              overlap_each = int(fold_overlap_pct * val_fold_each)
              assert all(
                  [x == val_fold_each for x in val_folds_samples]
              )
              train_folds_should = [
                  total_samples
                  - val_fold_each
                  - (valid_fold_num - i - 1)
                  * (val_fold_each - overlap_each)
                  for i in range(valid_fold_num)
              ]
              assert all(
                  [
                      x == y
                      for (x, y) in zip(
                          train_folds_samples, train_folds_should
                      )
                  ]
              )
          return folds
  
      # Test cv for dict with time series with similar time range
      len_df = 1000
      df1 = pd.DataFrame(
          {
              "ds": pd.date_range(start="2017-01-01", periods=len_df),
              "y": np.arange(len_df) * 3,
              "ID": "df1",
          }
      )
      df2 = pd.DataFrame(
          {
              "ds": pd.date_range(start="2017-01-01", periods=len_df),
              "y": np.arange(len_df) * 5,
              "ID": "df2",
          }
      )
      df3 = pd.DataFrame(
          {
              "ds": pd.date_range(start="2017-01-01", periods=len_df),
              "y": np.arange(len_df) * 2,
              "ID": "df3",
          }
      )
      df_global = pd.concat((df1, df2, df3))
      n_lags = 3
      n_forecasts = 2
      k = 4
      valid_fold_pct = 0.1
      fold_overlap_pct = 0.5
      # test three different types of crossvalidation for df_dict
      global_model_cv_options = ["global-time", "local", "intersect"]
      fold_type = {}
      single_fold = df_utils.crossvalidation_split_df(
          df1, n_lags, n_forecasts, k, valid_fold_pct, fold_overlap_pct
      )
      for cv_type in global_model_cv_options:
          if cv_type == "global-time":
              fold_type[cv_type] = df_utils.crossvalidation_split_df(
                  df_global,
                  n_lags,
                  n_forecasts,
                  k,
                  valid_fold_pct,
                  fold_overlap_pct,
                  global_model_cv_type=cv_type,
              )
              # manually asserting global-time case:
              for i in range(k):
                  for j in range(2):
                      aux = fold_type[cv_type][i][j].copy(deep=True)
                      assert len(aux[aux["ID"] == "df1"]) == len(
                          single_fold[i][j]
                      )
          else:
              fold_type[cv_type] = check_folds_dict(
                  df_global,
                  n_lags,
                  n_forecasts,
                  k,
                  valid_fold_pct,
                  fold_overlap_pct,
                  global_model_cv_type=cv_type,
              )
      # since the time range is the same in all cases all of the folds should be exactly the same no matter the
      # global_model_cv_option
      for x in global_model_cv_options:
          for y in global_model_cv_options:
              if x != y:
                  assert fold_type[x][0][0].equals(fold_type[y][0][0])
      assert fold_type["global-time"][-1][0][
          fold_type["global-time"][-1][0]["ID"] == "df1"
      ].equals(single_fold[-1][0])
  
      # Test cv for dict with time series with different time range
      list_for_global_time_assertion = [
          580,
          639,
          608,
          215,
          215,
          215,
          790,
          849,
          818,
          215,
          156,
          187,
      ]
      df1 = pd.DataFrame(
          {
              "ds": pd.date_range(start="2017-03-01", periods=len_df),
              "y": np.arange(len_df) * 3,
              "ID": "df1",
          }
      )
      df2 = pd.DataFrame(
          {
              "ds": pd.date_range(start="2017-01-01", periods=len_df),
              "y": np.arange(len_df) * 5,
              "ID": "df2",
          }
      )
      df3 = pd.DataFrame(
          {
              "ds": pd.date_range(start="2017-02-01", periods=len_df),
              "y": np.arange(len_df) * 2,
              "ID": "df3",
          }
      )
      df_global = pd.concat((df1, df2, df3))
      n_lags = 5
      n_forecasts = 1
      k = 2
      valid_fold_pct = 0.2
      fold_overlap_pct = 0.0
      fold_type = {}
      for cv_type in global_model_cv_options:
          if cv_type == "global-time":
              fold_type[cv_type] = df_utils.crossvalidation_split_df(
                  df_global,
                  n_lags,
                  n_forecasts,
                  k,
                  valid_fold_pct,
                  fold_overlap_pct,
                  global_model_cv_type=cv_type,
              )
              # manually asserting global-time case:
              cont = 0
              for i in range(k):
                  for j in range(2):
                      for key in fold_type[cv_type][i][j][
                          "ID"
                      ].unique():
                          aux = fold_type[cv_type][i][j].copy(deep=True)
                          assert (
                              len(aux[aux["ID"] == key])
                              == list_for_global_time_assertion[cont]
                          )
                          cont = cont + 1
          else:
              fold_type[cv_type] = check_folds_dict(
                  df_global,
                  n_lags,
                  n_forecasts,
                  k,
                  valid_fold_pct,
                  fold_overlap_pct,
                  global_model_cv_type=cv_type,
              )
      for x in global_model_cv_options:
          for y in global_model_cv_options:
              if x != y:
                  with pytest.raises(AssertionError):
                      assert fold_type[x][0][0].equals(
                          fold_type[y][0][0]
                      )
      df_list = list()
      df_list.append(df1)
      # Raise value error for df type different than pd.DataFrame or dict
      with pytest.raises(ValueError):
          df_utils.crossvalidation_split_df(
              df_list,
              n_lags,
              n_forecasts,
              k,
              valid_fold_pct,
              fold_overlap_pct,
              global_model_cv_type=cv_type,
          )
      # Raise value error for invalid type of global_model_cv_type
      with pytest.raises(ValueError):
          df_utils.crossvalidation_split_df(
              df_global,
              n_lags,
              n_forecasts,
              k,
              valid_fold_pct,
              fold_overlap_pct,
              global_model_cv_type="invalid",
          )
  
imports: import logging
  import os
  import pathlib
  import matplotlib.pyplot
  import numpy
  import pandas
  import pytest
  from torch.utils.data import DataLoader
  from neuralprophet import NeuralProphet, configure, df_utils, time_dataset
  from neuralprophet.data.process import _create_dataset, _handle_missing_data
  from neuralprophet.data.transform import _normalize
label_desc: Use image node_id 8 for calling a global function with example usage: test_cv_for_global_model() and returns: folds