code: def data_and_evaluations_from_raw_data(
      raw_data: Dict[str, TEvaluationOutcome],
      metric_names: List[str],
      trial_index: int,
      sample_sizes: Dict[str, int],
      data_type: DataType,
      start_time: Optional[Union[int, str]] = None,
      end_time: Optional[Union[int, str]] = None,
  ) -> Tuple[Dict[str, TEvaluationOutcome], Data]:
      """Transforms evaluations into Ax Data.
  
      Each evaluation is either a trial evaluation: {metric_name -> (mean, SEM)}
      or a fidelity trial evaluation for multi-fidelity optimizations:
      [(fidelities, {metric_name -> (mean, SEM)})].
  
      Args:
          raw_data: Mapping from arm name to raw_data.
          metric_names: Names of metrics used to transform raw data to evaluations.
          trial_index: Index of the trial, for which the evaluations are.
          sample_sizes: Number of samples collected for each arm, may be empty
              if unavailable.
          start_time: Optional start time of run of the trial that produced this
              data, in milliseconds or iso format.  Milliseconds will eventually be
              converted to iso format because iso format automatically works with the
              pandas column type `Timestamp`.
          end_time: Optional end time of run of the trial that produced this
              data, in milliseconds or iso format.  Milliseconds will eventually be
              converted to iso format because iso format automatically works with the
              pandas column type `Timestamp`.
      """
      evaluations = {
          arm_name: raw_data_to_evaluation(
              raw_data=raw_data[arm_name],
              metric_names=metric_names,
          )
          for arm_name in raw_data
      }
      if all(
          isinstance(evaluations[x], dict) for x in evaluations.keys()
      ):
          if data_type is DataType.MAP_DATA:
              raise UserInputError(
                  "The format of the `raw_data` is not compatible with `MapData`. "
                  "Possible cause: Did you set default data type to `MapData`, e.g., "
                  "for early stopping, but forgot to provide the `raw_data` "
                  "in the form of `[(fidelities, {metric_name -> (mean, SEM)})]` or "
                  "`[({mapping_key, mapping_value}, {metric_name -> (mean, SEM)})]`? "
                  f"Received: {raw_data=}"
              )
          # All evaluations are no-fidelity evaluations.
          data = Data.from_evaluations(
              evaluations=cast(
                  Dict[str, TTrialEvaluation], evaluations
              ),
              trial_index=trial_index,
              sample_sizes=sample_sizes,
              start_time=start_time,
              end_time=end_time,
          )
      elif all(
          isinstance(evaluations[x], list) for x in evaluations.keys()
      ):
          if data_type is DataType.DATA:
              raise UserInputError(
                  "The format of the `raw_data` is not compatible with `Data`. "
                  "Possible cause: Did you provide data for multi-fidelity evaluations, "
                  "e.g., for early stopping, but forgot to set the default data type "
                  f"to `MapData`? Received: {raw_data=}"
              )
          # All evaluations are map evaluations.
          data = MapData.from_map_evaluations(
              evaluations=cast(
                  Dict[str, TMapTrialEvaluation], evaluations
              ),
              trial_index=trial_index,
          )
      else:
          raise ValueError(
              "Evaluations included a mixture of no-fidelity and with-fidelity "
              "evaluations, which is not currently supported."
          )
      return evaluations, data
  
file_path: Ax/ax/core/formatting_utils.py
imports: from enum import Enum
  from typing import cast, Dict, List, Optional, Tuple, Type, Union
  import numpy
  from ax.core.data import Data
  from ax.core.map_data import MapData
  from ax.core.types import TEvaluationOutcome, TMapTrialEvaluation, TTrialEvaluation, validate_evaluation_outcome
  from ax.exceptions.core import UserInputError
  from ax.utils.common.typeutils import numpy_type_to_python_type
label_desc: Use image node_id 2 for calling a global function with example usage: data_and_evaluations_from_raw_data(raw_data, metric_names, trial_index, sample_sizes, data_type, start_time, end_time) and returns: evaluations,  data