`getitem` access with `str` value to a struct array causes impl "no match"
See original GitHub issueHopefully this isn’t a case of doing something obviously naive but, more or less the issue is that this compile error is the result of passing in a str argument (to an @njit-ed @staticmethod) to read a (numpy) struct-array via field name:
numba.core.errors.TypingError: Failed in nopython mode pipeline (step: nopython frontend)
No implementation of function Function(<built-in function getitem>) found for signature:
>>> getitem(Record(time[type=float64;offset=0],open[type=float64;offset=8],high[type=float64;offset=16],low[type=float64;offset=24],close[type=float64;offset=32],volume[type=float64;offset=40],bar_wap[type=float64;offset=48];56;False), unicode_type)
There are 22 candidate implementations:
- Of which 22 did not match due to:
Overload of function 'getitem': File: <numerous>: Line N/A.
With argument(s): '(Record(time[type=float64;offset=0],open[type=float64;offset=8],high[type=float64;offset=16],low[type=float64;offset=24],close[type=float64;offset=32],volume[type=float64;offset=40],bar_wap[type=float64;offset=48];56;False), unicode_type)':
No match.
During: typing of intrinsic-call at /home/goodboy/repos/piker/piker/data/_pathops.py (562)
File "piker/data/_pathops.py", line 562:
def path_arrays_from_ohlc(
<source elided>
close = q['close']
index = float64(q[index_field])
^
Yes, i’m on 0.56.4.
source code function which triggers this is here: https://github.com/pikers/piker/blob/8ee964451b085dfb957160465018f4d4bd8ab696/piker/data/_pathops.py#L526
More or less it seems that there is an issue with the type signature matching of the input struct-array both in terms of inferred (unspecified in numba terms) type sig as well as a manual spec.
For eg. I’ve tried something like
@staticmethod
@njit(
# TODO: need to construct this manually for readonly
# arrays, see https://github.com/numba/numba/issues/4511
(
types.Array(
numba_ohlc_dtype,
1,
'C',
readonly=True,
),
int64,
types.unicode_type,
optional(float64),
),
nogil=True
)
def path_arrays_from_ohlc(
data: np.ndarray,
start: int64,
index_field: str,
bar_gap: float64 = 0.43,
) -> tuple[
np.ndarray,
np.ndarray,
np.ndarray,
]:
And still get the same error.
Likely related issues include:
Issue Analytics
- State:
- Created 10 months ago
- Comments:9 (4 by maintainers)
Top Results From Across the Web
add element to array of struct in C++ encountered "error no ...
You are trying to assign a pointer to Numbers into a Numbers value. The rest of the error message is not helpful. Assuming...
Read more >BatchGetItem - Amazon DynamoDB - AWS Documentation
The BatchGetItem operation returns the attributes of one or more items from one or more tables. You identify requested items by primary key....
Read more >enum — Support for enumerations — Python 3.11.1 ...
Allows Enum members to have attributes without conflicting with member names. unique(). Enum class decorator that ensures only one name is bound to...
Read more >Troubleshooting and tips — Numba 0.50.1 documentation
Another common reason for Numba not being able to compile your code is that it cannot statically determine the return type of a...
Read more >The Type Hierarchy - SQLAlchemy 1.4 Documentation
For all backends, only the Python values None , True , False , 1 or 0 are ... access the string values inside...
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

Thanks for the report. I think this potentially demonstrates what it is you are seeing:
the issue is essentially that Numba sees the type of
fieldas atypes.unicode_type, it doesn’t know at compile time to which field in thedtdtypethis corresponds. As a result it cannot work out a return type of thegetitemcall which manifests as a typing error similar to that in the OP.The following case does work because the types can be resolved at compile time through the use of a compile-time-constant string that addresses the field:
@goodboy I don’t think list based access to the fields is supported. If the list is declared as in the above, then it has an
initial_value(the<iv=[...]>part of the type) which would potentially make it possible to implement this kind of indexing. If this is important to you then perhaps open a feature request? Many thanks.