- Notifications
You must be signed in to change notification settings - Fork6.2k
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
[Data] add reset pandas index when merge sorted blocks#45326
Open
tespent wants to merge1 commit intoray-project:masterChoose a base branch fromtespent:fix/pandas-sorted-index
base:master
Could not load branches
Branch not found:{{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline, and old review comments may become outdated.
Conversation
This file contains 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
MissiontoMars commentedMay 14, 2024
Hi@tespent , if you could add a test for this / rebase, that'd be appreciated. |
Signed-off-by: Wu Yufei <wuyufei.2000@bytedance.com>
07e4b54
to72c2c5d
Compare Comment on lines +447 to +465
def test_index_reset(ray_start_regular_shared): | ||
# pandas blocks should have index reset after processing | ||
import ray | ||
ds = ray.data.range(100, override_num_blocks=10) | ||
ds = ds.map_batches( | ||
lambda df: df.assign(val=(50.6 - df["id"]).abs(), idx=-df["id"]).set_index( | ||
"idx" | ||
), | ||
batch_format="pandas", | ||
) | ||
# ensure index is reset after map | ||
for df in ray.get(ds.get_internal_block_refs()): | ||
assert (df.index == df.reset_index(drop=True).index).all() | ||
ds = ds.sort("val") | ||
# ensure index is reset after sort | ||
for df in ray.get(ds.get_internal_block_refs()): | ||
assert (df.index == df.reset_index(drop=True).index).all() |
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.
This test checks for implementation-- can you instead provide a test for a data pipeline that was breaking before this change?
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Labels
community-contributionContributed by the community dataRay Data-related issues @external-author-action-requiredAlternate tag for PRs where the author doesn't have labeling permission. P1Issue that should be fixed within a few weeks
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.
Why are these changes needed?
The index of pandas blocks are reset after all block processing, but not for sort currently. This resulted in a lot of other code being broken. For example in get_bounds of random access dataset, it uses the index to get the first and the last row (L286), but without resetting index after sort, it gets random rows.
ray/python/ray/data/random_access_dataset.py
Lines 283 to 289 in9472ae2
Related issue number
Checks
git commit -s
) in this PR.scripts/format.sh
to lint the changes in this PR.method in Tune, I've added it in
doc/source/tune/api/
under thecorresponding
.rst
file.