-
-
Notifications
You must be signed in to change notification settings - Fork 18.2k
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
ENH: Add support for executing UDF's using Bodo as the engine #60668
Comments
I don’t see why this needs to live in pandas instead of something like bodo.apply(func, df). Same amount of changed code for users. |
@jbrockmendel while in general I agree with your point, we already have the numba engine in pandas. Do you think we should remove it? For what I understand, seems like Bodo should be better for most users, as it works with Arrow types (besides the other advantages discussed). So, while I'm a big fan of not adding more things into pandas, I don't see why we should have numba and not bodo. Is there a reason? Also, assuming Bodo is included, are there reasons to keep numba? When is numba a better choice than Bodo? |
Hi @datapythonista, I updated the issue description with more examples highlighting some of benefits of including bodo as an engine in pandas. Let me know if there is anything else needed for the issue and/or PR. We can also open a PDEP if necessary. Thanks! |
Numba is quite well-established and likely to stick around. Bodo looks very good from what I can tell, but arguably it doesn't yet meet the same bar for being included in pandas and for that code to then be maintained and tested by the pandas community There have been other cases where companies asked for code to be included in pandas, they promised to maintain it, and then disappeared. I'm sure Bodo wouldn't be like that, but still, I think some care needs taking here before adding more code to pandas I'm also concerned that this opens the doors for many, many more companies wanting their engine inside of pandas Would it work to define something like a standardised apply-engine entrypoint, as suggested in the PR review? This may address concerns around increasing the maintenance and testing burden on pandas? |
@MarcoGorelli You bring up some good points. We would be happy to help develop a standardized apply-engine entry-point and make the necessary changes on our end. Moving forward, we would like to open an issue (or update this issue) to work out the specifics of what this entry-point could look like. |
Do we know of any other index engines that are trying to make their way in? I've gone back and forth on this myself. To be fair, the current implementation doesn't look that crazy, and just follows suit for what we started with numba. Given both numba and bodo are open source, I'm not sure what one has a relatively higher risk of abandonment than the other. There is always the option to run with it for now and refactor at a later date if/when we have more engines that make sense to integrate |
Yup, that's also true! Starting with these two and then generalising later (if there's interest / demand) could work! |
|
Feature Type
Adding new functionality to pandas
Changing existing functionality in pandas
Removing existing functionality in pandas
Problem Description
Applying User Defined Functions (UDFs) to a DataFrame can be very slow when evaluated using the default python engine. Passing
engine="numba"
and leveraging Numba's Just-in-Time (JIT) compiler to transform the UDF application into an optimized binary can improve performance, however there are several limitations to the Numba UDF engine including:raw=True
)Adding support for the Bodo engine would solve the above issues and provide a good complement to the capabilities of the currently supported engines (Python and Numba).
Bodo uses an auto-parallelizing JIT compiler to transform Python code into highly optimized, parallel binaries with an MPI backend, allowing it to scale to very large data sizes with minimal extra work required from the user (large speedups on both laptops and clusters). Bodo is also built for Pandas and supports DataFrame, Series and Array Extension types natively.
Feature Description
Allow passing the value
"bodo"
to theengine
parameter inDataFrame.apply
and add anapply_bodo
method which accepts the user defined function and creates a jit function to do the apply and calls it. For example:In
pandas/core/apply.py
This approach could also be applied to other API's that accepts a UDF and engine argument.
Alternative Solutions
Users could execute their UDF using a Bodo JIT'd function. For example:
While this approach is fine, it has it's downsides such as requiring a larger code rewrite which could make it more difficult to quickly experiment with different engines.
Additional examples:
To demonstrate the value that the Bodo engine would bring to Pandas users, consider the following examples which highlight some of the limitations of the current engines (Python and Numba):
Numba does not support non-numeric column types such as strings and has limited support for Pandas APIs inside the UDF. The following example would not compile with the numba engine:
Bodo also natively supports Timestamp (with timezone) and DateOffset types inside UDFs whereas numba only supports datetime64/timedelta64:
Lastly, ExtensionDtypes are not supported by the Numba engine, so this example with
pyarrow.decimal128
type would not compile:For large Dataframes, the Bodo engine can offer performance benefits over the Python-based engine because it can translate functions into optimized machine code that executes in parallel. For example, consider this UDF which preprocesses text data by taking sections from two passages and joining them together to form a new passage:
For this example, we can randomly generate the string data to use:
Running on my laptop I saw:
Which represents a 5x improvement for 1 million strings.
Additional Context
Relevant links:
Bodo's documentation
Bodo's github repo
Proof-of-concept PR that adds support for
engine="bodo"
indf.apply
.The text was updated successfully, but these errors were encountered: