gurudesh/pytracebugs huggingface dataset:
# Buggy code
def _make_list(itemty, allocated=0):
    return listobject._as_meminfo(listobject.new_list(itemty, allocated=allocated))


# Traceback (numba.errors.TypingError)
======================================================================
ERROR: test_numba_typed_list_allocated (sdc.tests.test_series.TestSeries)
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\Users\akozlov\AppData\Local\Continuum\anaconda3\hpat\sdc\tests\test_series.py
", line 6817, in test_numba_typed_list_allocated
print(jitted())
File "c:\users\akozlov\appdata\local\continuum\anaconda3\numba_master\numba\numba\disp
atcher.py", line 401, in _compile_for_args
error_rewrite(e, 'typing')
File "c:\users\akozlov\appdata\local\continuum\anaconda3\numba_master\numba\numba\disp
atcher.py", line 344, in error_rewrite
reraise(type(e), e, None)
File "c:\users\akozlov\appdata\local\continuum\anaconda3\numba_master\numba\numba\six.
py", line 668, in reraise
raise value.with_traceback(tb)
numba.errors.TypingError: Failed in nopython mode pipeline (step: nopython frontend)
Invalid use of Function(<function typedlist_empty at 0x0000015A9C481550>) with argument(
s) of type(s): (typeref[<class 'numba.types.containers.ListType'>], class(int64), int64)

* parameterized
In definition 0:
TypeError: typedlist_empty() takes 2 positional arguments but 3 were given
raised from c:\users\akozlov\appdata\local\continuum\anaconda3\numba_master\numba\nu
mba\typing\templates.py:539
In definition 1:
TypeError: typedlist_empty() takes 2 positional arguments but 3 were given
raised from c:\users\akozlov\appdata\local\continuum\anaconda3\numba_master\numba\nu
mba\typing\templates.py:539
This error is usually caused by passing an argument of a type that is unsupported by the
named function.
[1] During: resolving callee type: BoundFunction((<class 'numba.types.abstract.TypeRef'>
, 'empty_list') for typeref[<class 'numba.types.containers.ListType'>])
[2] During: typing of call at C:\Users\akozlov\AppData\Local\Continuum\anaconda3\hpat\sd
c\tests\test_series.py (6813)


File "sdc\tests\test_series.py", line 6813:
def test_impl():
<source elided>
# problem in overload of empty_list in typedlist.py
alloc_list = List.empty_list(types.int64, 10)
^


----------------------------------------------------------------------
Ran 1 test in 0.075s

FAILED (errors=1)

# Fixed code
def _make_list(itemty, allocated=DEFAULT_ALLOCATED):
    return listobject._as_meminfo(listobject.new_list(itemty, allocated=allocated))
# Buggy code
def _allocated(self):
    if not self._typed:
        return 0
    else:
        return _allocated(self)


# Traceback (numba.errors.TypingError)
======================================================================
ERROR: test_numba_typed_list_allocated (sdc.tests.test_series.TestSeries)
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\Users\akozlov\AppData\Local\Continuum\anaconda3\hpat\sdc\tests\test_series.py
", line 6817, in test_numba_typed_list_allocated
print(jitted())
File "c:\users\akozlov\appdata\local\continuum\anaconda3\numba_master\numba\numba\disp
atcher.py", line 401, in _compile_for_args
error_rewrite(e, 'typing')
File "c:\users\akozlov\appdata\local\continuum\anaconda3\numba_master\numba\numba\disp
atcher.py", line 344, in error_rewrite
reraise(type(e), e, None)
File "c:\users\akozlov\appdata\local\continuum\anaconda3\numba_master\numba\numba\six.
py", line 668, in reraise
raise value.with_traceback(tb)
numba.errors.TypingError: Failed in nopython mode pipeline (step: nopython frontend)
Invalid use of Function(<function typedlist_empty at 0x0000015A9C481550>) with argument(
s) of type(s): (typeref[<class 'numba.types.containers.ListType'>], class(int64), int64)

* parameterized
In definition 0:
TypeError: typedlist_empty() takes 2 positional arguments but 3 were given
raised from c:\users\akozlov\appdata\local\continuum\anaconda3\numba_master\numba\nu
mba\typing\templates.py:539
In definition 1:
TypeError: typedlist_empty() takes 2 positional arguments but 3 were given
raised from c:\users\akozlov\appdata\local\continuum\anaconda3\numba_master\numba\nu
mba\typing\templates.py:539
This error is usually caused by passing an argument of a type that is unsupported by the
named function.
[1] During: resolving callee type: BoundFunction((<class 'numba.types.abstract.TypeRef'>
, 'empty_list') for typeref[<class 'numba.types.containers.ListType'>])
[2] During: typing of call at C:\Users\akozlov\AppData\Local\Continuum\anaconda3\hpat\sd
c\tests\test_series.py (6813)


File "sdc\tests\test_series.py", line 6813:
def test_impl():
<source elided>
# problem in overload of empty_list in typedlist.py
alloc_list = List.empty_list(types.int64, 10)
^


----------------------------------------------------------------------
Ran 1 test in 0.075s

FAILED (errors=1)

# Fixed code
def _allocated(self):
    if not self._typed:
        return DEFAULT_ALLOCATED
    else:
        return _allocated(self)
# Buggy code
def __new__(cls, lsttype=None, meminfo=None, allocated=None):
    if config.DISABLE_JIT:
        return list.__new__(list)
    else:
        return object.__new__(cls)


# Traceback (numba.errors.TypingError)
======================================================================
ERROR: test_numba_typed_list_allocated (sdc.tests.test_series.TestSeries)
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\Users\akozlov\AppData\Local\Continuum\anaconda3\hpat\sdc\tests\test_series.py
", line 6817, in test_numba_typed_list_allocated
print(jitted())
File "c:\users\akozlov\appdata\local\continuum\anaconda3\numba_master\numba\numba\disp
atcher.py", line 401, in _compile_for_args
error_rewrite(e, 'typing')
File "c:\users\akozlov\appdata\local\continuum\anaconda3\numba_master\numba\numba\disp
atcher.py", line 344, in error_rewrite
reraise(type(e), e, None)
File "c:\users\akozlov\appdata\local\continuum\anaconda3\numba_master\numba\numba\six.
py", line 668, in reraise
raise value.with_traceback(tb)
numba.errors.TypingError: Failed in nopython mode pipeline (step: nopython frontend)
Invalid use of Function(<function typedlist_empty at 0x0000015A9C481550>) with argument(
s) of type(s): (typeref[<class 'numba.types.containers.ListType'>], class(int64), int64)

