Skip to content

[Data][expr] Add cast method for type conversion in expressions#60695

Merged
alexeykudinkin merged 15 commits into
ray-project:masterfrom
daiping8:cast
Feb 9, 2026
Merged

[Data][expr] Add cast method for type conversion in expressions#60695
alexeykudinkin merged 15 commits into
ray-project:masterfrom
daiping8:cast

Conversation

@daiping8

@daiping8 daiping8 commented Feb 3, 2026

Copy link
Copy Markdown
Contributor

Description

  • Implemented a new cast method in the Expr class to allow casting of expressions to specified data types using PyArrow.
  • Added comprehensive tests for the cast method covering basic conversions, use cases, safe mode, and error handling for invalid types.

Related issues

Closes #60644

Signed-off-by: daiping8 <dai.ping88@zte.com.cn>

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a cast method for expressions, enabling type conversions within Ray Data expressions. The implementation is well-structured, leveraging a helper function _normalize_cast_target_type to handle various type representations and creating a UDF for the casting operation. The accompanying tests are comprehensive, covering basic conversions, edge cases like safe casting, and error handling for invalid types.

I have one suggestion to simplify the type normalization logic for improved maintainability. Overall, this is a great addition that enhances the expressiveness of Ray Data.

Comment thread python/ray/data/expressions.py Outdated
Signed-off-by: daiping8 <dai.ping88@zte.com.cn>
@daiping8 daiping8 changed the title [data][expr] Add cast method for type conversion in expressions Feb 3, 2026
@daiping8 daiping8 marked this pull request as ready for review February 3, 2026 03:55
@daiping8 daiping8 requested a review from a team as a code owner February 3, 2026 03:55
Comment thread python/ray/data/expressions.py Outdated
Signed-off-by: daiping8 <dai.ping88@zte.com.cn>
Signed-off-by: daiping8 <dai.ping88@zte.com.cn>
@ray-gardener ray-gardener Bot added data Ray Data-related issues community-contribution Contributed by the community labels Feb 3, 2026
Comment thread python/ray/data/expressions.py Outdated
Comment thread python/ray/data/expressions.py Outdated
Comment thread python/ray/data/tests/test_with_column.py Outdated
Comment thread python/ray/data/tests/test_with_column.py Outdated
@goutamvenkat-anyscale

Copy link
Copy Markdown
Contributor

Thanks for the contribution. Left a few comments.

Signed-off-by: daiping8 <dai.ping88@zte.com.cn>
@daiping8

daiping8 commented Feb 4, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the contribution. Left a few comments.

Thank you for your suggestion. All suggestions have been adopted.

Comment thread python/ray/data/tests/expressions/test_cast.py Outdated
Signed-off-by: daiping8 <dai.ping88@zte.com.cn>
@daiping8 daiping8 changed the title [WIP][data][expr] Add cast method for type conversion in expressions Feb 4, 2026
Comment thread python/ray/data/tests/expressions/test_cast.py Outdated
Comment thread python/ray/data/tests/expressions/test_cast.py Outdated
Signed-off-by: daiping8 <dai.ping88@zte.com.cn>
Signed-off-by: daiping8 <dai.ping88@zte.com.cn>

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Comment thread python/ray/data/tests/expressions/test_cast.py
Signed-off-by: daiping8 <dai.ping88@zte.com.cn>
Signed-off-by: daiping8 <dai.ping88@zte.com.cn>
@daiping8

daiping8 commented Feb 6, 2026

Copy link
Copy Markdown
Contributor Author

@goutamvenkat-anyscale All suggestions have been applied. CI test has passed. Please review again, thank you.

@goutamvenkat-anyscale goutamvenkat-anyscale left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

lgtm!

@goutamvenkat-anyscale goutamvenkat-anyscale added the go add ONLY when ready to merge, run all tests label Feb 9, 2026
Comment thread python/ray/data/expressions.py
@alexeykudinkin alexeykudinkin merged commit 7ecbca7 into ray-project:master Feb 9, 2026
7 checks passed
ans9868 pushed a commit to ans9868/ray that referenced this pull request Feb 18, 2026
…project#60695)

## Description
- Implemented a new `cast` method in the `Expr` class to allow casting
of expressions to specified data types using PyArrow.
- Added comprehensive tests for the `cast` method covering basic
conversions, use cases, safe mode, and error handling for invalid types.

## Related issues
Closes ray-project#60644

---------

Signed-off-by: daiping8 <dai.ping88@zte.com.cn>
Signed-off-by: 金嘉淇10353800 <jin.jiaqi@zte.com.cn>
Co-authored-by: 金嘉淇10353800 <jin.jiaqi@zte.com.cn>
Signed-off-by: Adel Nour <ans9868@nyu.edu>
Aydin-ab pushed a commit to kunling-anyscale/ray that referenced this pull request Feb 20, 2026
…project#60695)

## Description
- Implemented a new `cast` method in the `Expr` class to allow casting
of expressions to specified data types using PyArrow.
- Added comprehensive tests for the `cast` method covering basic
conversions, use cases, safe mode, and error handling for invalid types.

## Related issues
Closes ray-project#60644

---------

Signed-off-by: daiping8 <dai.ping88@zte.com.cn>
Signed-off-by: 金嘉淇10353800 <jin.jiaqi@zte.com.cn>
Co-authored-by: 金嘉淇10353800 <jin.jiaqi@zte.com.cn>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community-contribution Contributed by the community data Ray Data-related issues go add ONLY when ready to merge, run all tests

4 participants