class_docstr: A set of ``Result`` objects for interacting with Ray Tune results.
  
  You can use it to inspect the trials and obtain the best result.
  
  The constructor is a private API. This object can only be created as a result of
  ``Tuner.fit()``.
  
  Example:
  .. testcode::
  
      import random
      from ray import train, tune
      def random_error_trainable(config):
          if random.random() < 0.5:
              return {"loss": 0.0}
          else:
              raise ValueError("This is an error")
      tuner = tune.Tuner(
          random_error_trainable,
          run_config=train.RunConfig(name="example-experiment"),
          tune_config=tune.TuneConfig(num_samples=10),
      )
      try:
          result_grid = tuner.fit()
      except ValueError:
          pass
      for i in range(len(result_grid)):
          result = result_grid[i]
          if not result.error:
                  print(f"Trial finishes successfully with metrics"
                     f"{result.metrics}.")
          else:
                  print(f"Trial failed with error {result.error}.")
  
  .. testoutput::
      :hide:
  
      ...
  
  You can also use ``result_grid`` for more advanced analysis.
  
  >>> # Get the best result based on a particular metric.
  >>> best_result = result_grid.get_best_result( # doctest: +SKIP
  ...     metric="loss", mode="min")
  >>> # Get the best checkpoint corresponding to the best result.
  >>> best_checkpoint = best_result.checkpoint # doctest: +SKIP
  >>> # Get a dataframe for the last reported results of all of the trials
  >>> df = result_grid.get_dataframe() # doctest: +SKIP
  >>> # Get a dataframe for the minimum loss seen for each trial
  >>> df = result_grid.get_dataframe(metric="loss", mode="min") # doctest: +SKIP
  
  Note that trials of all statuses are included in the final result grid.
  If a trial is not in terminated state, its latest result and checkpoint as
  seen by Tune will be provided.
  
  See :doc:`/tune/examples/tune_analyze_results` for more usage examples.
docstr: Get the best result from all the trials run.
  
  Args:
      metric: Key for trial info to order on. Defaults to
          the metric specified in your Tuner's ``TuneConfig``.
      mode: One of [min, max]. Defaults to the mode specified
          in your Tuner's ``TuneConfig``.
      scope: One of [all, last, avg, last-5-avg, last-10-avg].
          If `scope=last`, only look at each trial's final step for
          `metric`, and compare across trials based on `mode=[min,max]`.
          If `scope=avg`, consider the simple average over all steps
          for `metric` and compare across trials based on
          `mode=[min,max]`. If `scope=last-5-avg` or `scope=last-10-avg`,
          consider the simple average over the last 5 or 10 steps for
          `metric` and compare across trials based on `mode=[min,max]`.
          If `scope=all`, find each trial's min/max score for `metric`
          based on `mode`, and compare trials based on `mode=[min,max]`.
      filter_nan_and_inf: If True (default), NaN or infinite
          values are disregarded and these trials are never selected as
          the best trial.
docstr_tok: ["Get","the","best","result","from","all","the","trials","run",".","Args",":","metric",":","Key","for","trial","info","to","order","on",".","Defaults","to","the","metric","specified","in","your","Tuner","'s","``","TuneConfig","``",".","mode",":","One","of","[","min",",","max","]",".","Defaults","to","the","mode","specified","in","your","Tuner","'s","``","TuneConfig","``",".","scope",":","One","of","[","all",",","last",",","avg",",","last-5-avg",",","last-10-avg","]",".","If","`","scope=last","`",",","only","look","at","each","trial","'s","final","step","for","`","metric","`",",","and","compare","across","trials","based","on","`","mode=","[","min",",","max","]","`",".","If","`","scope=avg","`",",","consider","the","simple","average","over","all","steps","for","`","metric","`","and","compare","across","trials","based","on","`","mode=","[","min",",","max","]","`",".","If","`","scope=last-5-avg","`","or","`","scope=last-10-avg","`",",","consider","the","simple","average","over","the","last","5","or","10","steps","for","`","metric","`","and","compare","across","trials","based","on","`","mode=","[","min",",","max","]","`",".","If","`","scope=all","`",",","find","each","trial","'s","min\/max","score","for","`","metric","`","based","on","`","mode","`",",","and","compare","trials","based","on","`","mode=","[","min",",","max","]","`",".","filter_nan_and_inf",":","If","True","(","default",")",",","NaN","or","infinite","values","are","disregarded","and","these","trials","are","never","selected","as","the","best","trial","."]
code: def get_best_result(
      self,
      metric: Optional[str] = None,
      mode: Optional[str] = None,
      scope: str = "last",
      filter_nan_and_inf: bool = True,
  ) -> Result:
      """Get the best result from all the trials run.
  
      Args:
          metric: Key for trial info to order on. Defaults to
              the metric specified in your Tuner's ``TuneConfig``.
          mode: One of [min, max]. Defaults to the mode specified
              in your Tuner's ``TuneConfig``.
          scope: One of [all, last, avg, last-5-avg, last-10-avg].
              If `scope=last`, only look at each trial's final step for
              `metric`, and compare across trials based on `mode=[min,max]`.
              If `scope=avg`, consider the simple average over all steps
              for `metric` and compare across trials based on
              `mode=[min,max]`. If `scope=last-5-avg` or `scope=last-10-avg`,
              consider the simple average over the last 5 or 10 steps for
              `metric` and compare across trials based on `mode=[min,max]`.
              If `scope=all`, find each trial's min/max score for `metric`
              based on `mode`, and compare trials based on `mode=[min,max]`.
          filter_nan_and_inf: If True (default), NaN or infinite
              values are disregarded and these trials are never selected as
              the best trial.
      """
      if len(self._experiment_analysis.trials) == 1:
          return self._trial_to_result(
              self._experiment_analysis.trials[0]
          )
      if not metric and not self._experiment_analysis.default_metric:
          raise ValueError(
              "No metric is provided. Either pass in a `metric` arg to "
              "`get_best_result` or specify a metric in the "
              "`TuneConfig` of your `Tuner`."
          )
      if not mode and not self._experiment_analysis.default_mode:
          raise ValueError(
              "No mode is provided. Either pass in a `mode` arg to "
              "`get_best_result` or specify a mode in the "
              "`TuneConfig` of your `Tuner`."
          )
  
      best_trial = self._experiment_analysis.get_best_trial(
          metric=metric,
          mode=mode,
          scope=scope,
          filter_nan_and_inf=filter_nan_and_inf,
      )
      if not best_trial:
          error_msg = (
              "No best trial found for the given metric: "
              f"{metric or self._experiment_analysis.default_metric}. "
              "This means that no trial has reported this metric"
          )
          error_msg += (
              ", or all values reported for this metric are NaN. To not ignore NaN "
              "values, you can set the `filter_nan_and_inf` arg to False."
              if filter_nan_and_inf
              else "."
          )
          raise RuntimeError(error_msg)
  
      return self._trial_to_result(best_trial)
  
imports: import os
  import pandas
  import pyarrow
  from typing import Optional, Union
  from ray.air.result import Result
  from ray.cloudpickle import cloudpickle
  from ray.exceptions import RayTaskError
  from ray.tune.analysis import ExperimentAnalysis
  from ray.tune.error import TuneError
  from ray.tune.experiment import Trial
  from ray.util import PublicAPI
label_desc: Use image node_id 4 for calling the ResultGrid obj's underlying member method code with example usage: obj.get_best_result(metric, mode, scope, filter_nan_and_inf) and returns: self, self