[Data] Compute Expressions-struct field_by_index#62560
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces index-based access for struct fields in Ray Data expressions, allowing users to retrieve fields by their position using both bracket notation and a new field_by_index method. The feedback suggests refining type checks to explicitly exclude boolean values from being treated as integer indices and adding validation to ensure indices are non-negative, preventing potential mismatches with the underlying PyArrow compute functions.
|
Hi @goutamvenkat-anyscale, could you help to review this pr when you have a moment? Thanks! |
a31c717 to
b7c69fa
Compare
Signed-off-by: wanadzhar913 <adzhar.faiq@gmail.com>
…oject/ray/pull/62560/changes#r3074173858) - Explicitly exclude boolean types when checking for integer indices to avoid confusing behavior (https://github.com/ray-project/ray/pull/62560/changes#r3074173838) Signed-off-by: wanadzhar913 <adzhar.faiq@gmail.com>
b7c69fa to
c0edef4
Compare
goutamvenkat-anyscale
left a comment
There was a problem hiding this comment.
Thanks for the PR. Left a few comments.
|
Tysm for reviewing my PR! Have resolved your comments. |
goutamvenkat-anyscale
left a comment
There was a problem hiding this comment.
thanks for the change!
|
Hi @goutamvenkat-anyscale, not too sure if the CI failure is related to this PR or not. Lmk if I've to change anything. Tysm! |
Description
Add index-based field access for struct namespace operations in Ray Data.
Changes
struct.field_by_index(field_index: int)inpython/ray/data/namespace_expressions/struct_namespace.pystruct.__getitem__to accept both:str(existing behavior):col("s").struct["field"]int(new):col("s").struct[0].struct[...]Expr.structexamples inpython/ray/data/expressions.pyto show index-based usageRelated issues
Related to #58674
Additional information
python -m pytest -v --doctest-modules python/ray/data/namespace_expressions/struct_namespace.pypython -m pytest -v python/ray/data/tests/expressions/test_namespace_struct.pypython -m pytest -v --doctest-modules python/ray/data/expressions.py -k 'struct and Expr'