* parameterized
In definition 0:
TypeError: typedlist_empty() takes 2 positional arguments but 3 were given
raised from c:\users\akozlov\appdata\local\continuum\anaconda3\numba_master\numba\nu
mba\typing\templates.py:539
In definition 1:
TypeError: typedlist_empty() takes 2 positional arguments but 3 were given
raised from c:\users\akozlov\appdata\local\continuum\anaconda3\numba_master\numba\nu
mba\typing\templates.py:539
This error is usually caused by passing an argument of a type that is unsupported by the
named function.
[1] During: resolving callee type: BoundFunction((<class 'numba.types.abstract.TypeRef'>
, 'empty_list') for typeref[<class 'numba.types.containers.ListType'>])
[2] During: typing of call at C:\Users\akozlov\AppData\Local\Continuum\anaconda3\hpat\sd
c\tests\test_series.py (6813)


File "sdc\tests\test_series.py", line 6813:
def test_impl():
<source elided>
# problem in overload of empty_list in typedlist.py
alloc_list = List.empty_list(types.int64, 10)
^


----------------------------------------------------------------------
Ran 1 test in 0.075s

FAILED (errors=1)

# Fixed code
def __new__(cls, lsttype=None, meminfo=None, allocated=DEFAULT_ALLOCATED):
    if config.DISABLE_JIT:
        return list.__new__(list)
    else:
        return object.__new__(cls)
# Buggy code
def empty_list(cls, item_type, allocated=0):
    """Create a new empty List.

    Parameters
    ----------
    item_type: Numba type
        type of the list item.
    allocated: int
        number of items to pre-allocate
    """
    if config.DISABLE_JIT:
        return list()
    else:
        return cls(lsttype=ListType(item_type), allocated=allocated)


# Traceback (numba.errors.TypingError)
======================================================================
ERROR: test_numba_typed_list_allocated (sdc.tests.test_series.TestSeries)
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\Users\akozlov\AppData\Local\Continuum\anaconda3\hpat\sdc\tests\test_series.py
", line 6817, in test_numba_typed_list_allocated
print(jitted())
File "c:\users\akozlov\appdata\local\continuum\anaconda3\numba_master\numba\numba\disp
atcher.py", line 401, in _compile_for_args
error_rewrite(e, 'typing')
File "c:\users\akozlov\appdata\local\continuum\anaconda3\numba_master\numba\numba\disp
atcher.py", line 344, in error_rewrite
reraise(type(e), e, None)
File "c:\users\akozlov\appdata\local\continuum\anaconda3\numba_master\numba\numba\six.
py", line 668, in reraise
raise value.with_traceback(tb)
numba.errors.TypingError: Failed in nopython mode pipeline (step: nopython frontend)
Invalid use of Function(<function typedlist_empty at 0x0000015A9C481550>) with argument(
s) of type(s): (typeref[<class 'numba.types.containers.ListType'>], class(int64), int64)

* parameterized
In definition 0:
TypeError: typedlist_empty() takes 2 positional arguments but 3 were given
raised from c:\users\akozlov\appdata\local\continuum\anaconda3\numba_master\numba\nu
mba\typing\templates.py:539
In definition 1:
TypeError: typedlist_empty() takes 2 positional arguments but 3 were given
raised from c:\users\akozlov\appdata\local\continuum\anaconda3\numba_master\numba\nu
mba\typing\templates.py:539
This error is usually caused by passing an argument of a type that is unsupported by the
named function.
[1] During: resolving callee type: BoundFunction((<class 'numba.types.abstract.TypeRef'>
, 'empty_list') for typeref[<class 'numba.types.containers.ListType'>])
[2] During: typing of call at C:\Users\akozlov\AppData\Local\Continuum\anaconda3\hpat\sd
c\tests\test_series.py (6813)


File "sdc\tests\test_series.py", line 6813:
def test_impl():
<source elided>
# problem in overload of empty_list in typedlist.py
alloc_list = List.empty_list(types.int64, 10)
^


----------------------------------------------------------------------
Ran 1 test in 0.075s

FAILED (errors=1)

# Fixed code
def empty_list(cls, item_type, allocated=DEFAULT_ALLOCATED):
    """Create a new empty List.

    Parameters
    ----------
    item_type: Numba type
        type of the list item.
    allocated: int
        number of items to pre-allocate
    """
    if config.DISABLE_JIT:
        return list()
    else:
        return cls(lsttype=ListType(item_type), allocated=allocated)
# Buggy code
def _parse_arg(self, lsttype, meminfo=None, allocated=0):
    if not isinstance(lsttype, ListType):
        raise TypeError("*lsttype* must be a ListType")

    if meminfo is not None:
        opaque = meminfo
    else:
        opaque = _make_list(lsttype.item_type, allocated=allocated)
    return lsttype, opaque


# Traceback (numba.errors.TypingError)
======================================================================
ERROR: test_numba_typed_list_allocated (sdc.tests.test_series.TestSeries)
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\Users\akozlov\AppData\Local\Continuum\anaconda3\hpat\sdc\tests\test_series.py
", line 6817, in test_numba_typed_list_allocated
print(jitted())
File "c:\users\akozlov\appdata\local\continuum\anaconda3\numba_master\numba\numba\disp
atcher.py", line 401, in _compile_for_args
error_rewrite(e, 'typing')
File "c:\users\akozlov\appdata\local\continuum\anaconda3\numba_master\numba\numba\disp
atcher.py", line 344, in error_rewrite
reraise(type(e), e, None)
File "c:\users\akozlov\appdata\local\continuum\anaconda3\numba_master\numba\numba\six.
py", line 668, in reraise
raise value.with_traceback(tb)
numba.errors.TypingError: Failed in nopython mode pipeline (step: nopython frontend)
Invalid use of Function(<function typedlist_empty at 0x0000015A9C481550>) with argument(
s) of type(s): (typeref[<class 'numba.types.containers.ListType'>], class(int64), int64)

