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

Allow parsing dates of the form "1899-12-30" in a jit context #4242

Open
2 tasks done
bmironov opened this issue Jul 1, 2019 · 3 comments
Open
2 tasks done

Allow parsing dates of the form "1899-12-30" in a jit context #4242

bmironov opened this issue Jul 1, 2019 · 3 comments

Comments

@bmironov
Copy link

bmironov commented Jul 1, 2019

Hello,

First, thanks for your hard work and this great library.
Recently I came across small issue that is stopping me from using numba in my project. We need to parse dates that are adjusted as floats from Dec 30, 1899 (this format is used in Excel).
Below is details of my environment and content of Jupyter cells:

Thanks again and best regards

Numba 0.44.1
Running through Jupyter

import numba
import numpy as np
print(np.datetime64("1899-12-30"))
1899-12-30
@numba.jit
def test():
    t = np.datetime64("1899-12-30")
    return 0
test()
<ipython-input-50-f403da816d8c>:1: NumbaWarning: 
Compilation is falling back to object mode WITH looplifting enabled because Function test failed at nopython mode lowering due to: Cannot cast Literal[str](1899-12-30) to datetime64[]: %".16" = load i8*, i8** %"$const0.3"

File "<ipython-input-50-f403da816d8c>", line 3:
def test():
    t = np.datetime64("1899-12-30")
    ^

[1] During: lowering "$0.4 = call $0.2($const0.3, func=$0.2, args=[Var($const0.3, <ipython-input-50-f403da816d8c> (3))], kws=(), vararg=None)" at <ipython-input-50-f403da816d8c> (3)
  @numba.jit
/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/numba/compiler.py:725: NumbaWarning: Function "test" was compiled in object mode without forceobj=True.

File "<ipython-input-50-f403da816d8c>", line 2:
@numba.jit
def test():
^

  self.func_ir.loc))
/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/numba/compiler.py:734: NumbaDeprecationWarning: 
Fall-back from the nopython compilation path to the object mode compilation path has been detected, this is deprecated behaviour.

For more information visit http://numba.pydata.org/numba-doc/latest/reference/deprecation.html#deprecation-of-object-mode-fall-back-behaviour-when-using-jit

File "<ipython-input-50-f403da816d8c>", line 2:
@numba.jit
def test():
^

  warnings.warn(errors.NumbaDeprecationWarning(msg, self.func_ir.loc))
@esc
Copy link
Member

esc commented Jul 1, 2019

Hi @bmironov

Thanks for the praise, we really appreciate it! Thank you for considering Numba and taking the time to report this error.

I can confirm that parsing such strings you mentioned in a @jit context currently does not seem to work. What you could do in the meantime as a workaround, is to create your np.datetime objects outside of the context and then pass them in as arguments like so:

In [8]: mydate = np.datetime64("1899-12-30")

In [9]: @numba.njit
   ...: def test(da):
   ...:     print(da)
   ...:

In [10]: test(mydate)
1899-12-30

Would that be feasible for your use-case?

@bmironov
Copy link
Author

bmironov commented Jul 1, 2019

Hi @esc
Thanks, this idea works for me

Look forward for permanent solution :)

@esc
Copy link
Member

esc commented Jul 1, 2019

@bmironov thanks for reporting back. I will convert your issue into a feature request!

@esc esc changed the title Numba has issue parsing "1899-12-30" Allow parsing dates of the form "1899-12-30" in a jit context Jul 1, 2019
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