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

ARROW-12060: [Python] Enable calling compute functions on Expressions #11918

Conversation

jorisvandenbossche
Copy link
Member

No description provided.

@github-actions
Copy link

github-actions bot commented Dec 9, 2021

@github-actions
Copy link

github-actions bot commented Dec 9, 2021

⚠️ Ticket has not been started in JIRA, please click 'Start Progress'.

@jorisvandenbossche
Copy link
Member Author

This makes the following already possible (to use in filter or projection expression in dataset):

In [1]: import pyarrow.compute as pc

In [2]: import pyarrow.dataset as ds

In [3]: pc.hour(ds.field("datetime_col"))
Out[3]: <pyarrow.dataset.Expression hour(datetime_col)>

In [4]: pc.days_between(ds.field("col1"), ds.field("col2"))
Out[4]: <pyarrow.dataset.Expression days_between(col1, col2)>

c_arguments.push_back((<Expression> argument).expr)

# if options is not None:
# c_options = make_shared[CFunctionOptions](options.get_options())
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given a python FunctionOptions class object, I need to get a shared pointer to the C++ object (get_options() returns a const CFunctionOptions*, but CmakeCallExpressions needs a shared_ptr[CFunctionOptions]).

But I haven't directly found how to do that conversion (cc @pitrou)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should probably replace the unique_ptr in the FunctionOptions declaration with a shared_ptr.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The DeserializeFunctionOptions in C++ (in function_internal.h, and several other methods there) returns a unique_ptr(from #10511). Can that be changed there as well?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can, but I don't think it's necessary on the C++ side. On the Python side, you can convert the unique_ptr into a shared_ptr (by moving it).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's what I did in the meantime. The only difficulty I ran into is that moving a uniqe_ptr to shared_ptr doesn't seem to work in cython, but with our helper to_shared it worked.

@jorisvandenbossche jorisvandenbossche marked this pull request as ready for review January 17, 2022 18:59
Copy link
Member

@pitrou pitrou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neat!

cdef:
vector[CExpression] c_arguments
shared_ptr[CFunctionOptions] c_options=(
<shared_ptr[CFunctionOptions]> nullptr)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need to explicitly initialize this, do you?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, yes, passing an unitialized c_options to CMakeCallExpression seems to work as well

@jorisvandenbossche jorisvandenbossche deleted the ARROW-12060-expressions-compute branch January 18, 2022 20:40
@ursabot
Copy link

ursabot commented Jan 18, 2022

Benchmark runs are scheduled for baseline = 18bedd3 and contender = 17bf54a. 17bf54a is a master commit associated with this PR. Results will be available as each benchmark for each run completes.
Conbench compare runs links:
[Finished ⬇️0.0% ⬆️0.0%] ec2-t3-xlarge-us-east-2
[Failed ⬇️0.36% ⬆️0.0%] ursa-i9-9960x
[Finished ⬇️0.39% ⬆️0.0%] ursa-thinkcentre-m75q
Supported benchmarks:
ec2-t3-xlarge-us-east-2: Supported benchmark langs: Python. Runs only benchmarks with cloud = True
ursa-i9-9960x: Supported benchmark langs: Python, R, JavaScript
ursa-thinkcentre-m75q: Supported benchmark langs: C++, Java

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

Successfully merging this pull request may close these issues.

None yet

3 participants