* parameterized
In definition 0:
TypeError: typedlist_empty() takes 2 positional arguments but 3 were given
raised from c:\users\akozlov\appdata\local\continuum\anaconda3\numba_master\numba\nu
mba\typing\templates.py:539
In definition 1:
TypeError: typedlist_empty() takes 2 positional arguments but 3 were given
raised from c:\users\akozlov\appdata\local\continuum\anaconda3\numba_master\numba\nu
mba\typing\templates.py:539
This error is usually caused by passing an argument of a type that is unsupported by the
named function.
[1] During: resolving callee type: BoundFunction((<class 'numba.types.abstract.TypeRef'>
, 'empty_list') for typeref[<class 'numba.types.containers.ListType'>])
[2] During: typing of call at C:\Users\akozlov\AppData\Local\Continuum\anaconda3\hpat\sd
c\tests\test_series.py (6813)


File "sdc\tests\test_series.py", line 6813:
def test_impl():
<source elided>
# problem in overload of empty_list in typedlist.py
alloc_list = List.empty_list(types.int64, 10)
^


----------------------------------------------------------------------
Ran 1 test in 0.075s

FAILED (errors=1)

# Fixed code
def _parse_arg(self, lsttype, meminfo=None, allocated=DEFAULT_ALLOCATED):
    if not isinstance(lsttype, ListType):
        raise TypeError("*lsttype* must be a ListType")

    if meminfo is not None:
        opaque = meminfo
    else:
        opaque = _make_list(lsttype.item_type, allocated=allocated)
    return lsttype, opaque
# Buggy code
def typedlist_empty(cls, item_type):
    if cls.instance_type is not ListType:
        return

    def impl(cls, item_type):
        return listobject.new_list(item_type)

    return impl


# Traceback (numba.errors.TypingError)
======================================================================
ERROR: test_numba_typed_list_allocated (sdc.tests.test_series.TestSeries)
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\Users\akozlov\AppData\Local\Continuum\anaconda3\hpat\sdc\tests\test_series.py
", line 6817, in test_numba_typed_list_allocated
print(jitted())
File "c:\users\akozlov\appdata\local\continuum\anaconda3\numba_master\numba\numba\disp
atcher.py", line 401, in _compile_for_args
error_rewrite(e, 'typing')
File "c:\users\akozlov\appdata\local\continuum\anaconda3\numba_master\numba\numba\disp
atcher.py", line 344, in error_rewrite
reraise(type(e), e, None)
File "c:\users\akozlov\appdata\local\continuum\anaconda3\numba_master\numba\numba\six.
py", line 668, in reraise
raise value.with_traceback(tb)
numba.errors.TypingError: Failed in nopython mode pipeline (step: nopython frontend)
Invalid use of Function(<function typedlist_empty at 0x0000015A9C481550>) with argument(
s) of type(s): (typeref[<class 'numba.types.containers.ListType'>], class(int64), int64)

* parameterized
In definition 0:
TypeError: typedlist_empty() takes 2 positional arguments but 3 were given
raised from c:\users\akozlov\appdata\local\continuum\anaconda3\numba_master\numba\nu
mba\typing\templates.py:539
In definition 1:
TypeError: typedlist_empty() takes 2 positional arguments but 3 were given
raised from c:\users\akozlov\appdata\local\continuum\anaconda3\numba_master\numba\nu
mba\typing\templates.py:539
This error is usually caused by passing an argument of a type that is unsupported by the
named function.
[1] During: resolving callee type: BoundFunction((<class 'numba.types.abstract.TypeRef'>
, 'empty_list') for typeref[<class 'numba.types.containers.ListType'>])
[2] During: typing of call at C:\Users\akozlov\AppData\Local\Continuum\anaconda3\hpat\sd
c\tests\test_series.py (6813)


File "sdc\tests\test_series.py", line 6813:
def test_impl():
<source elided>
# problem in overload of empty_list in typedlist.py
alloc_list = List.empty_list(types.int64, 10)
^


----------------------------------------------------------------------
Ran 1 test in 0.075s

FAILED (errors=1)

# Fixed code
def typedlist_empty(cls, item_type, allocated=DEFAULT_ALLOCATED):
    if cls.instance_type is not ListType:
        return

    def impl(cls, item_type, allocated=DEFAULT_ALLOCATED):
        return listobject.new_list(item_type, allocated=allocated)

    return impl
# Buggy code
def impl(cls, item_type):
    return listobject.new_list(item_type)


# Traceback (numba.errors.TypingError)
======================================================================
ERROR: test_numba_typed_list_allocated (sdc.tests.test_series.TestSeries)
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\Users\akozlov\AppData\Local\Continuum\anaconda3\hpat\sdc\tests\test_series.py
", line 6817, in test_numba_typed_list_allocated
print(jitted())
File "c:\users\akozlov\appdata\local\continuum\anaconda3\numba_master\numba\numba\disp
atcher.py", line 401, in _compile_for_args
error_rewrite(e, 'typing')
File "c:\users\akozlov\appdata\local\continuum\anaconda3\numba_master\numba\numba\disp
atcher.py", line 344, in error_rewrite
reraise(type(e), e, None)
File "c:\users\akozlov\appdata\local\continuum\anaconda3\numba_master\numba\numba\six.
py", line 668, in reraise
raise value.with_traceback(tb)
numba.errors.TypingError: Failed in nopython mode pipeline (step: nopython frontend)
Invalid use of Function(<function typedlist_empty at 0x0000015A9C481550>) with argument(
s) of type(s): (typeref[<class 'numba.types.containers.ListType'>], class(int64), int64)

