forked from huggingface/datasets
-
Notifications
You must be signed in to change notification settings - Fork 0
fix: force contiguous copy for sliced list arrays in embed_array_storage #8
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
Open
The-Obstacle-Is-The-Way
wants to merge
8
commits into
main
Choose a base branch
from
fix/embed-storage-crash
base: main
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.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
c5a4b62
fix(fingerprint): treat TMPDIR as strict API and fail (Issue #7877) (…
ada-ggf25 d68aaf5
encode nifti correctly when uploading lazily (#7892)
CloseChoice 8ea8fe5
fix(nifti): enable lazy loading for Nifti1ImageWrapper (#7887)
The-Obstacle-Is-The-Way 58dda42
Don't save original_shard_lengths by default for backward compat (#7906)
lhoestq 37d9615
release: 4.4.2 (#7907)
lhoestq 0feb65d
set dev version (#7908)
lhoestq 031956f
fix: force contiguous copy for sliced list arrays in embed_array_storage
The-Obstacle-Is-The-Way b46579b
chore: address CodeRabbit review feedback
The-Obstacle-Is-The-Way 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
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
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
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
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,122 @@ | ||
| """Tests for embed_array_storage with sliced/sharded arrays. | ||
|
|
||
| Regression tests for SIGKILL crash when processing sliced/sharded Arrow tables | ||
| with nested types like Sequence(Nifti()) or Sequence(Image()). | ||
| """ | ||
|
|
||
| import pyarrow as pa | ||
|
|
||
| from datasets.features import Image, List | ||
| from datasets.table import embed_array_storage | ||
|
|
||
| from ..utils import require_nibabel | ||
|
|
||
|
|
||
| class TestEmbedArrayStorageSliced: | ||
| """Tests for embed_array_storage with sliced/sharded arrays.""" | ||
|
|
||
| def test_embed_array_storage_sliced_list_image(self, shared_datadir): | ||
| """embed_array_storage should work on sliced ListArray with Image. | ||
|
|
||
| This is a regression test for SIGKILL when processing sharded datasets | ||
| with Sequence(Image()) or similar nested types. | ||
| """ | ||
| image_file = str(shared_datadir / "test_image_rgb.jpg") | ||
|
|
||
| # Create a ListArray with 4 items | ||
| array = pa.array( | ||
| [ | ||
| [{"bytes": None, "path": image_file}], | ||
| [{"bytes": None, "path": image_file}, {"bytes": None, "path": image_file}], | ||
| [], | ||
| [{"bytes": None, "path": image_file}], | ||
| ], | ||
| type=pa.list_(Image.pa_type), | ||
| ) | ||
|
|
||
| # Slice it (simulates ds.shard() or ds.select()) | ||
| sliced = array.slice(1, 2) # Items 1 and 2 | ||
|
|
||
| # Verify the array is actually sliced (this is the problematic case) | ||
| assert sliced.offset == 1, "Expected sliced array to have non-zero offset" | ||
|
|
||
| # This should NOT crash with SIGKILL | ||
| embedded = embed_array_storage(sliced, List(Image())) | ||
|
|
||
| # The fix should make the result contiguous (offset = 0) | ||
| assert embedded.offset == 0, "Result should be contiguous after fix" | ||
| assert len(embedded) == 2 | ||
| # Item 0 of sliced = Item 1 of original (has 2 images) | ||
| assert len(embedded[0].as_py()) == 2 | ||
| # Item 1 of sliced = Item 2 of original (empty list) | ||
| assert len(embedded[1].as_py()) == 0 | ||
|
|
||
| @require_nibabel | ||
| def test_embed_array_storage_sliced_list_nifti(self, shared_datadir): | ||
| """embed_array_storage should work on sliced ListArray with Nifti. | ||
|
|
||
| This is the specific case that crashed in the ARC dataset upload. | ||
| """ | ||
| from datasets.features.nifti import Nifti | ||
|
|
||
| nifti_path = str(shared_datadir / "test_nifti.nii.gz") | ||
|
|
||
| # Create a ListArray with 4 items (Sequence(Nifti())) | ||
| array = pa.array( | ||
| [ | ||
| [{"bytes": None, "path": nifti_path}], | ||
| [{"bytes": None, "path": nifti_path}, {"bytes": None, "path": nifti_path}], | ||
| [], # Empty list - this also triggered the crash | ||
| [{"bytes": None, "path": nifti_path}], | ||
| ], | ||
| type=pa.list_(Nifti.pa_type), | ||
| ) | ||
|
|
||
| # Slice it (simulates ds.shard()) | ||
| sliced = array.slice(1, 2) | ||
|
|
||
| # Verify the array is actually sliced | ||
| assert sliced.offset == 1, "Expected sliced array to have non-zero offset" | ||
|
|
||
| # This should NOT crash with SIGKILL | ||
| embedded = embed_array_storage(sliced, List(Nifti())) | ||
|
|
||
| # The fix should make the result contiguous (offset = 0) | ||
| assert embedded.offset == 0, "Result should be contiguous after fix" | ||
| assert len(embedded) == 2 | ||
| # Verify bytes were embedded | ||
| assert embedded[0].as_py()[0]["bytes"] is not None | ||
|
|
||
| def test_embed_array_storage_sliced_large_list(self, shared_datadir): | ||
| """embed_array_storage should work on sliced LargeListArray.""" | ||
| image_file = str(shared_datadir / "test_image_rgb.jpg") | ||
|
|
||
| # Create a LargeListArray with 4 items | ||
| from datasets.features import LargeList | ||
|
|
||
| array = pa.array( | ||
| [ | ||
| [{"bytes": None, "path": image_file}], | ||
| [{"bytes": None, "path": image_file}, {"bytes": None, "path": image_file}], | ||
| [], | ||
| [{"bytes": None, "path": image_file}], | ||
| ], | ||
| type=pa.large_list(Image.pa_type), | ||
| ) | ||
|
|
||
| # Slice it | ||
| sliced = array.slice(1, 2) | ||
|
|
||
| # Verify the array is actually sliced | ||
| assert sliced.offset == 1, "Expected sliced array to have non-zero offset" | ||
|
|
||
| # This should NOT crash with SIGKILL | ||
| embedded = embed_array_storage(sliced, LargeList(Image())) | ||
|
|
||
| # The fix should make the result contiguous (offset = 0) | ||
| assert embedded.offset == 0, "Result should be contiguous after fix" | ||
| assert len(embedded) == 2 | ||
| # Item 0 of sliced = Item 1 of original (has 2 images) | ||
| assert len(embedded[0].as_py()) == 2 | ||
| # Verify bytes were embedded | ||
| assert embedded[0].as_py()[0]["bytes"] is not None | ||
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
Oops, something went wrong.
Oops, something went wrong.
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.
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.
Update placeholder issue number in docstring.
Same as in
table.py, the placeholderXXXXshould be replaced with the actual issue number.📝 Committable suggestion
🤖 Prompt for AI Agents