class_docstr: Find new categories in the test set.
  
  Parameters
  ----------
  columns : Union[Hashable, List[Hashable]] , default: None
      Columns to check, if none are given checks all columns except ignored ones.
  ignore_columns : Union[Hashable, List[Hashable]] , default: None
      Columns to ignore, if none given checks based on columns variable.
  max_features_to_show : int , default: 5
      maximum features with new categories to show
  max_new_categories_to_show : int , default: 5
      maximum new categories to show in feature
  aggregation_method: Optional[str], default: 'max'
      {feature_aggregation_method_argument:2*indent}
  n_samples : int , default: 10_000_000
      number of samples to use for this check.
  random_state : int, default: 42
      random seed for all check internals.
class_docstr_tok: ["Find","new","categories","in","the","test","set",".","Parameters","--","--","--","--","--","columns",":","Union","[","Hashable",",","List","[","Hashable","]","]",",","default",":","None","Columns","to","check",",","if","none","are","given","checks","all","columns","except","ignored","ones",".","ignore_columns",":","Union","[","Hashable",",","List","[","Hashable","]","]",",","default",":","None","Columns","to","ignore",",","if","none","given","checks","based","on","columns","variable",".","max_features_to_show",":","int",",","default",":","5","maximum","features","with","new","categories","to","show","max_new_categories_to_show",":","int",",","default",":","5","maximum","new","categories","to","show","in","feature","aggregation_method",":","Optional","[","str","]",",","default",":","'max'","{","feature_aggregation_method_argument:2","*","indent","}","n_samples",":","int",",","default",":","10_000_000","number","of","samples","to","use","for","this","check",".","random_state",":","int",",","default",":","42","random","seed","for","all","check","internals","."]
docstr: Run check.
  
  Returns
  -------
  CheckResult
      value is a dataframe that lists new categories for each cat feature with its count
      displays a dataframe that shows columns with new categories
docstr_tok: ["Run","check",".","Returns","--","--","--","-","CheckResult","value","is","a","dataframe","that","lists","new","categories","for","each","cat","feature","with","its","count","displays","a","dataframe","that","shows","columns","with","new","categories"]
code: def run_logic(self, context: Context) -> CheckResult:
      """Run check.
  
      Returns
      -------
      CheckResult
          value is a dataframe that lists new categories for each cat feature with its count
          displays a dataframe that shows columns with new categories
      """
      test_dataset = context.test.sample(
          self.n_samples, random_state=self.random_state
      )
      train_dataset = context.train.sample(
          self.n_samples, random_state=self.random_state
      )
      cat_features = train_dataset.cat_features
  
      test_df = select_from_dataframe(
          test_dataset.data, self.columns, self.ignore_columns
      )
      train_df = select_from_dataframe(
          train_dataset.data, self.columns, self.ignore_columns
      )
  
      # After filtering the columns drop cat features that don't exist anymore
      cat_features = set(cat_features).intersection(
          set(train_df.columns)
      )
      feature_importance = (
          pd.Series(index=list(cat_features), dtype=object)
          if context.feature_importance is None
          else context.feature_importance
      )
  
      result_data = []
      n_test_samples = test_dataset.n_samples
  
      for feature in cat_features:
          train_column = train_df[feature]
          test_column = test_df[feature]
  
          # Nans are not considered as new categories
          train_column = train_column.dropna()
          test_column = test_column.dropna()
  
          unique_training_values = train_column.unique()
          unique_test_values = test_column.unique()
  
          new_category_values = sorted(
              list(
                  (
                      set(unique_test_values)
                      - set(unique_training_values)
                  )
              )
          )
          if new_category_values:
              new_category_counts = dict(
                  test_column.value_counts()[new_category_values]
              )
              new_categories_ratio = (
                  sum(new_category_counts.values()) / n_test_samples
              )
              sorted_new_categories = dict(
                  sorted(
                      new_category_counts.items(),
                      key=lambda x: x[1],
                      reverse=True,
                  )
              )
              result_data.append(
                  [
                      feature,
                      len(new_category_values),
                      new_categories_ratio,
                      list(sorted_new_categories.keys()),
                      feature_importance[feature],
                  ]
              )
          else:
              result_data.append(
                  [feature, 0, 0, [], feature_importance[feature]]
              )
  
      result_data = pd.DataFrame(
          data=result_data,
          columns=[
              "Feature Name",
              "# New Categories",
              "Ratio of New Categories",
              "New categories",
              "Feature importance",
          ],
      ).set_index(["Feature Name"])
      result_data.sort_values(
          by="Ratio of New Categories", ascending=False, inplace=True
      )
      if all(feature_importance.isna()):
          result_data.drop("Feature importance", axis=1, inplace=True)
  
      if context.with_display:
          display = result_data.copy()
          display["Ratio of New Categories"] = display[
              "Ratio of New Categories"
          ].apply(format_percent)
          display["# New Categories"] = display[
              "# New Categories"
          ].apply(format_number)
          display["New Categories Names"] = display[
              "New categories"
          ].apply(lambda x: x[: self.max_new_categories_to_show])
          display.drop("New categories", axis=1, inplace=True)
          display = display.iloc[: self.max_features_to_show, :]
      else:
          display = None
  
      return CheckResult(result_data, display=display)
  
file_path: deepchecks/deepchecks/tabular/checks/train_test_validation/new_category_train_test.py
imports: from typing import Dict, List, Optional, Union
  import pandas
  from deepchecks.core import CheckResult, ConditionCategory, ConditionResult
  from deepchecks.core.reduce_classes import ReduceFeatureMixin
  from deepchecks.tabular import Context, TrainTestCheck
  from deepchecks.tabular._shared_docs import docstrings
  from deepchecks.tabular.utils.messages import get_condition_passed_message
  from deepchecks.utils.dataframes import select_from_dataframe
  from deepchecks.utils.strings import format_number, format_percent
  from deepchecks.utils.typing import Hashable
label_desc: Use image node_id 2 for calling the NewCategoryTrainTest obj's underlying member method code with example usage: obj.run_logic(context) and returns: CheckResult