* parameterized
In definition 0:
TypeError: typedlist_empty() takes 2 positional arguments but 3 were given
raised from c:\users\akozlov\appdata\local\continuum\anaconda3\numba_master\numba\nu
mba\typing\templates.py:539
In definition 1:
TypeError: typedlist_empty() takes 2 positional arguments but 3 were given
raised from c:\users\akozlov\appdata\local\continuum\anaconda3\numba_master\numba\nu
mba\typing\templates.py:539
This error is usually caused by passing an argument of a type that is unsupported by the
named function.
[1] During: resolving callee type: BoundFunction((<class 'numba.types.abstract.TypeRef'>
, 'empty_list') for typeref[<class 'numba.types.containers.ListType'>])
[2] During: typing of call at C:\Users\akozlov\AppData\Local\Continuum\anaconda3\hpat\sd
c\tests\test_series.py (6813)


File "sdc\tests\test_series.py", line 6813:
def test_impl():
<source elided>
# problem in overload of empty_list in typedlist.py
alloc_list = List.empty_list(types.int64, 10)
^


----------------------------------------------------------------------
Ran 1 test in 0.075s

FAILED (errors=1)

# Fixed code
def impl(cls, item_type, allocated=DEFAULT_ALLOCATED):
    return listobject.new_list(item_type, allocated=allocated)
# Buggy code
def __getitem__(self, item):
    if isinstance(item, slice):
        start, stop, step = item.indices(self.size)
        stride = step * self.stride
        start = self.start + start * abs(self.stride)
        stop = self.start + stop * abs(self.stride)
        if stride == 0:
            size = 1
        else:
            size = _compute_size(start, stop, stride)
        ret = Dim(start=start, stop=stop, size=size, stride=stride, single=False)
        return ret
    else:
        sliced = self[item : item + 1]
        return Dim(
            start=sliced.start,
            stop=sliced.stop,
            size=sliced.size,
            stride=sliced.stride,
            single=True,
        )


# Traceback (AssertionError)
from numba import cuda
a = cuda.device_array((5,))
a[:] = range(5)

# this throws an AssertionError
... for v in a:
...     print(v)
...
0.0
1.0
2.0
3.0
4.0
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/leofang/conda_envs/cupy_dev/lib/python3.6/site-packages/numba/cuda/cudadrv/devices.py", line 212, in _require_cuda_context
return fn(*args, **kws)
File "/home/leofang/conda_envs/cupy_dev/lib/python3.6/site-packages/numba/cuda/cudadrv/devicearray.py", line 479, in __getitem__
return self._do_getitem(item)
File "/home/leofang/conda_envs/cupy_dev/lib/python3.6/site-packages/numba/cuda/cudadrv/devicearray.py", line 489, in _do_getitem
arr = self._dummy.__getitem__(item)
File "/home/leofang/conda_envs/cupy_dev/lib/python3.6/site-packages/numba/dummyarray.py", line 219, in __getitem__
dims = [dim.__getitem__(it) for dim, it in zip(self.dims, item)]
File "/home/leofang/conda_envs/cupy_dev/lib/python3.6/site-packages/numba/dummyarray.py", line 219, in <listcomp>
dims = [dim.__getitem__(it) for dim, it in zip(self.dims, item)]
File "/home/leofang/conda_envs/cupy_dev/lib/python3.6/site-packages/numba/dummyarray.py", line 78, in __getitem__
single=True,
File "/home/leofang/conda_envs/cupy_dev/lib/python3.6/site-packages/numba/dummyarray.py", line 51, in __init__
assert not single or size == 1
AssertionError
# but manually limiting the range works fine
... for i in range(5):
...     print(a[i])
...
0.0
1.0
2.0
3.0
4.0


# Fixed code
def __getitem__(self, item):
    if isinstance(item, slice):
        start, stop, step = item.indices(self.size)
        stride = step * self.stride
        start = self.start + start * abs(self.stride)
        stop = self.start + stop * abs(self.stride)
        if stride == 0:
            size = 1
        else:
            size = _compute_size(start, stop, stride)
        ret = Dim(start=start, stop=stop, size=size, stride=stride, single=False)
        return ret
    else:
        sliced = self[item : item + 1]
        if sliced.size != 1:
            raise IndexError
        return Dim(
            start=sliced.start,
            stop=sliced.stop,
            size=sliced.size,
            stride=sliced.stride,
            single=True,
        )
# Buggy code
def __init__(self, py_func, identity=None, cache=False, targetoptions={}):
    if isinstance(py_func, Dispatcher):
        py_func = py_func.py_func
    self.targetoptions = targetoptions.copy()
    kws = {}
    kws["identity"] = ufuncbuilder.parse_identity(identity)

    dispatcher = jit(target="npyufunc", cache=cache)(py_func)
    super(DUFunc, self).__init__(dispatcher, **kws)
    # Loop over a copy of the keys instead of the keys themselves,
    # since we're changing the dictionary while looping.
    self._install_type()
    self._lower_me = DUFuncLowerer(self)
    self._install_cg()
    self.__name__ = py_func.__name__
    self.__doc__ = py_func.__doc__


# Traceback (TypeError)
<class 'numpy.ufunc'>
b'\x80\x03cnumpy.core\n_ufunc_reconstruct\nq\x00X\x0b\x00\x00\x00__mp_main__q\x01X\x04\x00\x00\x00inc2q\x02\x86q\x03Rq\x04.'
<class 'numba.npyufunc.dufunc.DUFunc'>
Traceback (most recent call last):
File "vectorize_pickle.py", line 15, in <module>
print(pickle.dumps(inc1))
TypeError: can't pickle DUFunc objects

# Fixed code
def __init__(self, py_func, identity=None, cache=False, targetoptions={}):
    if isinstance(py_func, Dispatcher):
        py_func = py_func.py_func
    dispatcher = jit(target="npyufunc", cache=cache, **targetoptions)(py_func)
    self._initialize(dispatcher, identity)
# Buggy code
def store_overloads_on_success():
    # use to ensure overloads are stored on success
    try:
        yield
    except:
        raise
    else:
        exists = self.overloads.get(cres.signature)
        if exists is None:
            self.overloads[cres.signature] = cres


