Extended docs on numba
State: closed

Added more explicit note about the fact numba does not yet recognize pandas objects so one must always use `.values`, and added example of `numba.vectorize`.


Labels:
name: Docs

Comments:
since it's a code block u have to put the time it numbers in

you added an extraneous version file 
it is no longer used

Hmm. Numba ufuncs used to work on pandas objects in a way that preserved metadata like the index, but as of the latest version of Numba, they don't anymore. That was a nice trick... looks like we'll need to fix that in Numba.

ufuncs never worked on non numpy arrays

they r working on it but it is standard practice to wrap atm

@shoyer Yeah, they say they're on it: https://groups.google.com/a/continuum.io/forum/#!topic/numba-users/fr1S9mEL9I8

EDIT: by which I mean full numba integration. 

@jreback sorry Jeff, you're wrong :)

They actually still work, as long as you supply the function signature explicitly:

```
In [1]: import numba

In [3]: import pandas as pd

In [4]: @numba.vectorize('float64(float64)')
   ...: def f(x):
   ...:     return 2 * x
   ...:

In [5]: s = pd.Series(range(3), ['a', 'b', 'c'])

In [6]: f(s)
Out[6]:
a    0
b    2
c    4
dtype: float64
```

They just don't work with the new Numba dynamic ufuncs which determine the type signature automatically.

Stan and I discussed this last week - at some point this will happen
currently this works very much like how u pass to cython

@shoyer much harder to use and that's just using the array protocol
snd that might be in Python mode 

I wouldn't encourage that use at all

@shoyer show the timing

that's equivalent to np.vectorize which is useless

FWIW:

In [83]: @numba.vectorize('float64(float64)', nopython=True)
             def f(x):
                   return 2 \* x

```
     s = pd.Series(range(100000), range(300000,400000))
     %timeit f(s)

    1000 loops, best of 3: 214 µs per loop
```

In [84]: %timeit s*2
             1000 loops, best of 3: 675 µs per loop

In [85]: f(s).head()
Out[85]: 
        300000    0
        300001    2
        300002    4
        300003    6
        300004    8
        dtype: float64

ok I guess it must be loop lifting then

@nickeubank do u have numexpr installed?

> @shoyer show the timing
> 
> that's equivalent to np.vectorize which is useless

I guess @nickeubank showed that I'm right :).

Numba creates actual numpy ufuncs with the vectorize and guvectorize decorators if you supply a type signature, so of course they are applied in a vectorized fashion (that's the entire point).

IMO the NumPy array protocols are the right way for third party objects (like those in pandas) to interact with Numba -- I'll speak up about that on the Numba mailing list.

well for a trivial example I guess so

the problem here is that there are times when u want to actually manipulate the index
which is impossible atm and the reason that numba needs to understand a more complex dtype

@jreback I think so. Never installed explicitly -- I'm working off the basic anaconda build -- but `import numexpr` executes fine, so looks like yes. 

thanks @jorisvandenbossche -- tweaked!

added additional notes on numba modes and what it will and will not accelerate. 

pls squash

@jreback squashed. 

thanks