class_docstr: Defines the cohort filter.
  :param method: Cohort filter method from one of CohortFilterMethods.
  :type method: str
  :param arg: List of values to be used by the cohort filter.
  :type arg: list
  :param column: The column name from the dataset on which the filter
                 will be applied.
  :type column: str
class_docstr_tok: ["Defines","the","cohort","filter",".",":","param","method",":","Cohort","filter","method","from","one","of","CohortFilterMethods",".",":","type","method",":","str",":","param","arg",":","List","of","values","to","be","used","by","the","cohort","filter",".",":","type","arg",":","list",":","param","column",":","The","column","name","from","the","dataset","on","which","the","filter","will","be","applied",".",":","type","column",":","str"]
docstr: Validate the cohort filters parameters with respect to test data.
  
  :param test_data: Test data over which cohort analysis will be done
      in ResponsibleAI Dashboard.
  :type test_data: pd.DataFrame
  :param target_column: The target column in the test data.
  :type target_column: str
  :param categorical_features: The categorical feature names.
  :type categorical_features: list[str]
  :param is_classification: True to indicate if this validation needs
      to be done for a classification scenario and False to indicate
      that this needs to be done for regression scenario.
  :type is_classification: bool
  
  The following validations need to be performed for cohort filter with
  test data:-
  
  High level validations
  1. Validate if the filter column is present in the test data.
  2. Validate if the filter column is present in the special column
     list.
  
  "Index" Filter validations
  1. The Index filter only takes integer arguments.
  2. The Index filter doesn't take CohortFilterMethods.EXCLUDES
     filter method.
  
  "Classification outcome" Filter validations
  1. Validate that "Classification outcome" filter is not configure for
     multiclass classification and regression.
  2. The "Classification outcome" filter only contains values from set
     ClassificationOutcomes.
  3. The "Classification outcome" filter only takes
     CohortFilterMethods.INCLUDES filter method.
  
  "Error" Filter validations
  1. Validate that "Error" filter is not configure for
     multiclass classification and binary classification.
  2. Only integer or floating points can be configured as arguments.
  3. The CohortFilterMethods.INCLUDES and CohortFilterMethods.EXCLUDES
     filter methods cannot be configured for this filter.
  
  "Predicted Y/True Y" Filter validations
  1. The set of classes configured in case of classification is a
     superset of the classes available in the test data.
  2. The CohortFilterMethods.INCLUDES is only allowed to be
     configured for "Predicted Y" filter in case of classification.
  3. The CohortFilterMethods.INCLUDES and CohortFilterMethods.EXCLUDES
     filter methods cannot be configured for this filter for regression.
  
  "Dataset" Filter validations
  1. TODO:- For continuous features the allowed values that be configured
     should be within the range of minimum and maximum values available
     within the continuous feature column in the test data.
  2. For categorical features only CohortFilterMethods.INCLUDES can be
     configured.
  3. For categorical features the values allowed are a subset of the
     the values available in the categorical column in the test data.