# Traceback (TypeError)
<class 'numpy.ufunc'>
b'\x80\x03cnumpy.core\n_ufunc_reconstruct\nq\x00X\x0b\x00\x00\x00__mp_main__q\x01X\x04\x00\x00\x00inc2q\x02\x86q\x03Rq\x04.'
<class 'numba.npyufunc.dufunc.DUFunc'>
Traceback (most recent call last):
File "vectorize_pickle.py", line 15, in <module>
print(pickle.dumps(inc1))
TypeError: can't pickle DUFunc objects

# Fixed code
def store_overloads_on_success():
    # use to ensure overloads are stored on success
    try:
        yield
    except Exception:
        raise
    else:
        exists = self.overloads.get(cres.signature)
        if exists is None:
            self.overloads[cres.signature] = cres
# Buggy code
def build_ufunc(self):
    dtypelist = []
    ptrlist = []
    if not self.nb_func:
        raise TypeError("No definition")

    # Get signature in the order they are added
    keepalive = []
    for sig in self._sigs:
        cres = self._cres[sig]
        dtypenums, ptr, env = self.build(cres)
        dtypelist.append(dtypenums)
        ptrlist.append(utils.longint(ptr))
        keepalive.append((cres.library, env))

    datlist = [None] * len(ptrlist)

    inct = len(self.sin)
    outct = len(self.sout)

    # Pass envs to fromfuncsig to bind to the lifetime of the ufunc object
    ufunc = _internal.fromfunc(
        self.py_func.__name__,
        self.py_func.__doc__,
        ptrlist,
        dtypelist,
        inct,
        outct,
        datlist,
        keepalive,
        self.identity,
        self.signature,
    )
    return ufunc


# Traceback (TypeError)
<class 'numpy.ufunc'>
b'\x80\x03cnumpy.core\n_ufunc_reconstruct\nq\x00X\x0b\x00\x00\x00__mp_main__q\x01X\x04\x00\x00\x00inc2q\x02\x86q\x03Rq\x04.'
<class 'numba.npyufunc.dufunc.DUFunc'>
Traceback (most recent call last):
File "vectorize_pickle.py", line 15, in <module>
print(pickle.dumps(inc1))
TypeError: can't pickle DUFunc objects

# Fixed code
def build_ufunc(self):
    dtypelist = []
    ptrlist = []
    if not self.nb_func:
        raise TypeError("No definition")

    # Get signature in the order they are added
    keepalive = []
    for sig in self._sigs:
        cres = self._cres[sig]
        dtypenums, ptr, env = self.build(cres)
        dtypelist.append(dtypenums)
        ptrlist.append(utils.longint(ptr))
        keepalive.append((cres.library, env))

    datlist = [None] * len(ptrlist)

    inct = len(self.sin)
    outct = len(self.sout)

    # Pass envs to fromfuncsig to bind to the lifetime of the ufunc object
    ufunc = _internal.fromfunc(
        self.py_func.__name__,
        self.py_func.__doc__,
        ptrlist,
        dtypelist,
        inct,
        outct,
        datlist,
        keepalive,
        self.identity,
        self.signature,
    )
    return ufunc
# Buggy code
def _get_or_create_context_uncached(self, devnum):
    """See also ``get_or_create_context(devnum)``.
    This version does not read the cache.
    """
    with self._lock:
        # Try to get the active context in the CUDA stack or
        # activate GPU-0 with the primary context
        with driver.get_active_context() as ac:
            if not ac:
                return self._activate_context_for(0)
            else:
                # Get primary context for the active device
                ctx = self.gpus[ac.devnum].get_primary_context()
                # Is active context the primary context?
                if ctx.handle.value != ac.context_handle.value:
                    msg = "Numba cannot operate on non-primary CUDA context {:x}"
                    raise RuntimeError(msg.format(ac.context_handle.value))
            return ctx


# Traceback (AttributeError)
Traceback (most recent call last):
File "/conda/envs/gdf/lib/python3.6/site-packages/numba/utils.py", line 745, in _exitfunc
f()
File "/conda/envs/gdf/lib/python3.6/site-packages/numba/utils.py", line 669, in __call__
return info.func(*info.args, **(info.kwargs or {}))
File "/conda/envs/gdf/lib/python3.6/site-packages/numba/cuda/cudadrv/driver.py", line 1037, in core
dealloc.add_item(module_unload, handle)
AttributeError: 'NoneType' object has no attribute 'add_item'

# Fixed code
def _get_or_create_context_uncached(self, devnum):
    """See also ``get_or_create_context(devnum)``.
    This version does not read the cache.
    """
    with self._lock:
        # Try to get the active context in the CUDA stack or
        # activate GPU-0 with the primary context
        with driver.get_active_context() as ac:
            if not ac:
                return self._activate_context_for(0)
            else:
                # Get primary context for the active device
                ctx = self.gpus[ac.devnum].get_primary_context()
                # Is active context the primary context?
                if ctx.handle.value != ac.context_handle.value:
                    msg = "Numba cannot operate on non-primary CUDA context {:x}"
                    raise RuntimeError(msg.format(ac.context_handle.value))
                # Ensure the context is ready
                ctx.prepare_for_use()
            return ctx
# Buggy code
def push(self):
    """
    Pushes this context on the current CPU Thread.
    """
    driver.cuCtxPushCurrent(self.handle)
    # setup *deallocations* as the context becomes active for the first time
    if self.deallocations is None:
        self.deallocations = _PendingDeallocs(self.get_memory_info().total)


# Traceback (AttributeError)
Traceback (most recent call last):
File "/conda/envs/gdf/lib/python3.6/site-packages/numba/utils.py", line 745, in _exitfunc
f()
File "/conda/envs/gdf/lib/python3.6/site-packages/numba/utils.py", line 669, in __call__
return info.func(*info.args, **(info.kwargs or {}))
File "/conda/envs/gdf/lib/python3.6/site-packages/numba/cuda/cudadrv/driver.py", line 1037, in core
dealloc.add_item(module_unload, handle)
AttributeError: 'NoneType' object has no attribute 'add_item'

# Fixed code
def push(self):
    """
    Pushes this context on the current CPU Thread.
    """
    driver.cuCtxPushCurrent(self.handle)
    self.prepare_for_use()
