Cannot iterate over fields of record array
See original GitHub issueWhen iterating over the fields of a record array, numba complains about a not implemented getitem. Accessing the fields by name outside a loop works. I am using numba 0.52, the problem occurs on both Windows and linux
This is the ipython cell that produces the error:
%pylab
import numpy.random
from numba import njit
@njit
def recarriterator(rec):
for o in 'a','b','c':
print(rec[o][0])
return
@njit
def recarriterator2(rec):
print(rec['a'][0])
print(rec['b'][0])
print(rec['c'][0])
return
ldd=[]
ldk=[]
keys='a','b','c'
for o in keys:
#if not (o == 'observation_id' or o == 'report_id' or o == 'sensor_id' or o == 'source_id'):
ldd.append(random.rand(5))
ldk.append((o,ldd[-1].dtype))
rec = numpy.rec.fromarrays(ldd, dtype=ldk)
recarriterator2(rec)
recarriterator(rec)
The error code:
Using matplotlib backend: Qt5Agg
Populating the interactive namespace from numpy and matplotlib
0.26156099390229226
0.4919898206995005
0.363624558244539
---------------------------------------------------------------------------
TypingError Traceback (most recent call last)
<ipython-input-1-56c6c55bddcf> in <module>
26
27 recarriterator2(rec)
---> 28 recarriterator(rec)
~\anaconda3\lib\site-packages\numba\core\dispatcher.py in _compile_for_args(self, *args, **kws)
413 e.patch_message(msg)
414
--> 415 error_rewrite(e, 'typing')
416 except errors.UnsupportedError as e:
417 # Something unsupported is present in the user code, add help info
~\anaconda3\lib\site-packages\numba\core\dispatcher.py in error_rewrite(e, issue_type)
356 raise e
357 else:
--> 358 reraise(type(e), e, None)
359
360 argtypes = []
~\anaconda3\lib\site-packages\numba\core\utils.py in reraise(tp, value, tb)
78 value = tp()
79 if value.__traceback__ is not tb:
---> 80 raise value.with_traceback(tb)
81 raise value
82
TypingError: Failed in nopython mode pipeline (step: nopython frontend)
No implementation of function Function(<built-in function getitem>) found for signature:
>>> getitem(unaligned array(Record(a[type=float64;offset=0],b[type=float64;offset=8],c[type=float64;offset=16];24;False), 1d, C), unicode_type)
There are 22 candidate implementations:
- Of which 20 did not match due to:
Overload of function 'getitem': File: <numerous>: Line N/A.
With argument(s): '(unaligned array(Record(a[type=float64;offset=0],b[type=float64;offset=8],c[type=float64;offset=16];24;False), 1d, C), unicode_type)':
No match.
- Of which 2 did not match due to:
Overload in function 'GetItemBuffer.generic': File: numba\core\typing\arraydecl.py: Line 162.
With argument(s): '(unaligned array(Record(a[type=float64;offset=0],b[type=float64;offset=8],c[type=float64;offset=16];24;False), 1d, C), unicode_type)':
Rejected as the implementation raised a specific error:
TypeError: unsupported array index type unicode_type in [unicode_type]
raised from C:\Users\leopo\anaconda3\lib\site-packages\numba\core\typing\arraydecl.py:68
During: typing of intrinsic-call at <ipython-input-1-56c6c55bddcf> (8)
File "<ipython-input-1-56c6c55bddcf>", line 8:
def recarriterator(rec):
<source elided>
for o in 'a','b','c':
print(rec[o][0])
^
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (7 by maintainers)
Top Results From Across the Web
Cant iterate through the array of fetched records - Stack Overflow
Cant iterate through the array of fetched records · "So, how can I iterate through" you are already iterating through data array here....
Read more >How to iterate through an array of input fields with the same ...
Presumably, you want to update same element/object in whatever iteration of contentArray that you are updating in the other fields.
Read more >How do I iterate through an array of results from a step? - Help
At the top of the step, you'll need to iterate over the array of results ( steps.airtable_get_tasksOutstanding.$return_value.records ) ...
Read more >TypeError: 'x' is not iterable - JavaScript - MDN Web Docs
An iterable can be a built-in iterable type such as Array , String or Map , a ... Therefore, you cannot use for...of...
Read more >Iterate through collections in C# | Microsoft Learn
Learn how to use an iterator to step through collections like lists and arrays. Iterators are consumed from client code using a foreach ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This should work:
note that
literal_unroll
is imported explicitly. This is a known bug, think it’s a duplicate of https://github.com/numba/numba/issues/5344.@pwuertz thank you for submitting this. I can confirm that I am able to reproduce on current
main
(3781d6836d78f3467b02500b19a889039bdaf3bb
) with the following error: