Skip to content
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

[Data] Fix to_pandas error when multiple block types #48583

Merged
merged 3 commits into from
Nov 7, 2024

Conversation

bveeramani
Copy link
Member

Why are these changes needed?

Two issues:

  1. When the execution plan caches the dataset schema, it might call unify_schema to produce a single schema from all of the bundles' schemas. The issue is that this function expects all of the input schemas to be of Arrow type, but we only check if at least one schema is of Arrow type before calling the function.
  2. to_pandas iterates over blocks and adds them to DelegatingBlockBuilder. The issue is that DelegatingBlockBuilder expects all input blocks to be of the same type.

Related issue number

Fixes #48575

Checks

  • I've signed off every commit(by using the -s flag, i.e., git commit -s) in this PR.
  • I've run scripts/format.sh to lint the changes in this PR.
  • I've included any doc changes needed for https://docs.ray.io/en/master/.
    • I've added any new APIs to the API Reference. For example, if I added a
      method in Tune, I've added it in doc/source/tune/api/ under the
      corresponding .rst file.
  • I've made sure the tests are passing. Note that there might be a few flaky tests, see the recent failures at https://flakey-tests.ray.io/
  • Testing Strategy
    • Unit tests
    • Release tests
    • This PR is not tested :(

Signed-off-by: Balaji Veeramani <bveeramani@berkeley.edu>
Signed-off-by: Balaji Veeramani <bveeramani@berkeley.edu>
Comment on lines +4617 to +4625
builder = PandasBlockBuilder()
for batch in self.iter_batches(batch_format="pandas", batch_size=None):
builder.add_block(batch)
block = builder.build()

# `PandasBlockBuilder` creates a dataframe with internal extension types like
# 'TensorDtype'. We use the `to_pandas` method to convert these extension
# types to regular types.
return BlockAccessor.for_block(block).to_pandas()
Copy link
Contributor

Choose a reason for hiding this comment

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

if i'm understanding correctly, i think this new code now adds an extra conversion from Arrow to pandas batch. is there any way we can avoid it?

the old code:
Arrow internal -> Arrow Block -> build to big Arrow block -> convert to pd DF

the new code:
Arrow internal -> Pandas batch -> build to big Arrow block -> convert to pd DF

Copy link
Contributor

Choose a reason for hiding this comment

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

There's no step 3 ("build to big Arrow block") in the new code, since we're using PandasBlockBuilder

Copy link
Contributor

Choose a reason for hiding this comment

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

ah you're right, i mistakenly thought it converts to arrow tables.

@alexeykudinkin alexeykudinkin added the go add ONLY when ready to merge, run all tests label Nov 7, 2024
Comment on lines +4617 to +4625
builder = PandasBlockBuilder()
for batch in self.iter_batches(batch_format="pandas", batch_size=None):
builder.add_block(batch)
block = builder.build()

# `PandasBlockBuilder` creates a dataframe with internal extension types like
# 'TensorDtype'. We use the `to_pandas` method to convert these extension
# types to regular types.
return BlockAccessor.for_block(block).to_pandas()
Copy link
Contributor

Choose a reason for hiding this comment

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

There's no step 3 ("build to big Arrow block") in the new code, since we're using PandasBlockBuilder

@bveeramani bveeramani enabled auto-merge (squash) November 7, 2024 20:09
Signed-off-by: Balaji Veeramani <bveeramani@berkeley.edu>
@github-actions github-actions bot disabled auto-merge November 7, 2024 20:45
@bveeramani bveeramani merged commit 1bc18a1 into master Nov 7, 2024
5 checks passed
@bveeramani bveeramani deleted the fix-pandas-union branch November 7, 2024 21:53
JP-sDEV pushed a commit to JP-sDEV/ray that referenced this pull request Nov 14, 2024
…8583)

Two issues:
1. When the execution plan caches the dataset schema, it might call
`unify_schema` to produce a single schema from all of the bundles'
schemas. The issue is that this function expects all of the input
schemas to be of Arrow type, but we only check if at least one schema is
of Arrow type before calling the function.
2. `to_pandas` iterates over blocks and adds them to
`DelegatingBlockBuilder`. The issue is that `DelegatingBlockBuilder`
expects all input blocks to be of the same type.

---------

Signed-off-by: Balaji Veeramani <bveeramani@berkeley.edu>
mohitjain2504 pushed a commit to mohitjain2504/ray that referenced this pull request Nov 15, 2024
…8583)

Two issues:
1. When the execution plan caches the dataset schema, it might call
`unify_schema` to produce a single schema from all of the bundles'
schemas. The issue is that this function expects all of the input
schemas to be of Arrow type, but we only check if at least one schema is
of Arrow type before calling the function.
2. `to_pandas` iterates over blocks and adds them to
`DelegatingBlockBuilder`. The issue is that `DelegatingBlockBuilder`
expects all input blocks to be of the same type.

---------

Signed-off-by: Balaji Veeramani <bveeramani@berkeley.edu>
Signed-off-by: mohitjain2504 <mohit.jain@dream11.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
go add ONLY when ready to merge, run all tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Data] Unifying block metadata schemas for pandas and pyarrow errors out
4 participants