class_docstr: Defines the CounterfactualManager for generating counterfactuals
  from a model.
class_docstr_tok: ["Defines","the","CounterfactualManager","for","generating","counterfactuals","from","a","model","."]
code: def _add_counterfactual_config(self, new_counterfactual_config):
      if any(_find_features_having_missing_values(self._train)):
          raise UserConfigValidationException(
              "Missing values are not allowed in the "
              "train dataset while computing counterfactuals."
          )
      if any(_find_features_having_missing_values(self._test)):
          raise UserConfigValidationException(
              "Missing values are not allowed in the "
              "test dataset while computing counterfactuals."
          )
  
      if self._model is None:
          raise UserConfigValidationException(
              "Model is required for counterfactual example generation and "
              "feature importances"
          )
  
      validate_train_test_categories(
          train_data=self._train,
          test_data=self._test,
          rai_compute_type="Counterfactual example generation",
          categoricals=self._categorical_features,
      )
  
      to_vary = new_counterfactual_config.features_to_vary
      if to_vary != "all":
          difference_set = set(to_vary) - set(self._train.columns)
          if len(difference_set) > 0:
              message = (
                  "Feature names in features_to_vary do "
                  f"not exist in train data: {list(difference_set)}"
              )
              raise UserConfigValidationException(message)
  
      if new_counterfactual_config.permitted_range is not None:
          permitted_features = list(
              new_counterfactual_config.permitted_range
          )
          difference_set = set(permitted_features) - set(
              self._train.columns
          )
          if len(difference_set) > 0:
              message = (
                  "Feature names in permitted_range do "
                  f"not exist in train data: {list(difference_set)}"
              )
              raise UserConfigValidationException(message)
  
      if self._task_type == ModelTask.CLASSIFICATION:
          if new_counterfactual_config.desired_class is None:
              raise UserConfigValidationException(
                  "The desired_class attribute should be either '{0}'"
                  " for binary classification or the class value for "
                  "multi-classification scenarios.".format(
                      CounterfactualConstants.OPPOSITE
                  )
              )
  
          is_multiclass = (
              len(
                  np.unique(
                      self._train[self._target_column].values
                  ).tolist()
              )
              > 2
          )
          if (
              is_multiclass
              and new_counterfactual_config.desired_class
              == CounterfactualConstants.OPPOSITE
          ):
              raise UserConfigValidationException(
                  "The desired_class attribute should not be '{0}'"
                  " It should be the class value for multiclass"
                  " classification scenario.".format(
                      CounterfactualConstants.OPPOSITE
                  )
              )
  
      if self._task_type == ModelTask.REGRESSION:
          if new_counterfactual_config.desired_range is None:
              raise UserConfigValidationException(
                  "The desired_range should not be None"
                  " for regression scenarios."
              )
  
      if (
          new_counterfactual_config.feature_importance
          and new_counterfactual_config.total_CFs < 10
      ):
          raise UserConfigValidationException(
              "A total_CFs value of at least 10 is required to "
              "use counterfactual feature importances. "
              "Either increase total_CFs to at least 10 or "
              "set feature_importance to False."
          )
  
      is_duplicate = new_counterfactual_config.is_duplicate(
          self._counterfactual_config_list
      )
  
      if is_duplicate:
          raise DuplicateManagerConfigException(
              "Duplicate counterfactual configuration detected."
          )
      else:
          self._counterfactual_config_list.append(
              new_counterfactual_config
          )
  
imports: import json
  import uuid
  import warnings
  from pathlib import Path
  from typing import Any, List, Optional, Union
  import dice_ml
  import jsonschema
  import numpy
  import pandas
  from dice_ml import Dice
  from dice_ml.counterfactual_explanations import CounterfactualExplanations
  from dice_ml.explainer_interfaces.explainer_base import ExplainerBase
  from raiutils.exceptions import UserConfigValidationException
  from raiutils.models import ModelTask
  from responsibleai._config.base_config import BaseConfig
  from responsibleai._data_validations import validate_train_test_categories
  from responsibleai._interfaces import CounterfactualData
  from responsibleai._internal.constants import CounterfactualManagerKeys, FileFormats, ListProperties, ManagerNames
  from responsibleai._tools.shared.state_directory_management import DirectoryManager
  from responsibleai.exceptions import DuplicateManagerConfigException, SchemaErrorException
  from responsibleai.managers.base_manager import BaseManager
  from responsibleai.utils import _find_features_having_missing_values, _measure_time
label_desc: Use image node_id 3 for calling the CounterfactualManager obj's underlying member method code with example usage: obj._add_counterfactual_config(new_counterfactual_config) without return types