# Buggy code
def _create_shape_signature(
    get_shape_classes, num_inputs, num_reductions, args, func_sig, races
):
    """Create shape signature for GUFunc"""
    if config.DEBUG_ARRAY_OPT:
        print("_create_shape_signature", num_inputs, num_reductions, args, func_sig)
        for i in args[1:]:
            print("argument", i, type(i), get_shape_classes(i))

    num_inouts = len(args) - num_reductions
    # maximum class number for array shapes
    classes = [
        get_shape_classes(var) if var not in races else (-1,) for var in args[1:]
    ]
    class_set = set()
    for _class in classes:
        if _class:
            for i in _class:
                class_set.add(i)
    max_class = max(class_set) + 1 if class_set else 0
    classes.insert(0, (max_class,))  # force set the class of 'sched' argument
    class_set.add(max_class)
    class_map = {}
    # TODO: use prefix + class number instead of single char
    alphabet = ord("a")
    for n in class_set:
        if n >= 0:
            class_map[n] = chr(alphabet)
            alphabet += 1

    alpha_dict = {"latest_alpha": alphabet}

    def bump_alpha(c, class_map):
        if c >= 0:
            return class_map[c]
        else:
            alpha_dict["latest_alpha"] += 1
            return chr(alpha_dict["latest_alpha"])

    gu_sin = []
    gu_sout = []
    count = 0
    syms_sin = ()
    for cls in classes:
        # print("create_shape_signature: var = ", var, " typ = ", typ)
        count = count + 1
        if cls:
            dim_syms = tuple(bump_alpha(c, class_map) for c in cls)
        else:
            dim_syms = ()
        if count > num_inouts:
            # assume all reduction vars are scalar
            gu_sout.append(())
        elif count > num_inputs and all([s in syms_sin for s in dim_syms]):
            # only when dim_syms are found in gu_sin, we consider this as
            # output
            gu_sout.append(dim_syms)
        else:
            gu_sin.append(dim_syms)
            syms_sin += dim_syms
    return (gu_sin, gu_sout)


# Traceback (TypeError)
Traceback (most recent call last):
File "C:\Users\kittoku\Anaconda3\envs\test_env\lib\site-packages\numba\errors.py", line 491, in new_error_context
yield
File "C:\Users\kittoku\Anaconda3\envs\test_env\lib\site-packages\numba\lowering.py", line 216, in lower_block
self.lower_inst(inst)
File "C:\Users\kittoku\Anaconda3\envs\test_env\lib\site-packages\numba\lowering.py", line 365, in lower_inst
func(self, inst)
File "C:\Users\kittoku\Anaconda3\envs\test_env\lib\site-packages\numba\npyufunc\parfor.py", line 83, in _lower_parfor_parallel
bool(alias_map), index_var_typ)
File "C:\Users\kittoku\Anaconda3\envs\test_env\lib\site-packages\numba\npyufunc\parfor.py", line 357, in _create_gufunc_for_parfor_body
typemap[arr] = types.npytypes.Array(typemap[var], 1, "C")
File "C:\Users\kittoku\Anaconda3\envs\test_env\lib\site-packages\numba\types\abstract.py", line 60, in __call__
inst = type.__call__(cls, *args, **kwargs)
File "C:\Users\kittoku\Anaconda3\envs\test_env\lib\site-packages\numba\types\npytypes.py", line 288, in __init__
super(Array, self).__init__(dtype, ndim, layout, name=name)
File "C:\Users\kittoku\Anaconda3\envs\test_env\lib\site-packages\numba\types\common.py", line 51, in __init__
raise TypeError("Buffer dtype cannot be buffer")
TypeError: Buffer dtype cannot be buffer

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\kittoku\Anaconda3\envs\test_env\lib\site-packages\numba\dispatcher.py", line 360, in _compile_for_args
raise e
File "C:\Users\kittoku\Anaconda3\envs\test_env\lib\site-packages\numba\dispatcher.py", line 311, in _compile_for_args
return self.compile(tuple(argtypes))
File "C:\Users\kittoku\Anaconda3\envs\test_env\lib\site-packages\numba\dispatcher.py", line 618, in compile
cres = self._compiler.compile(args, return_type)
File "C:\Users\kittoku\Anaconda3\envs\test_env\lib\site-packages\numba\dispatcher.py", line 83, in compile
pipeline_class=self.pipeline_class)
File "C:\Users\kittoku\Anaconda3\envs\test_env\lib\site-packages\numba\compiler.py", line 871, in compile_extra
return pipeline.compile_extra(func)
File "C:\Users\kittoku\Anaconda3\envs\test_env\lib\site-packages\numba\compiler.py", line 365, in compile_extra
return self._compile_bytecode()
File "C:\Users\kittoku\Anaconda3\envs\test_env\lib\site-packages\numba\compiler.py", line 802, in _compile_bytecode
return self._compile_core()
File "C:\Users\kittoku\Anaconda3\envs\test_env\lib\site-packages\numba\compiler.py", line 789, in _compile_core
res = pm.run(self.status)
File "C:\Users\kittoku\Anaconda3\envs\test_env\lib\site-packages\numba\compiler.py", line 251, in run
raise patched_exception
File "C:\Users\kittoku\Anaconda3\envs\test_env\lib\site-packages\numba\compiler.py", line 243, in run
stage()
File "C:\Users\kittoku\Anaconda3\envs\test_env\lib\site-packages\numba\compiler.py", line 676, in stage_nopython_backend
self._backend(lowerfn, objectmode=False)
File "C:\Users\kittoku\Anaconda3\envs\test_env\lib\site-packages\numba\compiler.py", line 626, in _backend
lowered = lowerfn()
File "C:\Users\kittoku\Anaconda3\envs\test_env\lib\site-packages\numba\compiler.py", line 613, in backend_nopython_mode
self.flags)
File "C:\Users\kittoku\Anaconda3\envs\test_env\lib\site-packages\numba\compiler.py", line 990, in native_lowering_stage
lower.lower()
File "C:\Users\kittoku\Anaconda3\envs\test_env\lib\site-packages\numba\lowering.py", line 135, in lower
self.lower_normal_function(self.fndesc)
File "C:\Users\kittoku\Anaconda3\envs\test_env\lib\site-packages\numba\lowering.py", line 176, in lower_normal_function
entry_block_tail = self.lower_function_body()
File "C:\Users\kittoku\Anaconda3\envs\test_env\lib\site-packages\numba\lowering.py", line 201, in lower_function_body
self.lower_block(block)
File "C:\Users\kittoku\Anaconda3\envs\test_env\lib\site-packages\numba\lowering.py", line 216, in lower_block
self.lower_inst(inst)
File "C:\Users\kittoku\Anaconda3\envs\test_env\lib\contextlib.py", line 99, in __exit__
self.gen.throw(type, value, traceback)
File "C:\Users\kittoku\Anaconda3\envs\test_env\lib\site-packages\numba\errors.py", line 499, in new_error_context
six.reraise(type(newerr), newerr, tb)
File "C:\Users\kittoku\Anaconda3\envs\test_env\lib\site-packages\numba\six.py", line 659, in reraise
raise value
numba.errors.LoweringError: Failed at nopython (nopython mode backend)
Buffer dtype cannot be buffer

