Skip to content

Add pylibcudf.Scalar.to_py to avoid scalar conversion to host via pyarrow #19043

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

Merged
merged 6 commits into from
May 31, 2025

Conversation

mroeschke
Copy link
Contributor

@mroeschke mroeschke commented May 29, 2025

Description

closes #18921

Additionally adds a expr.Literal.astype method to contain Literal casting logic between 2 DataTypes. This casting logic before was using pylibcudf to cast between 2 scalars. I think this is an unnecessary operation to do on a GPU, so now this just performs the cast using Polars directly.

Checklist

  • I am familiar with the Contributing Guidelines.
  • New or existing tests cover these changes.
  • The documentation is up to date with these changes.

@mroeschke mroeschke self-assigned this May 29, 2025
@mroeschke mroeschke requested a review from a team as a code owner May 29, 2025 21:47
@mroeschke mroeschke requested review from wence- and Matt711 May 29, 2025 21:47
@mroeschke mroeschke added improvement Improvement / enhancement to an existing function non-breaking Non-breaking change cudf.polars Issues specific to cudf.polars pylibcudf Issues specific to the pylibcudf package labels May 29, 2025
@github-actions github-actions bot added the Python Affects Python cuDF API. label May 29, 2025
@GPUtester GPUtester moved this to In Progress in cuDF Python May 29, 2025
Comment on lines 181 to 184
if not self.is_valid():
return None
elif self.type().id() == type_id.BOOL8:
return (<numeric_scalar[cbool]*>self.c_obj.get()).value()
Copy link
Contributor

Choose a reason for hiding this comment

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

You could try storing these in variables self.type().id() and self.c_obj.get()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure thing, good idea!

@@ -168,6 +169,47 @@ cdef class Scalar:
"""
return _from_numpy(np_val)

def to_py(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

if-else or match-case?
image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

An old habit of mine before match existed in Python. I wouldn't be opposed to use match in the future

@mroeschke
Copy link
Contributor Author

/merge

@rapids-bot rapids-bot bot merged commit 5cb49f7 into rapidsai:branch-25.08 May 31, 2025
91 checks passed
@github-project-automation github-project-automation bot moved this from In Progress to Done in cuDF Python May 31, 2025
@mroeschke mroeschke deleted the plc/scalar/to_py branch May 31, 2025 00:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cudf.polars Issues specific to cudf.polars improvement Improvement / enhancement to an existing function non-breaking Non-breaking change pylibcudf Issues specific to the pylibcudf package Python Affects Python cuDF API.
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

[FEA] Support pylibcudf.Scalar.to_py
2 participants