code: def infer_domain(terms):
      
      domains = {t.domain for t in terms}
      num_domains = len(domains)
  
      if num_domains == 0:
          return GENERIC
      elif num_domains == 1:
          return domains.pop()
      elif num_domains == 2 and GENERIC in domains:
          domains.remove(GENERIC)
          return domains.pop()
      else:
          # Remove GENERIC if it's present before raising. Showing it to the user
          # is confusing because it doesn't contribute to the error.
          domains.discard(GENERIC)
          raise AmbiguousDomain(sorted(domains, key=repr))
docs: Infer the domain from a collection of terms.
  
      The algorithm for inferring domains is as follows:
  
      - If all input terms have a domain of GENERIC, the result is GENERIC.
  
      - If there is exactly one non-generic domain in the input terms, the result
        is that domain.
  
      - Otherwise, an AmbiguousDomain error is raised.
  
      Parameters
      ----------
      terms : iterable[zipline.pipeline.term.Term]
  
      Returns
      -------
      inferred : Domain or NotSpecified
  
      Raises
      ------
      AmbiguousDomain
          Raised if more than one concrete domain is present in the input terms.