question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

numba.typed.typeddict.Dict.get returns the default even though the key is present

See original GitHub issue

With some specific key dtypes, Dict.get returns the default value even when the key is present. This has been tested with numba 0.55.1

To reproduce:

import numba

numba_dict = numba.typed.typeddict.Dict.empty(
    key_type=numba.types.Tuple([numba.types.uint32, numba.types.uint32]),
    value_type=numba.types.int64)

numba_dict[(1,1)] = 12345
assert numba_dict.get((1,1), 1) == numba_dict[(1,1)]

The error depends on the size of the ints in the key, not on the unsigned aspect. It disappears with e.g. numba.types.Tuple([numba.types.uint32, numba.types.uint64])

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
stuartarchibaldcommented, Apr 5, 2022

@guilhermeleobas Thanks for debugging, your assessment in https://github.com/numba/numba/issues/7908#issuecomment-1068327361 seems to highlight the likely cause.

@czgdp1807 RE the warning:

NumbaTypeSafetyWarning: unsafe cast from UniTuple(int64 x 2) to UniTuple(uint32 x 2). Precision may be lost.

This is because the dictionary is declared as taking uint32 but Numba will infer the type of a Python int as int64, as a result the type of the requested key UniTuple(int64 x 2) has to be cast to match the types of the keys as declared in the dictionary. This is expected.

Patches to fix and test as suggested are welcome. Many thanks!

0reactions
czgdp1807commented, Apr 5, 2022

Great. I will send a fix with a regression test tomorrow.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Supported Python features - Numba
Numba supports function calls using positional and named arguments, as well as arguments with default values and *args (note the argument for *args...
Read more >
Using Dictionaries with numba njit function - Stack Overflow
Now I have a function that accepts and returns dictionaries. How can I apply numba here? def collocation(aeolus_data,val_data): ... return ...
Read more >
SystemError potentially from Typed Dict - Numba Discussion
Therefore, I updated VTK 6.3 to VTK 7.1 and noticed that mentions of Python 3.8 (default on Ubuntu 20.04) were now present in...
Read more >
numba/numba - Gitter
mydict = nb.typed.Dict.empty( key_type=nb.types.UniTuple(nb.int64,2), value_type=nb.typeof(np.ones(2))) #I set a len==2 array mydict[(1,2)] = np.ones(2) #I ...
Read more >
alphapept - FASTA - GitHub Pages
Returns : list (of str): cleaved peptide sequences with missed cleavages. ... List, mass_dict:numba.typed.typeddict.Dict). Get neutral peptide mass, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found