class_docstr: Detects labels that appear only in the test set.
  
  Parameters
  ----------
  max_images_to_display_per_label : int , default: 3
      maximum number of images to show from each newly found label in the test set.
  max_new_labels_to_display : int , default: 3
      Maximum number of new labels to display in output.
  {additional_check_init_params:2*indent}
class_docstr_tok: ["Detects","labels","that","appear","only","in","the","test","set",".","Parameters","--","--","--","--","--","max_images_to_display_per_label",":","int",",","default",":","3","maximum","number","of","images","to","show","from","each","newly","found","label","in","the","test","set",".","max_new_labels_to_display",":","int",",","default",":","3","Maximum","number","of","new","labels","to","display","in","output",".","{","additional_check_init_params:2","*","indent","}"]
docstr: Add condition - Ratio of labels that appear only in the test set required to be less or equal to the threshold.
  
  Parameters
  ----------
  max_allowed_new_labels_ratio: float , default: 0.005
      the max threshold for percentage of labels that only apper in the test set.
docstr_tok: ["Add","condition","-","Ratio","of","labels","that","appear","only","in","the","test","set","required","to","be","less","or","equal","to","the","threshold",".","Parameters","--","--","--","--","--","max_allowed_new_labels_ratio",":","float",",","default",":","0.005","the","max","threshold","for","percentage","of","labels","that","only","apper","in","the","test","set","."]
code: def add_condition_new_label_ratio_less_or_equal(
      self, max_allowed_new_labels_ratio: float = 0.005
  ):
      # Default value set to 0.005 because of sampling mechanism
      """
      Add condition - Ratio of labels that appear only in the test set required to be less or equal to the threshold.
  
      Parameters
      ----------
      max_allowed_new_labels_ratio: float , default: 0.005
          the max threshold for percentage of labels that only apper in the test set.
      """
  
      def condition(result: Dict) -> ConditionResult:
          total_labels_in_test_set = result["all_labels_count"]
          new_labels_in_test_set = sum(result["new_labels"].values())
          percent_new_labels = (
              new_labels_in_test_set / total_labels_in_test_set
          )
  
          if new_labels_in_test_set > 0:
              top_new_class = list(result["new_labels"].keys())[:3]
              message = f"{format_percent(percent_new_labels)} of labels found in test set were not in train set. "
              message += (
                  f"New labels most common in test set: {top_new_class}"
              )
          else:
              message = "No new labels were found in test set."
  
          category = (
              ConditionCategory.PASS
              if percent_new_labels <= max_allowed_new_labels_ratio
              else ConditionCategory.FAIL
          )
          return ConditionResult(category, message)
  
      name = (
          f"Percentage of new labels in the test set is less or equal to "
          f"{format_percent(max_allowed_new_labels_ratio)}"
      )
      return self.add_condition(name, condition)
  
imports: import string
  from collections import defaultdict
  from secrets import choice
  from typing import Dict, Optional
  import numpy
  from deepchecks.core import CheckResult, ConditionResult, DatasetKind
  from deepchecks.core.condition import ConditionCategory
  from deepchecks.core.errors import DeepchecksValueError
  from deepchecks.core.reduce_classes import ReduceLabelMixin
  from deepchecks.utils.strings import format_number, format_percent
  from deepchecks.vision._shared_docs import docstrings
  from deepchecks.vision.base_checks import TrainTestCheck
  from deepchecks.vision.context import Context
  from deepchecks.vision.utils.image_functions import draw_image
  from deepchecks.vision.vision_data import TaskType
  from deepchecks.vision.vision_data.batch_wrapper import BatchWrapper
label_desc: Use image node_id 7 for calling the NewLabels obj's underlying member method code with example usage: obj.add_condition_new_label_ratio_less_or_equal(max_allowed_new_labels_ratio) and returns: self, ConditionResult