code: def validate_schema(
      nodes: Union[List[Hashable], Set[Hashable], NodeView],
      default_type: str = "continuous",
      schema: Optional[Dict[Hashable, str]] = None,
  ) -> Dict:
      """
      Verifies category type and uses default data type for unspecified variables.
  
      Variables in the schema but not in the node list are ignored. The ``nodes``
      object is taken as the ground truth for variables to process.
  
      Args:
          nodes: All variables that should have a schema.
          schema: Dictionary mapping a variable to a data type.
          default_type: Allowed data types are 'binary', 'continuous',
              'categorical:X' where X stands for the cardinality of the category.
              Leading zeros are not allowed for the cardinality.
      Returns:
          Schema with missing type imputed by ``default_type``
  
      Raises:
          ValueError: for unknown data type
          ValueError: for missing cardinality for categorical variables
      """
      if not any(
          x in default_type
          for x in VariableFeatureMapper.PERMISSIBLE_TYPES
      ):
          permissible_str = ", ".join(
              VariableFeatureMapper.PERMISSIBLE_TYPES
          )
          raise ValueError(
              f"Unknown default data type. Supported data types are {permissible_str}"
          )
  
      schema = {} if schema is None else schema
      # # add default data type to missing nodes
      schema = {k: schema.get(k, default_type) for k in nodes}
  
      # verify if the data type is supported
      if not all(
          any(t in x for t in VariableFeatureMapper.PERMISSIBLE_TYPES)
          for x in schema.values()
      ):
          unknown_vars = [
              k
              for k, v in schema.items()
              if v not in VariableFeatureMapper.PERMISSIBLE_TYPES
          ]
          permissible_str = ", ".join(
              VariableFeatureMapper.PERMISSIBLE_TYPES
          )
          raise ValueError(
              f"Unknown data type for variable(s) {unknown_vars}, "
              f"Supported data types are {permissible_str}"
          )
  
      missing_cardinality = {
          k
          for k, v in schema.items()
          if "categorical" in v
          and re.match(r"^categorical:[1-9]+[0-9]*", v) is None
      }
  
      if missing_cardinality:
          raise ValueError(
              f"Missing cardinality for categorical variable(s) {missing_cardinality} "
              "For example, specify the data type as `categorical:3` for a "
              "3-class categorical feature. Leading zeros are not allowed."
          )
      return schema
  
file_path: causalnex/causalnex/structure/categorical_variable_mapper.py
imports: import re
  from collections import OrderedDict
  from itertools import chain
  from typing import Dict, Hashable, Iterator, List, Optional, Set, Union
  from networkx.classes.reportviews import NodeView
label_desc: Use image node_id 1 for calling a global function with example usage: validate_schema(nodes, default_type, schema) and returns: schema