-
Notifications
You must be signed in to change notification settings - Fork 7.3k
[Data] Compute Expressions-fixed size array #58741
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
bveeramani
merged 28 commits into
ray-project:master
from
400Ping:data/compute-expressions-arr
Jan 14, 2026
Merged
Changes from 22 commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
c2b03a8
[data]Compute Expressions-fixed-size-array-operations
400Ping b1615a8
fix prpperty
400Ping 950ef28
add type-checking
400Ping 7819f4b
[data] Improve array namespace docs and tests
400Ping 0bc9400
fix linter
400Ping 7a51d0b
fix
400Ping 6cd7558
Merge branch 'master' into data/compute-expressions-arr
400Ping d666c74
fix
400Ping afb4571
fix linter
400Ping 2957754
fix test
400Ping 040877a
fix test_namespace_expressions
400Ping 0fd0ff4
Merge branch 'master' into data/compute-expressions-arr
400Ping 24f7eaf
Merge branch 'master' into data/compute-expressions-arr
400Ping c9b92a6
fix
400Ping 804c228
Merge branch 'master' into data/compute-expressions-arr
400Ping a7e4520
Update python/ray/data/namespace_expressions/arr_namespace.py
400Ping 70dbbd0
fix format
400Ping 7a6a2fb
fix
400Ping 244e2b0
Merge branch 'master' into data/compute-expressions-arr
400Ping 2829610
fix
400Ping 4717267
update
400Ping bb6fb05
Merge branch 'master' into data/compute-expressions-arr
400Ping c72eb5b
remove flatten()
400Ping 71e4784
Merge branch 'master' into data/compute-expressions-arr
400Ping c46d1fa
Merge remote-tracking branch 'upstream/master' into data/compute-expr…
400Ping c3d3bb2
fix CI error
400Ping aa9ded9
update
400Ping 2a283d8
fix
400Ping File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| """Array namespace for expression operations on array-typed columns.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from dataclasses import dataclass | ||
| from typing import TYPE_CHECKING | ||
|
|
||
| import pyarrow | ||
|
|
||
| from ray.data.datatype import DataType | ||
| from ray.data.expressions import pyarrow_udf | ||
|
|
||
| if TYPE_CHECKING: | ||
| from ray.data.expressions import Expr, UDFExpr | ||
|
|
||
|
|
||
| @dataclass | ||
| class _ArrayNamespace: | ||
| """Namespace for array operations on expression columns. | ||
|
|
||
| Example: | ||
| >>> from ray.data.expressions import col | ||
| >>> # Convert fixed-size lists to variable-length lists | ||
| >>> expr = col("features").arr.to_list() | ||
| """ | ||
|
|
||
| _expr: Expr | ||
|
|
||
| def to_list(self) -> "UDFExpr": | ||
| """Convert FixedSizeList columns into variable-length lists.""" | ||
| return_dtype = DataType(object) | ||
|
|
||
| expr_dtype = self._expr.data_type | ||
| if expr_dtype.is_list_type(): | ||
| arrow_type = expr_dtype.to_arrow_dtype() | ||
| if pyarrow.types.is_fixed_size_list(arrow_type): | ||
| return_dtype = DataType.from_arrow(pyarrow.list_(arrow_type.value_type)) | ||
| else: | ||
| return_dtype = expr_dtype | ||
|
|
||
| @pyarrow_udf(return_dtype=return_dtype) | ||
| def _to_list(arr: pyarrow.Array) -> pyarrow.Array: | ||
| arr_dtype = DataType.from_arrow(arr.type) | ||
| if not arr_dtype.is_list_type(): | ||
| raise pyarrow.lib.ArrowInvalid( | ||
| "to_list() can only be called on list-like columns, " | ||
| f"but got {arr.type}" | ||
| ) | ||
|
|
||
| if isinstance(arr.type, pyarrow.FixedSizeListType): | ||
| return arr.cast(pyarrow.list_(arr.type.value_type)) | ||
| return arr | ||
|
|
||
| return _to_list(self._expr) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.