code: def test_evalfactor_reraise():
      # This will produce a PatsyError, but buried inside the factor evaluation,
      # so the original code has no way to give it an appropriate origin=
      # attribute. EvalFactor should notice this, and add a useful origin:
      def raise_patsy_error(x):
          raise PatsyError("WHEEEEEE")
  
      formula = "raise_patsy_error(X) + Y"
      try:
          dmatrix(formula, {"X": [1, 2, 3], "Y": [4, 5, 6]})
      except PatsyError as e:
          assert e.origin == Origin(formula, 0, formula.index(" "))
      else:
          assert False
      # This will produce a KeyError, which on Python 3 we can do wrap without
      # destroying the traceback, so we do so. On Python 2 we let the original
      # exception escape.
      try:
          dmatrix("1 + x[1]", {"x": {}})
      except Exception as e:
          if sys.version_info[0] >= 3:
              assert isinstance(e, PatsyError)
              assert e.origin == Origin("1 + x[1]", 4, 8)
          else:
              assert isinstance(e, KeyError)
      else:
          assert False
  
imports: import sys
  import __future__
  import six
  import numpy
  import pytest
  from patsy import PatsyError
  from patsy.design_info import DesignMatrix, DesignInfo
  from patsy.eval import EvalEnvironment
  from patsy.desc import ModelDesc, Term, INTERCEPT
  from patsy.categorical import C
  from patsy.contrasts import Helmert
  from patsy.user_util import balanced, LookupFactor
  from patsy.build import design_matrix_builders, build_design_matrices
  from patsy.highlevel import *
  from patsy.util import have_pandas, have_pandas_categorical, have_pandas_categorical_dtype, pandas_Categorical_from_codes
  from patsy.origin import Origin
label_desc: Use image node_id 20 for calling a global function with example usage: test_evalfactor_reraise() without return types