Coder Social home page Coder Social logo

Comments (5)

lithomas1 avatar lithomas1 commented on June 7, 2024

Hm, this doesn't look too hard to fix, looking at the error (the nb_compat_func line).

It's been a while since I've looked at any numba stuff, though.

Are you interested in potentially contributing a PR?

from pandas.

auderson avatar auderson commented on June 7, 2024

Are you interested in potentially contributing a PR?

Sure, but I find the solution may not be that trivial:

Since numba generally requires the argument is known when function is defined, so any kind of varargs is not well supported.
It dosen't support **kwargs, and IIRC it also had some bugs with *args.

This means we can't simply add **kwargs to nb_looper:

@numba.jit(nopython=nopython, nogil=nogil, parallel=parallel)
def nb_looper(values, axis):
# Operate on the first row/col in order to get
# the output shape
if axis == 0:
first_elem = values[:, 0]
dim0 = values.shape[1]
else:
first_elem = values[0]
dim0 = values.shape[0]
res0 = nb_compat_func(first_elem)
# Use np.asarray to get shape for
# https://github.com/numba/numba/issues/4202#issuecomment-1185981507
buf_shape = (dim0,) + np.atleast_1d(np.asarray(res0)).shape
if axis == 0:
buf_shape = buf_shape[::-1]
buff = np.empty(buf_shape)
if axis == 1:
buff[0] = res0
for i in numba.prange(1, values.shape[0]):
buff[i] = nb_compat_func(values[i])
else:
buff[:, 0] = res0
for j in numba.prange(1, values.shape[1]):
buff[:, j] = nb_compat_func(values[:, j])
return buff

A possible solution is to dynamically create an intermediate function for each case. Use the example above:
df.apply(np.nanquantile, q=0.5, raw=True, engine="numba")

In this case, we dynamically defines:

@register_jitable
def nb_compat_func(values, q=0.5):
    return user_func(values, q=q)

which holds the **kwargs and the only required argument is values and this nb_compat_func will be used by nb_looper just as before.

However, I felt this solution is somewhat too hacky and not clean. Do you have any other ideas?

from pandas.

lithomas1 avatar lithomas1 commented on June 7, 2024

I think *args might be the best way to deal with this, if it's possible to fix this.
It's how we pass the kwargs to the other numba stuff like the numba groupby stuff.

Do you remember the issue you had with *args?

from pandas.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.