Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot create datetime inside njit #6555

Open
2 tasks done
astrojuanlu opened this issue Dec 7, 2020 · 1 comment
Open
2 tasks done

Cannot create datetime inside njit #6555

astrojuanlu opened this issue Dec 7, 2020 · 1 comment

Comments

@astrojuanlu
Copy link
Contributor

Reporting a bug

  • I have tried using the latest released version of Numba (most recent is
    visible in the change log (https://github.com/numba/numba/blob/master/CHANGE_LOG).
  • I have included a self contained code sample to reproduce the problem.
    i.e. it's possible to run as 'python bug.py'.

By reading in https://numba.readthedocs.io/en/stable/reference/numpysupported.html#scalar-types that Numba supports NumPy datetimes and timestamps of any unit, I tried creating one inside a @njitted function, but it failed:

$ cat dt_test.py 
import numpy as np
from numba import njit


@njit
def f(dt64):
    return dt64

print(f(np.datetime64(100, "D")))  # Works


@njit
def d():
    return np.datetime64(100, "D")

print(d())  # Fails
$ python dt_test.py 
1970-04-11
Traceback (most recent call last):
  File "dt_test.py", line 16, in <module>
    print(d())  # Fails
  File "/home/juanlu/.pyenv/versions/sgp38/lib/python3.8/site-packages/numba/core/dispatcher.py", line 414, in _compile_for_args
    error_rewrite(e, 'typing')
  File "/home/juanlu/.pyenv/versions/sgp38/lib/python3.8/site-packages/numba/core/dispatcher.py", line 357, in error_rewrite
    raise e.with_traceback(None)
numba.core.errors.TypingError: Failed in nopython mode pipeline (step: nopython frontend)
No implementation of function Function(datetime64[]) found for signature:
 
 >>> <unknown function>(Literal[int](100), Literal[str](D))
 
There are 2 candidate implementations:
 - Of which 2 did not match due to:
 Overload in function 'make_callable_template.<locals>.generic': File: numba/core/typing/templates.py: Line 170.
   With argument(s): '(int64, unicode_type)':
  Rejected as the implementation raised a specific error:
    TypeError: typer() takes 1 positional argument but 2 were given
  raised from /home/juanlu/.pyenv/versions/sgp38/lib/python3.8/site-packages/numba/core/typing/templates.py:399

During: resolving callee type: class(datetime64[])
During: typing of call at dt_test.py (14)


File "dt_test.py", line 14:
def d():
    return np.datetime64(100, "D")
    ^

Tested on Python 3.8, Linux, latest numba installed from pip using manylinux wheels.

@stuartarchibald
Copy link
Contributor

Thanks for the report. From memory, creation of datetime types inside JIT code regions is not supported yet, however most operations should work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants