-
Notifications
You must be signed in to change notification settings - Fork 6k
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
Add the boundary param for sort in ray.data.Dataset #41269
Changes from all commits
e8a21ac
1efd05a
a1b3adb
e1fa5a4
e9455c2
616a7ab
d6f0e64
448072f
ab10605
5f7b579
59e999e
0a3728c
2117532
d9ea6c4
90bfd6f
e2ccb6d
e3b686e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2294,6 +2294,7 @@ def sort( | |
self, | ||
key: Union[str, List[str], None] = None, | ||
descending: Union[bool, List[bool]] = False, | ||
boundaries: List[Union[int, float]] = None, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will it work for non-numeric columns? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, this function cannot currently process non-numeric columns. However, in our business, if we encounter a non-numeric column, we will process it and convert it to a numeric type. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That sounds good for now; could you just update the docstring to say that this only supports numeric columns right now? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks, I have added code comments to explain that the boundaries parameter currently supports numeric types.😁😁😁 |
||
) -> "Dataset": | ||
"""Sort the dataset by the specified key column or key function. | ||
|
||
|
@@ -2304,22 +2305,48 @@ def sort( | |
|
||
Examples: | ||
>>> import ray | ||
>>> ds = ray.data.range(100) | ||
>>> ds.sort("id", descending=True).take(3) | ||
[{'id': 99}, {'id': 98}, {'id': 97}] | ||
>>> ds = ray.data.range(15) | ||
>>> ds = ds.sort("id", descending=False, boundaries=[5, 10]) | ||
>>> for df in ray.get(ds.to_pandas_refs()): | ||
... print(df) | ||
id | ||
0 0 | ||
1 1 | ||
2 2 | ||
3 3 | ||
4 4 | ||
id | ||
0 5 | ||
1 6 | ||
2 7 | ||
3 8 | ||
4 9 | ||
id | ||
0 10 | ||
1 11 | ||
2 12 | ||
3 13 | ||
4 14 | ||
|
||
Time complexity: O(dataset size * log(dataset size / parallelism)) | ||
|
||
Args: | ||
key: The column or a list of columns to sort by. | ||
descending: Whether to sort in descending order. Must be a boolean or a list | ||
of booleans matching the number of the columns. | ||
boundaries: The list of values based on which to repartition the dataset. | ||
For example, if the input boundary is [10,20], rows with values less | ||
than 10 will be divided into the first block, rows with values greater | ||
than or equal to 10 and less than 20 will be divided into the | ||
second block, and rows with values greater than or equal to 20 | ||
will be divided into the third block. If not provided, the | ||
boundaries will be sampled from the input blocks. This feature | ||
only supports numeric columns right now. | ||
|
||
Returns: | ||
A new, sorted :class:`Dataset`. | ||
""" | ||
|
||
sort_key = SortKey(key, descending) | ||
sort_key = SortKey(key, descending, boundaries) | ||
plan = self._plan.with_stage(SortStage(self, sort_key)) | ||
|
||
logical_plan = self._logical_plan | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment should follow closely with the related code. In this case, I think it should be moved into the if block.