class_docstr: Pruner to detect outlying metrics of the trials.
  
  Prune if a metric exceeds upper threshold,
  falls behind lower threshold or reaches ``nan``.
  
  Example:
      .. testcode::
  
          from optuna import create_study
          from optuna.pruners import ThresholdPruner
          from optuna import TrialPruned
  
  
          def objective_for_upper(trial):
              for step, y in enumerate(ys_for_upper):
                  trial.report(y, step)
  
                  if trial.should_prune():
                      raise TrialPruned()
              return ys_for_upper[-1]
  
  
          def objective_for_lower(trial):
              for step, y in enumerate(ys_for_lower):
                  trial.report(y, step)
  
                  if trial.should_prune():
                      raise TrialPruned()
              return ys_for_lower[-1]
  
  
          ys_for_upper = [0.0, 0.1, 0.2, 0.5, 1.2]
          ys_for_lower = [100.0, 90.0, 0.1, 0.0, -1]
  
          study = create_study(pruner=ThresholdPruner(upper=1.0))
          study.optimize(objective_for_upper, n_trials=10)
  
          study = create_study(pruner=ThresholdPruner(lower=0.0))
          study.optimize(objective_for_lower, n_trials=10)
  
  Args:
      lower:
          A minimum value which determines whether pruner prunes or not.
          If an intermediate value is smaller than lower, it prunes.
      upper:
          A maximum value which determines whether pruner prunes or not.
          If an intermediate value is larger than upper, it prunes.
      n_warmup_steps:
          Pruning is disabled if the step is less than the given number of warmup steps.
      interval_steps:
          Interval in number of steps between the pruning checks, offset by the warmup steps.
          If no value has been reported at the time of a pruning check, that particular check
          will be postponed until a value is reported. Value must be at least 1.
code: def prune(
      self,
      study: "optuna.study.Study",
      trial: "optuna.trial.FrozenTrial",
  ) -> bool:
      step = trial.last_step
      if step is None:
          return False
  
      n_warmup_steps = self._n_warmup_steps
      if step < n_warmup_steps:
          return False
  
      if not _is_first_in_interval_step(
          step,
          trial.intermediate_values.keys(),
          n_warmup_steps,
          self._interval_steps,
      ):
          return False
  
      latest_value = trial.intermediate_values[step]
      if math.isnan(latest_value):
          return True
  
      if latest_value < self._lower:
          return True
  
      if latest_value > self._upper:
          return True
  
      return False
  
file_path: optuna/optuna/pruners/_threshold.py
imports: import math
  from typing import Any
  from typing import Optional
  import optuna
  from optuna.pruners import BasePruner
  from optuna.pruners._percentile import _is_first_in_interval_step
label_desc: Use image node_id 2 for calling the ThresholdPruner obj's underlying member method code with example usage: obj.prune(study, trial) and returns: False, False, False, False, True, True, True