# Buggy code
def _numpy_map_to_parfor(self, call_name, lhs, args, kws, expr):
    """generate parfor from Numpy calls that are maps."""
    scope = lhs.scope
    loc = lhs.loc
    arr_typ = self.typemap[lhs.name]
    el_typ = arr_typ.dtype

    # generate loopnests and size variables from lhs correlations
    loopnests = []
    size_vars = []
    index_vars = []
    for this_dim in range(arr_typ.ndim):
        corr = self.array_analysis.array_shape_classes[lhs.name][this_dim]
        size_var = self.array_analysis.array_size_vars[lhs.name][this_dim]
        size_vars.append(size_var)
        index_var = ir.Var(scope, mk_unique_var("parfor_index"), loc)
        index_vars.append(index_var)
        self.typemap[index_var.name] = types.intp
        loopnests.append(LoopNest(index_var, 0, size_var, 1, corr))

    # generate init block and body
    init_block = ir.Block(scope, loc)
    init_block.body = mk_alloc(
        self.typemap, self.calltypes, lhs, tuple(size_vars), el_typ, scope, loc
    )
    body_label = next_label()
    body_block = ir.Block(scope, loc)
    expr_out_var = ir.Var(scope, mk_unique_var("$expr_out_var"), loc)
    self.typemap[expr_out_var.name] = el_typ

    index_var, index_var_typ = self._make_index_var(scope, index_vars, body_block)

    if call_name == "zeros":
        value = ir.Const(0, loc)
    elif call_name == "ones":
        value = ir.Const(1, loc)
    elif call_name == "random.ranf":
        # reuse the call expr for single value
        expr.args = []
        self.calltypes.pop(expr)
        self.calltypes[expr] = self.typemap[expr.func.name].get_call_type(
            typing.Context(), [], {}
        )
        value = expr
    else:
        NotImplementedError(
            "Map of numpy.{} to parfor is not implemented".format(call_name)
        )

    value_assign = ir.Assign(value, expr_out_var, loc)
    body_block.body.append(value_assign)

    parfor = Parfor(loopnests, init_block, {}, loc, self.array_analysis, index_var)

    setitem_node = ir.SetItem(lhs, index_var, expr_out_var, loc)
    self.calltypes[setitem_node] = signature(
        types.none, self.typemap[lhs.name], index_var_typ, el_typ
    )
    body_block.body.append(setitem_node)
    parfor.loop_body = {body_label: body_block}
    if config.DEBUG_ARRAY_OPT == 1:
        print("generated parfor for numpy map:")
        parfor.dump()
    return parfor


# Traceback (TypeError)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-15-3b23f7331ceb> in <module>()
----> 1 @jit(arg_types=[numba.double], ret_type=numba.double)
2 def is_REALLY_five(some_value):
3     for i in range(5):
4         if some_value == 5.0:
5             return 1.0

/Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/site-packages/numba/decorators.pyc in _jit(func)
77                   "garbage collected!" % (func,))
78         t = Translate(func, *args, **kws)
---> 79         t.translate()
80         __tr_map__[func] = t
81         return t.get_ctypes_func(llvm)

/Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/site-packages/numba/translate.pyc in translate(self)
926                     # Ensure we are playing with locals that might
927                     # actually precede the next block.
--> 928                     self.check_locals(i)
929
930                 self.crnt_block = i

/Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/site-packages/numba/translate.pyc in check_locals(self, i)
1135                 else:
1136                     assert next_locals is not None, "Internal compiler error!"
-> 1137             self._locals = next_locals[:]
1138
1139     def get_ctypes_func(self, llvm=True):

TypeError: 'NoneType' object has no attribute '__getitem__'

# Fixed code
def _numpy_map_to_parfor(self, call_name, lhs, args, kws, expr):
    """generate parfor from Numpy calls that are maps."""
    scope = lhs.scope
    loc = lhs.loc
    arr_typ = self.typemap[lhs.name]
    el_typ = arr_typ.dtype

    # generate loopnests and size variables from lhs correlations
    loopnests = []
    size_vars = []
    index_vars = []
    for this_dim in range(arr_typ.ndim):
        corr = self.array_analysis.array_shape_classes[lhs.name][this_dim]
        size_var = self.array_analysis.array_size_vars[lhs.name][this_dim]
        size_vars.append(size_var)
        index_var = ir.Var(scope, mk_unique_var("parfor_index"), loc)
        index_vars.append(index_var)
        self.typemap[index_var.name] = types.intp
        loopnests.append(LoopNest(index_var, 0, size_var, 1, corr))

    # generate init block and body
    init_block = ir.Block(scope, loc)
    init_block.body = mk_alloc(
        self.typemap, self.calltypes, lhs, tuple(size_vars), el_typ, scope, loc
    )
    body_label = next_label()
    body_block = ir.Block(scope, loc)
    expr_out_var = ir.Var(scope, mk_unique_var("$expr_out_var"), loc)
    self.typemap[expr_out_var.name] = el_typ

    index_var, index_var_typ = self._make_index_var(scope, index_vars, body_block)

    if call_name == "zeros":
        value = ir.Const(0, loc)
    elif call_name == "ones":
        value = ir.Const(1, loc)
    elif call_name.startswith("random."):
        # remove size arg to reuse the call expr for single value
        _remove_size_arg(call_name, expr)
        # update expr type
        new_arg_typs, new_kw_types = _get_call_arg_types(expr, self.typemap)
        self.calltypes.pop(expr)
        self.calltypes[expr] = self.typemap[expr.func.name].get_call_type(
            typing.Context(), new_arg_typs, new_kw_types
        )
        value = expr
    else:
        NotImplementedError(
            "Map of numpy.{} to parfor is not implemented".format(call_name)
        )

    value_assign = ir.Assign(value, expr_out_var, loc)
    body_block.body.append(value_assign)

    parfor = Parfor(loopnests, init_block, {}, loc, self.array_analysis, index_var)

    setitem_node = ir.SetItem(lhs, index_var, expr_out_var, loc)
    self.calltypes[setitem_node] = signature(
        types.none, self.typemap[lhs.name], index_var_typ, el_typ
    )
    body_block.body.append(setitem_node)
    parfor.loop_body = {body_label: body_block}
    if config.DEBUG_ARRAY_OPT == 1:
        print("generated parfor for numpy map:")
        parfor.dump()
    return parfor