docstr: Here we *ASSUME* that the whole dataset contains at least one non-empty step
  Otherwise it will go into infinite loop looking for the one
docstr_tok: ["Here","we","*","ASSUME","*","that","the","whole","dataset","contains","at","least","one","non-empty","step","Otherwise","it","will","go","into","infinite","loop","looking","for","the","one"]
code: def _find_nonempty_random_step(self, dataset: List[str]) -> str:
      """Here we *ASSUME* that the whole dataset contains at least one non-empty step
      Otherwise it will go into infinite loop looking for the one
      """
      # what we call an empty step
      empty_steps = ["", " "]
      # first find chain with at least one non-empty step
      rand_steps = self._clean_steps(
          self.math_random.choice(dataset)["solution"]
      ).split(". ")
      # make sure this chain has at least one non-empty step
      i = 0
      while i < len(rand_steps) and rand_steps[i] in empty_steps:
          i += 1
      # if it doesn't, try again
      if i == len(rand_steps):
          return self._find_nonempty_random_step(dataset)
      random_step = empty_steps[0]
      # find non-empty random step (and we know it exists in this chain)
      while random_step in empty_steps:
          random_step = self.math_random.choice(rand_steps)
      return random_step
  
imports: import glob
  import json
  import os
  import random
  import re
  from parlai.tasks.math_dataset.build import build
  from parlai.core.opt import Opt
  from parlai.core.params import ParlaiParser
  from parlai.utils.io import PathManager
  from typing import List, Optional
  from parlai.tasks.reasoning.agents import MWPStepsReasoningTeacher
label_desc: Use image node_id 7 for calling the MathDatasetStepByStepReasoningTeacher obj's underlying member method code with example usage: obj._find_nonempty_random_step(dataset) and returns: random_step, self