File "<stdin>", line 5:

[1] During: lowering "id=6[LoopNest(index_variable = parfor_index.271, range = (0, $16.3, 1))]{28: <ir.Block at <stdin> (5)>}Var(parfor_index.271, <stdin> (5))" at <stdin> (5)
-------------------------------------------------------------------------------
This should not have happened, a problem has occurred in Numba's internals.

Please report the error message and traceback, along with a minimal reproducer
at: https://github.com/numba/numba/issues/new

If you need help writing a minimal reproducer please see:
http://matthewrocklin.com/blog/work/2018/02/28/minimal-bug-reports

If more help is needed please feel free to speak to the Numba core developers
directly at: https://gitter.im/numba/numba

Thanks in advance for your help in improving Numba!

# Fixed code
def _create_shape_signature(
    get_shape_classes,
    num_inputs,
    num_reductions,
    args,
    redargstartdim,
    func_sig,
    races,
    typemap,
):
    """Create shape signature for GUFunc"""
    if config.DEBUG_ARRAY_OPT:
        print(
            "_create_shape_signature", num_inputs, num_reductions, args, redargstartdim
        )
        for i in args[1:]:
            print("argument", i, type(i), get_shape_classes(i, typemap=typemap))

    num_inouts = len(args) - num_reductions
    # maximum class number for array shapes
    classes = [
        get_shape_classes(var, typemap=typemap) if var not in races else (-1,)
        for var in args[1:]
    ]
    class_set = set()
    for _class in classes:
        if _class:
            for i in _class:
                class_set.add(i)
    max_class = max(class_set) + 1 if class_set else 0
    classes.insert(0, (max_class,))  # force set the class of 'sched' argument
    class_set.add(max_class)
    class_map = {}
    # TODO: use prefix + class number instead of single char
    alphabet = ord("a")
    for n in class_set:
        if n >= 0:
            class_map[n] = chr(alphabet)
            alphabet += 1

    alpha_dict = {"latest_alpha": alphabet}

    def bump_alpha(c, class_map):
        if c >= 0:
            return class_map[c]
        else:
            alpha_dict["latest_alpha"] += 1
            return chr(alpha_dict["latest_alpha"])

    gu_sin = []
    gu_sout = []
    count = 0
    syms_sin = ()
    if config.DEBUG_ARRAY_OPT:
        print("args", args)
        print("classes", classes)
    for cls, arg in zip(classes, args):
        count = count + 1
        if cls:
            dim_syms = tuple(bump_alpha(c, class_map) for c in cls)
        else:
            dim_syms = ()
        if count > num_inouts:
            # Strip the first symbol corresponding to the number of workers
            # so that guvectorize will parallelize across the reduction.
            gu_sin.append(dim_syms[redargstartdim[arg] :])
        else:
            gu_sin.append(dim_syms)
            syms_sin += dim_syms
    return (gu_sin, gu_sout)