code: def _get_best_intermediate_result_over_steps(
      trial: "optuna.trial.FrozenTrial", direction: StudyDirection
  ) -> float:
      values = np.asarray(
          list(trial.intermediate_values.values()), dtype=float
      )
      if direction == StudyDirection.MAXIMIZE:
          return np.nanmax(values)
      return np.nanmin(values)
  
file_path: optuna/optuna/pruners/_percentile.py
imports: import functools
  import math
  from typing import KeysView
  from typing import List
  import numpy
  import optuna
  from optuna.pruners import BasePruner
  from optuna.study._study_direction import StudyDirection
  from optuna.trial._state import TrialState
label_desc: Use image node_id 1 for calling a global function with example usage: _get_best_intermediate_result_over_steps(trial, direction) and returns: np, np