code: def time_and_space_learning_curve_splitter(
      train_data: pd.DataFrame,
      training_time_limit: str,
      space_column: str,
      time_column: str,
      freq: str = "M",
      space_hold_percentage: float = 0.5,
      holdout_gap: timedelta = timedelta(days=0),
      random_state: int = None,
      min_samples: int = 1000,
  ) -> SplitterReturnType:
      """
      Splits the data into temporal buckets given by the specified frequency.
      Uses a fixed out-of-ID and time hold out set for every fold.
      Training size increases per fold, with more recent data being added in each fold.
      Useful for learning curve validation, that is, for seeing how hold out performance
      increases as the training size increases with more recent data.
  
      Parameters
      ----------
      train_data : pandas.DataFrame
          A Pandas' DataFrame that will be split for learning curve estimation.
  
      training_time_limit : str
          The Date String for the end of the testing period. Should be of the same
          format as `time_column`.
  
      space_column : str
          The name of the ID column of `train_data`.
  
      time_column : str
          The name of the Date column of `train_data`.
  
      freq : str
          The temporal frequency.
          See: http://pandas.pydata.org/pandas-docs/stable/timeseries.html#offset-aliases
  
      space_hold_percentage : float
          The proportion of hold out IDs.
  
      holdout_gap: datetime.timedelta
          Timedelta of the gap between the end of the training period and the start of the validation period.
  
      random_state : int
          A seed for the random number generator for ID sampling across train and
          hold out sets.
  
      min_samples : int
          The minimum number of samples required in the split to keep the split.
      """
  
      train_data = train_data.reset_index()
      first_moment = train_data[time_column].min()
      date_range = pd.date_range(
          start=first_moment, end=training_time_limit, freq=freq
      )
  
      # sklearn function that handles int or object random states, turns them into a rng
      rng = check_random_state(random_state)
      out_of_space_mask = pipe(
          train_data,
          lambda df: df[
              df[time_column] > date_range[-1]
          ],  # filter out of time
          lambda df: df[space_column].unique(),  # get unique space
          lambda array: rng.choice(
              array,
              int(len(array) * space_hold_percentage),
              replace=False,
          ),
          lambda held_space: train_data[space_column].isin(held_space),
      )  # filter out of space
  
      training_time_limit_dt = (
          datetime.strptime(training_time_limit, "%Y-%m-%d")
          + holdout_gap
      )
      test_time = train_data[
          (train_data[time_column] > training_time_limit_dt)
          & out_of_space_mask
      ][time_column]
  
      def date_filter_fn(date: DateType) -> pd.DataFrame:
          return train_data[
              (train_data[time_column] <= date) & ~out_of_space_mask
          ]
  
      folds = _get_lc_folds(
          date_range,
          date_filter_fn,
          test_time,
          time_column,
          min_samples,
      )
  
      logs = list(map(_log_time_fold, folds))  # get fold logs
      folds_indexes = _lc_fold_to_indexes(
          folds
      )  # final formatting with idx
  
      return folds_indexes, logs
  
imports: import operator
  from datetime import datetime, timedelta
  from itertools import chain, repeat, starmap
  from typing import Callable, Iterable, List, Tuple, Union
  import numpy
  import pandas
  from sklearn.model_selection import GroupKFold, KFold, StratifiedKFold
  from sklearn.utils import check_random_state
  from toolz.curried import curry, partial, pipe, assoc, accumulate, map, filter
  from fklearn.common_docstrings import splitter_return_docstring
  from fklearn.types import DateType, LogType, SplitterReturnType
label_desc: Use image node_id 8 for calling a global function with example usage: time_and_space_learning_curve_splitter(train_data, training_time_limit, space_column, time_column, freq, space_hold_percentage, holdout_gap, random_state, min_samples) and returns: folds_indexes,  logs, train_data