# Buggy code
def _module_finalizer(context, handle):
    dealloc = context.deallocations
    modules = context.modules

    def core():
        shutting_down = utils.shutting_down  # early bind

        def module_unload(handle):
            # If we are not shutting down, we must be called due to
            # Context.reset() of Context.unload_module().  Both must have
            # cleared the module reference from the context.
            assert shutting_down() or handle.value not in modules
            driver.cuModuleUnload(handle)

        dealloc.add_item(module_unload, handle)

    return core


# Traceback (AttributeError)
Traceback (most recent call last):
File "/conda/envs/gdf/lib/python3.6/site-packages/numba/utils.py", line 745, in _exitfunc
f()
File "/conda/envs/gdf/lib/python3.6/site-packages/numba/utils.py", line 669, in __call__
return info.func(*info.args, **(info.kwargs or {}))
File "/conda/envs/gdf/lib/python3.6/site-packages/numba/cuda/cudadrv/driver.py", line 1037, in core
dealloc.add_item(module_unload, handle)
AttributeError: 'NoneType' object has no attribute 'add_item'

# Fixed code
def _module_finalizer(context, handle):
    dealloc = context.deallocations
    modules = context.modules

    def core():
        shutting_down = utils.shutting_down  # early bind

        def module_unload(handle):
            # If we are not shutting down, we must be called due to
            # Context.reset() of Context.unload_module().  Both must have
            # cleared the module reference from the context.
            assert shutting_down() or handle.value not in modules
            driver.cuModuleUnload(handle)

        if dealloc is not None:
            dealloc.add_item(module_unload, handle)
        else:
            # Check the impossible case.
            assert shutting_down(), (
                "dealloc is None but interpreter is not being shutdown!"
            )

    return core
# Buggy code
def core():
    shutting_down = utils.shutting_down  # early bind

    def module_unload(handle):
        # If we are not shutting down, we must be called due to
        # Context.reset() of Context.unload_module().  Both must have
        # cleared the module reference from the context.
        assert shutting_down() or handle.value not in modules
        driver.cuModuleUnload(handle)

    dealloc.add_item(module_unload, handle)


# Traceback (AttributeError)
Traceback (most recent call last):
File "/conda/envs/gdf/lib/python3.6/site-packages/numba/utils.py", line 745, in _exitfunc
f()
File "/conda/envs/gdf/lib/python3.6/site-packages/numba/utils.py", line 669, in __call__
return info.func(*info.args, **(info.kwargs or {}))
File "/conda/envs/gdf/lib/python3.6/site-packages/numba/cuda/cudadrv/driver.py", line 1037, in core
dealloc.add_item(module_unload, handle)
AttributeError: 'NoneType' object has no attribute 'add_item'

# Fixed code
def core():
    shutting_down = utils.shutting_down  # early bind

    def module_unload(handle):
        # If we are not shutting down, we must be called due to
        # Context.reset() of Context.unload_module().  Both must have
        # cleared the module reference from the context.
        assert shutting_down() or handle.value not in modules
        driver.cuModuleUnload(handle)

    if dealloc is not None:
        dealloc.add_item(module_unload, handle)
    else:
        # Check the impossible case.
        assert shutting_down(), "dealloc is None but interpreter is not being shutdown!"
# Buggy code
def _module_finalizer(context, handle):
    dealloc = context.deallocations
    modules = context.modules

    def core():
        shutting_down = utils.shutting_down  # early bind

        def module_unload(handle):
            # If we are not shutting down, we must be called due to
            # Context.reset() of Context.unload_module().  Both must have
            # cleared the module reference from the context.
            assert shutting_down() or handle.value not in modules
            driver.cuModuleUnload(handle)

        if dealloc is not None:
            dealloc.add_item(module_unload, handle)
        else:
            # Check the impossible case.
            assert shutting_down(), (
                "dealloc is None but interpreter is not being shutdown!"
            )

    return core


# Traceback (AttributeError)
Traceback (most recent call last):
File "/conda/envs/gdf/lib/python3.6/site-packages/numba/utils.py", line 745, in _exitfunc
f()
File "/conda/envs/gdf/lib/python3.6/site-packages/numba/utils.py", line 669, in __call__
return info.func(*info.args, **(info.kwargs or {}))
File "/conda/envs/gdf/lib/python3.6/site-packages/numba/cuda/cudadrv/driver.py", line 1037, in core
dealloc.add_item(module_unload, handle)
AttributeError: 'NoneType' object has no attribute 'add_item'

# Fixed code
def _module_finalizer(context, handle):
    dealloc = context.deallocations
    modules = context.modules

    def core():
        shutting_down = utils.shutting_down  # early bind

        def module_unload(handle):
            # If we are not shutting down, we must be called due to
            # Context.reset() of Context.unload_module().  Both must have
            # cleared the module reference from the context.
            assert shutting_down() or handle.value not in modules
            driver.cuModuleUnload(handle)

        dealloc.add_item(module_unload, handle)

    return core
# Buggy code
def core():
    shutting_down = utils.shutting_down  # early bind

    def module_unload(handle):
        # If we are not shutting down, we must be called due to
        # Context.reset() of Context.unload_module().  Both must have
        # cleared the module reference from the context.
        assert shutting_down() or handle.value not in modules
        driver.cuModuleUnload(handle)

    if dealloc is not None:
        dealloc.add_item(module_unload, handle)
    else:
        # Check the impossible case.
        assert shutting_down(), "dealloc is None but interpreter is not being shutdown!"


# Traceback (AttributeError)
Traceback (most recent call last):
File "/conda/envs/gdf/lib/python3.6/site-packages/numba/utils.py", line 745, in _exitfunc
f()
File "/conda/envs/gdf/lib/python3.6/site-packages/numba/utils.py", line 669, in __call__
return info.func(*info.args, **(info.kwargs or {}))
File "/conda/envs/gdf/lib/python3.6/site-packages/numba/cuda/cudadrv/driver.py", line 1037, in core
dealloc.add_item(module_unload, handle)
AttributeError: 'NoneType' object has no attribute 'add_item'