docstr_tok: ["Validate","the","cohort","filters","parameters","with","respect","to","test","data",".",":","param","test_data",":","Test","data","over","which","cohort","analysis","will","be","done","in","ResponsibleAI","Dashboard",".",":","type","test_data",":","pd.DataFrame",":","param","target_column",":","The","target","column","in","the","test","data",".",":","type","target_column",":","str",":","param","categorical_features",":","The","categorical","feature","names",".",":","type","categorical_features",":","list","[","str","]",":","param","is_classification",":","True","to","indicate","if","this","validation","needs","to","be","done","for","a","classification","scenario","and","False","to","indicate","that","this","needs","to","be","done","for","regression","scenario",".",":","type","is_classification",":","bool","The","following","validations","need","to","be","performed","for","cohort","filter","with","test","data",":","-","High","level","validations","1",".","Validate","if","the","filter","column","is","present","in","the","test","data",".","2",".","Validate","if","the","filter","column","is","present","in","the","special","column","list",".","``","Index","''","Filter","validations","1",".","The","Index","filter","only","takes","integer","arguments",".","2",".","The","Index","filter","does","n't","take","CohortFilterMethods.EXCLUDES","filter","method",".","``","Classification","outcome","''","Filter","validations","1",".","Validate","that","``","Classification","outcome","''","filter","is","not","configure","for","multiclass","classification","and","regression",".","2",".","The","``","Classification","outcome","''","filter","only","contains","values","from","set","ClassificationOutcomes",".","3",".","The","``","Classification","outcome","''","filter","only","takes","CohortFilterMethods.INCLUDES","filter","method",".","``","Error","''","Filter","validations","1",".","Validate","that","``","Error","''","filter","is","not","configure","for","multiclass","classification","and","binary","classification",".","2",".","Only","integer","or","floating","points","can","be","configured","as","arguments",".","3",".","The","CohortFilterMethods.INCLUDES","and","CohortFilterMethods.EXCLUDES","filter","methods","can","not","be","configured","for","this","filter",".","``","Predicted","Y\/True","Y","''","Filter","validations","1",".","The","set","of","classes","configured","in","case","of","classification","is","a","superset","of","the","classes","available","in","the","test","data",".","2",".","The","CohortFilterMethods.INCLUDES","is","only","allowed","to","be","configured","for","``","Predicted","Y","''","filter","in","case","of","classification",".","3",".","The","CohortFilterMethods.INCLUDES","and","CohortFilterMethods.EXCLUDES","filter","methods","can","not","be","configured","for","this","filter","for","regression",".","``","Dataset","''","Filter","validations","1",".","TODO",":","-","For","continuous","features","the","allowed","values","that","be","configured","should","be","within","the","range","of","minimum","and","maximum","values","available","within","the","continuous","feature","column","in","the","test","data",".","2",".","For","categorical","features","only","CohortFilterMethods.INCLUDES","can","be","configured",".","3",".","For","categorical","features","the","values","allowed","are","a","subset","of","the","the","values","available","in","the","categorical","column","in","the","test","data","."]
code: def _validate_with_test_data(
      self,
      test_data: pd.DataFrame,
      target_column: str,
      categorical_features: List[str],
      is_classification: Optional[bool] = True,
  ):
      """
      Validate the cohort filters parameters with respect to test data.
  
      :param test_data: Test data over which cohort analysis will be done
          in ResponsibleAI Dashboard.
      :type test_data: pd.DataFrame
      :param target_column: The target column in the test data.
      :type target_column: str
      :param categorical_features: The categorical feature names.
      :type categorical_features: list[str]
      :param is_classification: True to indicate if this validation needs
          to be done for a classification scenario and False to indicate
          that this needs to be done for regression scenario.
      :type is_classification: bool
  
      The following validations need to be performed for cohort filter with
      test data:-
  
      High level validations
      1. Validate if the filter column is present in the test data.
      2. Validate if the filter column is present in the special column
         list.
  
      "Index" Filter validations
      1. The Index filter only takes integer arguments.
      2. The Index filter doesn't take CohortFilterMethods.EXCLUDES
         filter method.
  
      "Classification outcome" Filter validations
      1. Validate that "Classification outcome" filter is not configure for
         multiclass classification and regression.
      2. The "Classification outcome" filter only contains values from set
         ClassificationOutcomes.
      3. The "Classification outcome" filter only takes
         CohortFilterMethods.INCLUDES filter method.
  
      "Error" Filter validations
      1. Validate that "Error" filter is not configure for
         multiclass classification and binary classification.
      2. Only integer or floating points can be configured as arguments.
      3. The CohortFilterMethods.INCLUDES and CohortFilterMethods.EXCLUDES
         filter methods cannot be configured for this filter.
  
      "Predicted Y/True Y" Filter validations
      1. The set of classes configured in case of classification is a
         superset of the classes available in the test data.
      2. The CohortFilterMethods.INCLUDES is only allowed to be
         configured for "Predicted Y" filter in case of classification.
      3. The CohortFilterMethods.INCLUDES and CohortFilterMethods.EXCLUDES
         filter methods cannot be configured for this filter for regression.
  
      "Dataset" Filter validations
      1. TODO:- For continuous features the allowed values that be configured
         should be within the range of minimum and maximum values available
         within the continuous feature column in the test data.
      2. For categorical features only CohortFilterMethods.INCLUDES can be
         configured.
      3. For categorical features the values allowed are a subset of the
         the values available in the categorical column in the test data.
      """
      # High level validations
      if self.column not in CohortFilter.SPECIAL_COLUMN_LIST and (
          self.column
          not in (set(test_data.columns) - set([target_column]))
      ):
          raise UserConfigValidationException(
              "Unknown column {0} specified in cohort filter".format(
                  self.column
              )
          )
  
      if self.column == CohortFilter.INDEX:
          # "Index" Filter validations
          if self.method == CohortFilterMethods.METHOD_EXCLUDES:
              raise UserConfigValidationException(
                  "{0} filter is not supported with {1} based "
                  "selection.".format(
                      CohortFilterMethods.METHOD_EXCLUDES,
                      CohortFilter.INDEX,
                  )
              )
  
          if not all(isinstance(entry, int) for entry in self.arg):
              raise UserConfigValidationException(
                  "All entries in arg should be of type int."
              )
      elif self.column == CohortFilter.CLASSIFICATION_OUTCOME:
          # "Classification outcome" Filter validations
          is_multiclass = (
              len(np.unique(test_data[target_column].values).tolist())
              > 2
          )
  
          if not is_classification or is_multiclass:
              raise UserConfigValidationException(
                  "{0} cannot be configured for multi-class classification"
                  " and regression scenarios.".format(
                      CohortFilter.CLASSIFICATION_OUTCOME
                  )
              )
  
          if self.method != CohortFilterMethods.METHOD_INCLUDES:
              raise UserConfigValidationException(
                  "{0} can only be configured with "
                  "cohort filter {1}.".format(
                      CohortFilter.CLASSIFICATION_OUTCOME,
                      CohortFilterMethods.METHOD_INCLUDES,
                  )
              )
  
          for classification_outcome in self.arg:
              if (
                  classification_outcome
                  not in ClassificationOutcomes.ALL
              ):
                  raise UserConfigValidationException(
                      "{0} can only take argument values from {1}.".format(
                          CohortFilter.CLASSIFICATION_OUTCOME,
                          " or ".join(ClassificationOutcomes.ALL),
                      )
                  )
      elif self.column == CohortFilter.REGRESSION_ERROR:
          # "Error" Filter validations
          if is_classification:
              raise UserConfigValidationException(
                  "{0} cannot be configured for classification"
                  " scenarios.".format(CohortFilter.REGRESSION_ERROR)
              )
  
          if (
              self.method == CohortFilterMethods.METHOD_INCLUDES
              or self.method == CohortFilterMethods.METHOD_EXCLUDES
          ):
              raise UserConfigValidationException(
                  "{0} cannot be configured with either {1} or {2}.".format(
                      CohortFilter.REGRESSION_ERROR,
                      CohortFilterMethods.METHOD_INCLUDES,
                      CohortFilterMethods.METHOD_EXCLUDES,
                  )
              )
  
          if not all(
              isinstance(entry, int) for entry in self.arg
          ) and not all(isinstance(entry, float) for entry in self.arg):
              raise UserConfigValidationException(
                  "All entries in arg should be of type int or float"
                  " for {} cohort.".format(
                      CohortFilter.REGRESSION_ERROR
                  )
              )
      elif (
          self.column == CohortFilter.PREDICTED_Y
          or self.column == CohortFilter.TRUE_Y
      ):
          # "Predicted Y/True Y" Filter validations
          if is_classification:
              if self.method != CohortFilterMethods.METHOD_INCLUDES:
                  raise UserConfigValidationException(
                      "{0} can only be configured with "
                      "filter {1} for classification".format(
                          self.column,
                          CohortFilterMethods.METHOD_INCLUDES,
                      )
                  )
  
              test_classes = np.unique(
                  test_data[target_column].values
              ).tolist()
  
              if not all(entry in test_classes for entry in self.arg):
                  raise UserConfigValidationException(
                      "Found a class in arg which is not present in "
                      "test data"
                  )
          else:
              if (
                  self.method == CohortFilterMethods.METHOD_INCLUDES
                  or self.method == CohortFilterMethods.METHOD_EXCLUDES
              ):
                  raise UserConfigValidationException(
                      "{0} cannot be configured with "
                      "filter {1} for regression.".format(
                          self.column, self.method
                      )
                  )
      else:
          # "Dataset" Filter validations
          if self.column in categorical_features:
              if self.method != CohortFilterMethods.METHOD_INCLUDES:
                  raise UserConfigValidationException(
                      "{0} is a categorical feature and should be only "
                      "configured with {1} cohort filter.".format(
                          self.column,
                          CohortFilterMethods.METHOD_INCLUDES,
                      )
                  )
  
              categories = np.unique(
                  test_data[self.column].values
              ).tolist()
  
              for entry in self.arg:
                  if entry not in categories:
                      raise UserConfigValidationException(
                          "Found a category {0} in arg which is not present "
                          "in test data column {1}.".format(
                              entry, self.column
                          )
                      )
  
imports: import json
  from typing import Any, List, Optional
  import numpy
  import pandas
  from raiutils.exceptions import UserConfigValidationException
  from .constants import ClassificationOutcomes, CohortFilterMethods
label_desc: Use image node_id 4 for calling the CohortFilter obj's underlying member method code with example usage: obj._validate_with_test_data(test_data, target_column, categorical_features, is_classification) without return types