code: def validate_train_test_categories(
      train_data: pd.DataFrame,
      test_data: pd.DataFrame,
      rai_compute_type: str,
      categoricals: Optional[List[str]] = None,
  ):
      if categoricals is None:
          return
      _validate_unique_operation_on_categorical_columns(
          train_data, test_data, categoricals
      )
      discovered = {}
      for column in categoricals:
          if column in train_data.columns:
              train_unique = np.unique(train_data[column])
              test_unique = np.unique(test_data[column])
              difference = np.setdiff1d(test_unique, train_unique)
              if difference.shape[0] != 0:
                  discovered[column] = difference.tolist()
      if len(discovered) > 0:
          message = (
              "{} requires that every category of "
              "categorical features present in the test data "
              "be also present in the train data. "
              "Categories missing from train data: {}"
          )
          raise UserConfigValidationException(
              message.format(rai_compute_type, discovered)
          )
  
imports: from typing import List, Optional
  import numpy
  import pandas
  from raiutils.exceptions import UserConfigValidationException
label_desc: Use image node_id 2 for calling a global function with example usage: validate_train_test_categories(train_data, test_data, rai_compute_type, categoricals) without return types