# Fixed code
def core():
    shutting_down = utils.shutting_down  # early bind

    def module_unload(handle):
        # If we are not shutting down, we must be called due to
        # Context.reset() of Context.unload_module().  Both must have
        # cleared the module reference from the context.
        assert shutting_down() or handle.value not in modules
        driver.cuModuleUnload(handle)

    dealloc.add_item(module_unload, handle)
# Buggy code
def get_cache_path(self):
    # We could also use jupyter_core.paths.jupyter_runtime_dir()
    # In both cases this is a user-wide directory, so we need to
    # be careful when disambiguating if we don't want too many
    # conflicts (see below).
    try:
        from IPython.paths import get_ipython_cache_dir
    except ImportError:
        # older IPython version
        from IPython.utils.path import get_ipython_cache_dir
    return os.path.join(get_ipython_cache_dir(), "numba")


# Traceback (AttributeError)
(gammapy-dev) hfm-1804a:tmp deil$ ipython
Python 3.7.0 | packaged by conda-forge | (default, Nov 12 2018, 12:34:36)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.3.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: import numba

In [2]: numba.jit
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-2-509e32de4401> in <module>
----> 1 numba.jit

AttributeError: module 'numba' has no attribute 'jit'

In [3]: numba
Out[3]: <module 'numba' (namespace)>

In [4]: numba.__path__
Out[4]: _NamespacePath(['/Users/deil/.ipython/numba'])

In [5]:
Do you really want to exit ([y]/n)?
(gammapy-dev) hfm-1804a:tmp deil$ ls -lh /Users/deil/.ipython/numba
total 24
-rw-r--r--  1 deil  staff   5.4K Apr 20 11:30 ipython-input-4-f982ea8710c3.f-fc3bc4f3ad.py37m.1.nbc
-rw-r--r--  1 deil  staff   961B Apr 20 11:30 ipython-input-4-f982ea8710c3.f-fc3bc4f3ad.py37m.nbi

# Fixed code
def get_cache_path(self):
    # We could also use jupyter_core.paths.jupyter_runtime_dir()
    # In both cases this is a user-wide directory, so we need to
    # be careful when disambiguating if we don't want too many
    # conflicts (see below).
    try:
        from IPython.paths import get_ipython_cache_dir
    except ImportError:
        # older IPython version
        from IPython.utils.path import get_ipython_cache_dir
    return os.path.join(get_ipython_cache_dir(), "numba_cache")
# Buggy code
def find_file(pat, libdir=None):
    if libdir is None:
        libdirs = get_lib_dirs()
    else:
        libdirs = list(libdir)
    files = []
    for ldir in libdirs:
        entries = os.listdir(ldir)
        candidates = [os.path.join(ldir, ent) for ent in entries if pat.match(ent)]
        files.extend([c for c in candidates if os.path.isfile(c)])
    return files


# Traceback (FileNotFoundError)
Traceback (most recent call last):
File "cuda_issue.py", line 4, in <module>
@cuda.jit('(int64, float32)')
File "numba/numba/cuda/decorators.py", line 98, in kernel_jit
kernel.bind()
File "numba/numba/cuda/compiler.py", line 503, in bind
self._func.get()
File "numba/numba/cuda/compiler.py", line 381, in get
ptx = self.ptx.get()
File "numba/numba/cuda/compiler.py", line 352, in get
**self._extra_options)
File "numba/numba/cuda/cudadrv/nvvm.py", line 475, in llvm_to_ptx
libdevice = LibDevice(arch=opts.get('arch', 'compute_20'))
File "numba/numba/cuda/cudadrv/nvvm.py", line 350, in __init__
if get_libdevice(arch) is None:
File "numba/numba/cuda/cudadrv/libs.py", line 22, in get_libdevice
candidates = find_file(re.compile(pat), libdir)
File "numba/numba/findlib.py", line 45, in find_file
entries = os.listdir(ldir)
FileNotFoundError: [Errno 2] No such file or directory: 'u'

# Fixed code
def find_file(pat, libdir=None):
    if libdir is None:
        libdirs = get_lib_dirs()
    elif isinstance(libdir, str):
        libdirs = [
            libdir,
        ]
    else:
        libdirs = list(libdir)
    files = []
    for ldir in libdirs:
        entries = os.listdir(ldir)
        candidates = [os.path.join(ldir, ent) for ent in entries if pat.match(ent)]
        files.extend([c for c in candidates if os.path.isfile(c)])
    return files
# Buggy code
def device_memory_size(devmem):
    """Check the memory size of the device memory.
    The result is cached in the device memory object.
    It may query the driver for the memory size of the device memory allocation.
    """
    sz = getattr(devmem, "_cuda_memsize_", None)
    if sz is None:
        s, e = device_extents(devmem)
        sz = e - s
        devmem._cuda_memsize_ = sz
    assert sz > 0, "zero length array"
    return sz


# Traceback (ValueError)
Traceback (most recent call last):
File "pyarrow/tests/numba_bug.py", line 9, in <module>
d_arr[::-1].copy_to_host()
File "/home/pearu/miniconda3/envs/pyarrow-dev/lib/python3.7/site-packages/numba/cuda/cudadrv/devices.py", line 212, in _require_cuda_context
return fn(*args, **kws)
File "/home/pearu/miniconda3/envs/pyarrow-dev/lib/python3.7/site-packages/numba/cuda/cudadrv/devicearray.py", line 240, in copy_to_host
strides=self.strides, buffer=hostary)
ValueError: strides is incompatible with shape of requested array and size of buffer

# Fixed code
def device_memory_size(devmem):
    """Check the memory size of the device memory.
    The result is cached in the device memory object.
    It may query the driver for the memory size of the device memory allocation.
    """
    sz = getattr(devmem, "_cuda_memsize_", None)
    if sz is None:
        s, e = device_extents(devmem)
        sz = e - s
        devmem._cuda_memsize_ = sz
    assert sz >= 0, "{} length array".format(sz)
    return sz
# Buggy code
def __init__(self, start, stop, size, stride, single):
    if stop < start:
        raise ValueError("end offset is before start offset")
    self.start = start
    self.stop = stop
    self.size = size
    self.stride = stride
    self.single = single
    assert not single or size == 1


