Fix save_to_disk writing no shard for a dataset with no rows - #8385
Open
LeSingh1 wants to merge 1 commit into
Open
Fix save_to_disk writing no shard for a dataset with no rows#8385LeSingh1 wants to merge 1 commit into
LeSingh1 wants to merge 1 commit into
Conversation
save_to_disk computes the number of shards from the estimated size and then clamps it to the number of rows, which gives 0 shards for a dataset with no rows. In that case the directory only gets state.json and dataset_info.json, with an empty "_data_files" list, and load_from_disk raises "IndexError: list index out of range" while rebuilding the table. This is reachable from a normal pipeline, e.g. a filter that keeps nothing followed by flatten_indices, and passing num_shards=1 explicitly already worked, so only the automatic path was affected.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
save_to_diskcomputes the number of shards from the estimated size and then clamps it to the number of rows (added in #7912):For a dataset with no rows that gives
0shards. No.arrowfile is written,state.jsongets an empty"_data_files", and loading it back fails:save_to_diskreports success, so the data loss is silent until the load fails later.It is reachable from an ordinary pipeline rather than only from a hand-built empty dataset:
and the same applies through
DatasetDict.save_to_diskwhen one split filters down to nothing.Passing
num_shards=1explicitly already worked, so only the automatic path was affected. This clamps the computed value to at least one shard.Added a regression test asserting the shard file exists and the dataset round-trips; it fails on
mainwithassert (dataset_path / "data-00000-of-00001.arrow").exists()and passes with the change.tests/test_arrow_dataset.pyandtests/test_dataset_dict.pypass (469 passed, 26 skipped).