This seems to be the same kind of issue but it’s reading rather than writing structured array data types. Should I enter a new bug?
numbafail.py:
import sys
import numpy as np
import numba
@numba.jit(nopython=True)
def test1(result, content, ncols):
int16LE = np.dtype('<h')
ndata = 0
for item in content:
j = ndata
k = j+ncols
result[j:k] = item['data'][:2*ncols].view(int16LE)
ndata += ncols
content = np.zeros(5,dtype=[('data', 'u1', (255,))])
notable_content_base = np.array([10,20,30,40,50,60,70,80])
ncols = len(notable_content_base)
nrows = content.shape[0]
for k in range(nrows):
content[k]['data'][:ncols*2:2] = notable_content_base+k
content[k]['data'][1:ncols*2:2] = 100
result = np.zeros(nrows*ncols, dtype=np.dtype('<h'))
print('python %s\nnumpy %s\nnumba %s' % (sys.version, np.__version__, numba.__version__))
test1(result, content, ncols)
print(result)
Numba 0.53.1 works:
>python numbafail.py
python 3.8.5 (default, Sep 3 2020, 21:29:08) [MSC v.1916 64 bit (AMD64)]
numpy 1.19.2
numba 0.53.1
[25610 25620 25630 25640 25650 25660 25670 25680 25611 25621 25631 25641
25651 25661 25671 25681 25612 25622 25632 25642 25652 25662 25672 25682
25613 25623 25633 25643 25653 25663 25673 25683 25614 25624 25634 25644
25654 25664 25674 25684]
Numba 0.54 fails:
>python numbafail.py
python 3.8.5 (default, Sep 3 2020, 21:29:08) [MSC v.1916 64 bit (AMD64)]
numpy 1.19.2
numba 0.54.0
Traceback (most recent call last):
File "numbafail.py", line 24, in <module>
test1(result, content, ncols)
File "c:\app\python\anaconda\3\envs\py3-2\lib\site-packages\numba\core\dispatcher.py", line 482, in _compile_for_args
error_rewrite(e, 'typing')
File "c:\app\python\anaconda\3\envs\py3-2\lib\site-packages\numba\core\dispatcher.py", line 423, in error_rewrite
raise e.with_traceback(None)
numba.core.errors.TypingError: Failed in nopython mode pipeline (step: nopython frontend)
←[1m←[1mNo implementation of function Function(<built-in function getitem>) found for signature:
>>> getitem(nestedarray(uint8, (255,)), slice<a:b>)
There are 22 candidate implementations:
←[1m - Of which 20 did not match due to:
Overload of function 'getitem': File: <numerous>: Line N/A.
With argument(s): '(nestedarray(uint8, (255,)), slice<a:b>)':←[0m
←[1m No match.←[0m
←[1m - Of which 2 did not match due to:
Overload in function 'GetItemBuffer.generic': File: numba\core\typing\arraydecl.py: Line 162.
With argument(s): '(nestedarray(uint8, (255,)), slice<a:b>)':←[0m
←[1m Rejected as the implementation raised a specific error:
TypeError: __init__() got an unexpected keyword argument 'ndim'←[0m
raised from c:\app\python\anaconda\3\envs\py3-2\lib\site-packages\numba\core\types\abstract.py:66
←[0m
←[0m←[1mDuring: typing of intrinsic-call at numbafail.py (12)←[0m
←[1m
File "numbafail.py", line 12:←[0m
←[1mdef test1(result, content, ncols):
<source elided>
k = j+ncols
←[1m result[j:k] = item['data'][:2*ncols].view(int16LE)
←[0m ←[1m^←[0m←[0m