# Traceback (ValueError)
Traceback (most recent call last):
File "pyarrow/tests/numba_bug.py", line 9, in <module>
d_arr[::-1].copy_to_host()
File "/home/pearu/miniconda3/envs/pyarrow-dev/lib/python3.7/site-packages/numba/cuda/cudadrv/devices.py", line 212, in _require_cuda_context
return fn(*args, **kws)
File "/home/pearu/miniconda3/envs/pyarrow-dev/lib/python3.7/site-packages/numba/cuda/cudadrv/devicearray.py", line 240, in copy_to_host
strides=self.strides, buffer=hostary)
ValueError: strides is incompatible with shape of requested array and size of buffer

# Fixed code
def __init__(self, start, stop, size, stride, single):
    self.start = start
    self.stop = stop
    self.size = size
    self.stride = stride
    self.single = single
    assert not single or size == 1
# Buggy code
def __getitem__(self, item):
    if isinstance(item, slice):
        start, stop, step = item.start, item.stop, item.step
        single = False
    else:
        single = True
        start = item
        stop = start + 1
        step = None

    # Default values
    #   Start value is default to zero
    if start is None:
        start = 0
    #   Stop value is default to self.size
    if stop is None:
        stop = self.size
    #   Step is default to 1
    if step is None:
        step = 1

    stride = step * self.stride

    # Compute start in bytes
    if start >= 0:
        start = self.start + start * self.stride
    else:
        start = self.stop + start * self.stride
    start = max(start, self.start)

    # Compute stop in bytes
    if stop >= 0:
        stop = self.start + stop * self.stride
    else:
        stop = self.stop + stop * self.stride
    stop = min(stop, self.stop)

    # Clip stop
    if (stop - start) > self.size * self.stride:
        stop = start + self.size * stride

    if stop < start:
        start = stop
        size = 0
    elif stride == 0:
        size = 1 if single else ((stop - start) // step)
    else:
        size = (stop - start + (stride - 1)) // stride

    return Dim(start, stop, size, stride, single)


# Traceback (ValueError)
Traceback (most recent call last):
File "pyarrow/tests/numba_bug.py", line 9, in <module>
d_arr[::-1].copy_to_host()
File "/home/pearu/miniconda3/envs/pyarrow-dev/lib/python3.7/site-packages/numba/cuda/cudadrv/devices.py", line 212, in _require_cuda_context
return fn(*args, **kws)
File "/home/pearu/miniconda3/envs/pyarrow-dev/lib/python3.7/site-packages/numba/cuda/cudadrv/devicearray.py", line 240, in copy_to_host
strides=self.strides, buffer=hostary)
ValueError: strides is incompatible with shape of requested array and size of buffer

# Fixed code
def __getitem__(self, item):
    if isinstance(item, slice):
        start, stop, step = item.indices(self.size)
        stride = step * self.stride
        start = self.start + start * abs(self.stride)
        stop = self.start + stop * abs(self.stride)
        if stride == 0:
            size = 1
        else:
            size = (stop - start + (stride - 1)) // stride
        if size < 0:
            size = 0
        ret = Dim(start=start, stop=stop, size=size, stride=stride, single=False)
        return ret
    else:
        sliced = self[item : item + 1]
        return Dim(
            start=sliced.start,
            stop=sliced.stop,
            size=sliced.size,
            stride=sliced.stride,
            single=True,
        )
# Buggy code
def infer_constant(self, name):
    """
    Infer a constant value for the given variable *name*.
    If no value can be inferred, numba.errors.ConstantInferenceError
    is raised.
    """
    if name not in self._cache:
        try:
            self._cache[name] = (True, self._do_infer(name))
        except ConstantInferenceError as exc:
            # Store the exception args only, to avoid keeping
            # a whole traceback alive.
            self._cache[name] = (False, (exc.__class__, exc.args))
    success, val = self._cache[name]
    if success:
        return val
    else:
        exc, args = val
        raise exc(*args)


# Traceback (ConstantInferenceError)
---------------------------------------------------------------------------
ConstantInferenceError                    Traceback (most recent call last)
<ipython-input-29-41c708083646> in <module>
5     return a*b
6
----> 7 problem(1,2)

~/.virtualenvs/dl4cv/lib/python3.7/site-packages/numba/dispatcher.py in _compile_for_args(self, *args, **kws)
358             # this is from trying to infer something as constant when it isn't
359             # or isn't supported as a constant
--> 360             error_rewrite(e, 'constant_inference')
361         except Exception as e:
362             if config.SHOW_HELP:

~/.virtualenvs/dl4cv/lib/python3.7/site-packages/numba/dispatcher.py in error_rewrite(e, issue_type)
313                 raise e
314             else:
--> 315                 reraise(type(e), e, None)
316
317         argtypes = []

~/.virtualenvs/dl4cv/lib/python3.7/site-packages/numba/six.py in reraise(tp, value, tb)
656             value = tp()
657         if value.__traceback__ is not tb:
--> 658             raise value.with_traceback(tb)
659         raise value
660

ConstantInferenceError: Failed in nopython mode pipeline (step: nopython rewrites)
Cannot make a constant from: Cannot make a constant from: Cannot make a constant from: constant inference not possible for arg(0, name=a)
Numba could not make a constant out of something that it decided should be
a constant. This could well be a current limitation in Numba's internals,
please either raise a bug report along with a minimal reproducer at:
https://github.com/numba/numba/issues/new

# Fixed code
def infer_constant(self, name, loc=None):
    """
    Infer a constant value for the given variable *name*.
    If no value can be inferred, numba.errors.ConstantInferenceError
    is raised.
    """
    if name not in self._cache:
        try:
            self._cache[name] = (True, self._do_infer(name))
        except ConstantInferenceError as exc:
            # Store the exception args only, to avoid keeping
            # a whole traceback alive.
            self._cache[name] = (False, (exc.__class__, exc.args))
    success, val = self._cache[name]
    if success:
        return val
    else:
        exc, args = val
        if issubclass(exc, NumbaError):
            raise exc(*args, loc=loc)
        else:
            raise exc(*args)