docstr: Piecewise function printer
docstr_tok: ["Piecewise","function","printer"]
code: def _print_Piecewise(self, expr):
      "Piecewise function printer"
      exprs = [self._print(arg.expr) for arg in expr.args]
      conds = [self._print(arg.cond) for arg in expr.args]
      # If [default_value, True] is a (expr, cond) sequence in a Piecewise object
      #     it will behave the same as passing the 'default' kwarg to select()
      #     *as long as* it is the last element in expr.args.
      # If this is not the case, it may be triggered prematurely.
      ans = []
      parenthesis_count = 0
      is_last_cond_True = False
      for cond, expr in zip(conds, exprs):
          if cond == "True":
              ans.append(expr)
              is_last_cond_True = True
              break
          else:
              ans.append("where(%s, %s, " % (cond, expr))
              parenthesis_count += 1
      if not is_last_cond_True:
          # See https://github.com/pydata/numexpr/issues/298
          #
          # simplest way to put a nan but raises
          # 'RuntimeWarning: invalid value encountered in log'
          #
          # There are other ways to do this such as
          #
          #   >>> import numexpr as ne
          #   >>> nan = float('nan')
          #   >>> ne.evaluate('where(x < 0, -1, nan)', {'x': [-1, 2, 3], 'nan':nan})
          #   array([-1., nan, nan])
          #
          # That needs to be handled in the lambdified function though rather
          # than here in the printer.
          ans.append("log(-1)")
      return "".join(ans) + ")" * parenthesis_count
  
imports: from .pycode import PythonCodePrinter, MpmathPrinter
  from .numpy import NumPyPrinter
  from sympy.core.sorting import default_sort_key
label_desc: Use image node_id 4 for calling the NumExprPrinter obj's underlying member method code with example usage: obj._print_Piecewise(expr) and returns: unknown